summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFrederik Zipp <fzipp@gmx.de>2010-08-01 12:54:37 +0200
committerRico Tzschichholz <ricotz@ubuntu.com>2023-01-11 19:54:08 +0100
commit58dcad084f427585994ab66904436e1bd0e0b2a1 (patch)
tree7e065d02ee93732615fbf1272630eb8685e9d50d /tests
parent4bdb3e7301c59a32216ff383c23a4bdcf70fa268 (diff)
downloadvala-58dcad084f427585994ab66904436e1bd0e0b2a1.tar.gz
codegen: Add foreach support for strings
Fixes https://gitlab.gnome.org/GNOME/vala/issues/108
Diffstat (limited to 'tests')
-rw-r--r--tests/control-flow/foreach.c-expected32
-rw-r--r--tests/control-flow/foreach.vala12
2 files changed, 44 insertions, 0 deletions
diff --git a/tests/control-flow/foreach.c-expected b/tests/control-flow/foreach.c-expected
index c402e1c12..3263a32ef 100644
--- a/tests/control-flow/foreach.c-expected
+++ b/tests/control-flow/foreach.c-expected
@@ -46,6 +46,7 @@ static void _vala_GValue_free_function_content_of (gpointer data);
VALA_EXTERN void test_foreach_multidim_array (void);
VALA_EXTERN void test_foreach_const_array (void);
VALA_EXTERN void test_foreach_slice_array (void);
+VALA_EXTERN void test_foreach_string (void);
static void _vala_main (void);
const gint FOO[6] = {1, 2, 3, 4, 5, 6};
@@ -669,6 +670,36 @@ test_foreach_slice_array (void)
foo = (g_free (foo), NULL);
}
+void
+test_foreach_string (void)
+{
+ guint i = 0U;
+ gchar* s = NULL;
+ gchar* _tmp0_;
+ const gchar* _tmp1_;
+ i = (guint) 0;
+ _tmp0_ = g_strdup ("abc àçêö 你好");
+ s = _tmp0_;
+ _tmp1_ = s;
+ {
+ const gchar* c_collection = NULL;
+ const gchar* c_iter = NULL;
+ c_collection = _tmp1_;
+ _vala_warn_if_fail (g_utf8_validate (c_collection, -1, NULL), "Invalid UTF-8 string");
+ for (c_iter = c_collection; (*c_iter) != '\0'; c_iter = g_utf8_next_char (c_iter)) {
+ gunichar c = 0U;
+ c = g_utf8_get_char (c_iter);
+ {
+ guint _tmp2_;
+ _tmp2_ = i;
+ i = _tmp2_ + 1;
+ }
+ }
+ }
+ _vala_assert (i == ((guint) 11), "i == 11");
+ _g_free0 (s);
+}
+
static void
_vala_main (void)
{
@@ -679,6 +710,7 @@ _vala_main (void)
test_foreach_const_array ();
test_foreach_multidim_array ();
test_foreach_slice_array ();
+ test_foreach_string ();
}
int
diff --git a/tests/control-flow/foreach.vala b/tests/control-flow/foreach.vala
index 8689a18ad..83cef663a 100644
--- a/tests/control-flow/foreach.vala
+++ b/tests/control-flow/foreach.vala
@@ -173,6 +173,17 @@ void test_foreach_slice_array () {
assert (result == "2345");
}
+void test_foreach_string () {
+ uint i = 0;
+ string s = "abc àçêö 你好"; // Ni hao
+
+ foreach (unichar c in s) {
+ i++;
+ }
+
+ assert (i == 11);
+}
+
void main () {
test_foreach_gvaluearray ();
test_foreach_garray ();
@@ -181,4 +192,5 @@ void main () {
test_foreach_const_array ();
test_foreach_multidim_array ();
test_foreach_slice_array ();
+ test_foreach_string ();
}