[vala/0.40] tests: Add "string switch" test to increase coverage



commit e35c6cda12e0410f2b16979ae5587ae9714b11b0
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sat Jan 2 14:12:11 2021 +0100

    tests: Add "string switch" test to increase coverage

 tests/Makefile.am                     |  1 +
 tests/control-flow/switch-string.vala | 42 +++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3cdf9d256..c7a257239 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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
index 000000000..bc015692a
--- /dev/null
+++ b/tests/control-flow/switch-string.vala
@@ -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");
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]