]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
tests: Extend "foreach" tests to increase coverage
authorRico Tzschichholz <ricotz@ubuntu.com>
Sat, 13 Apr 2019 15:46:23 +0000 (17:46 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 6 Aug 2019 11:26:06 +0000 (13:26 +0200)
tests/control-flow/foreach.vala

index 396c9f19c889deda6fef4ac88ccb43f1ce5c83cf..0646c2d9a2498c3537c222c7fae260f13115cca1 100644 (file)
@@ -33,6 +33,37 @@ void test_foreach_gvaluearray () {
        test_unowned (array);
 }
 
+void test_foreach_multidim_array () {
+       int[,] foo = { { 1, 2 }, { 3, 4 }, { 5, 6 } };
+       string result = "";
+       foreach (var i in foo) {
+               result += i.to_string ();
+       }
+       assert (result == "123456");
+}
+
+const int[] FOO = { 1, 2, 3, 4, 5, 6 };
+
+void test_foreach_const_array () {
+       string result = "";
+       foreach (var i in FOO) {
+               result += i.to_string ();
+       }
+       assert (result == "123456");
+}
+
+void test_foreach_slice_array () {
+       int[] foo = { 1, 2, 3, 4, 5, 6 };
+       string result = "";
+       foreach (var i in foo[1:foo.length - 1]) {
+               result += i.to_string ();
+       }
+       assert (result == "2345");
+}
+
 void main () {
        test_foreach_gvaluearray ();
+       test_foreach_const_array ();
+       test_foreach_multidim_array ();
+       test_foreach_slice_array ();
 }