]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
tests: Add "string switch" test to increase coverage
authorRico Tzschichholz <ricotz@ubuntu.com>
Sat, 2 Jan 2021 13:12:11 +0000 (14:12 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 3 Jan 2021 12:34:57 +0000 (13:34 +0100)
tests/Makefile.am
tests/control-flow/switch-string.vala [new file with mode: 0644]

index 3cdf9d2567970699a79ca2615fc1bf20787b4309..c7a257239497d136e32af6cddcc0a45d24706e56 100644 (file)
@@ -219,6 +219,7 @@ TESTS = \
        control-flow/pre-post-increment-parameter.vala \
        control-flow/pre-post-increment-property.vala \
        control-flow/switch.vala \
+       control-flow/switch-string.vala \
        control-flow/sideeffects.vala \
        control-flow/unassigned-captured-local-variable.test \
        control-flow/unassigned-local-block-variable.test \
diff --git a/tests/control-flow/switch-string.vala b/tests/control-flow/switch-string.vala
new file mode 100644 (file)
index 0000000..bc01569
--- /dev/null
@@ -0,0 +1,42 @@
+const string FOO = "foo";
+const string BAR = "bar";
+const string MANAM = "manam";
+
+string foo () {
+       string foo = "foo";
+
+       switch (foo) {
+       case FOO:
+               break;
+       case BAR:
+       case MANAM:
+               assert_not_reached ();
+       case "minim":
+               assert_not_reached ();
+       }
+
+       return foo;
+}
+
+string get_bar () {
+       return "bar";
+}
+
+string bar () {
+       switch (get_bar ()) {
+       case BAR:
+               break;
+       case FOO:
+       case "minim":
+               assert_not_reached ();
+       default:
+               assert_not_reached ();
+       }
+
+       return BAR;
+}
+
+void main () {
+       assert (foo () == "foo");
+       assert (bar () == "bar");
+}