summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2020-08-13 19:05:49 +0200
committerRico Tzschichholz <ricotz@ubuntu.com>2020-08-13 19:05:49 +0200
commit8bab9d110ab18a693e81ccbe0619cb7b5471d54f (patch)
tree86ab859d8c63afd3240b5736e3209f382524551e
parentcb1828cfc5273aca752de9b39a77e0cd53305e61 (diff)
downloadvala-wip/issue/1061.tar.gz
tests: Add "pre-post-increment with side effect" tests to increase coveragewip/issue/1061
See https://gitlab.gnome.org/GNOME/vala/issues/1061
-rw-r--r--tests/Makefile.am4
-rw-r--r--tests/control-flow/pre-post-increment-field.vala75
-rw-r--r--tests/control-flow/pre-post-increment-local.vala73
-rw-r--r--tests/control-flow/pre-post-increment-parameter.vala77
-rw-r--r--tests/control-flow/pre-post-increment-property.vala152
5 files changed, 381 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c2505dcba..0f636c50c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -222,6 +222,10 @@ TESTS = \
control-flow/missing-return.test \
control-flow/nested-conditional.vala \
control-flow/pre-post-increment.vala \
+ control-flow/pre-post-increment-field.vala \
+ control-flow/pre-post-increment-local.vala \
+ control-flow/pre-post-increment-parameter.vala \
+ control-flow/pre-post-increment-property.vala \
control-flow/switch.vala \
control-flow/switch-enum.vala \
control-flow/sideeffects.vala \
diff --git a/tests/control-flow/pre-post-increment-field.vala b/tests/control-flow/pre-post-increment-field.vala
new file mode 100644
index 000000000..cf742a36c
--- /dev/null
+++ b/tests/control-flow/pre-post-increment-field.vala
@@ -0,0 +1,75 @@
+int field;
+
+void main () {
+ // incrementing
+ {
+ field = 1;
+ int res = field + field++;
+ assert (res == 2);
+ assert (field == 2);
+ }
+ {
+ field = 1;
+ int res = field++ + field;
+ assert (res == 3);
+ assert (field == 2);
+ }
+ {
+ field = 1;
+ int res = field + ++field;
+ assert (res == 3);
+ assert (field == 2);
+ }
+ {
+ field = 1;
+ int res = ++field + field;
+ assert (res == 4);
+ assert (field == 2);
+ }
+ {
+ field = 1;
+ assert (field++ == 1);
+ assert (field == 2);
+ }
+ {
+ field = 1;
+ assert (++field == 2);
+ assert (field == 2);
+ }
+
+ // decrementing
+ {
+ field = 1;
+ int d = field + field--;
+ assert (d == 2);
+ assert (field == 0);
+ }
+ {
+ field = 1;
+ int res = field-- + field;
+ assert (res == 1);
+ assert (field == 0);
+ }
+ {
+ field = 1;
+ int res = field + --field;
+ assert (res == 1);
+ assert (field == 0);
+ }
+ {
+ field = 1;
+ int res = --field + field;
+ assert (res == 0);
+ assert (field == 0);
+ }
+ {
+ field = 1;
+ assert (field-- == 1);
+ assert (field == 0);
+ }
+ {
+ field = 1;
+ assert (--field == 0);
+ assert (field == 0);
+ }
+}
diff --git a/tests/control-flow/pre-post-increment-local.vala b/tests/control-flow/pre-post-increment-local.vala
new file mode 100644
index 000000000..d630871e7
--- /dev/null
+++ b/tests/control-flow/pre-post-increment-local.vala
@@ -0,0 +1,73 @@
+void main () {
+ // incrementing
+ {
+ int local = 1;
+ int res = local + local++;
+ assert (res == 2);
+ assert (local == 2);
+ }
+ {
+ int local = 1;
+ int res = local++ + local;
+ assert (res == 3);
+ assert (local == 2);
+ }
+ {
+ int local = 1;
+ int res = local + ++local;
+ assert (res == 3);
+ assert (local == 2);
+ }
+ {
+ int local = 1;
+ int res = ++local + local;
+ assert (res == 4);
+ assert (local == 2);
+ }
+ {
+ int local = 1;
+ assert (local++ == 1);
+ assert (local == 2);
+ }
+ {
+ int local = 1;
+ assert (++local == 2);
+ assert (local == 2);
+ }
+
+ // decrementing
+ {
+ int local = 1;
+ int res = local + local--;
+ assert (res == 2);
+ assert (local == 0);
+ }
+ {
+ int local = 1;
+ int res = local-- + local;
+ assert (res == 1);
+ assert (local == 0);
+ }
+ {
+ int local = 1;
+ int res = local + --local;
+ assert (res == 1);
+ assert (local == 0);
+ }
+ {
+ int local = 1;
+ int res = --local + local;
+ assert (res == 0);
+ assert (local == 0);
+ }
+ {
+ int local = 1;
+ assert (local-- == 1);
+ assert (local == 0);
+ }
+ {
+ int local = 1;
+ assert (--local == 0);
+ assert (local == 0);
+ }
+}
diff --git a/tests/control-flow/pre-post-increment-parameter.vala b/tests/control-flow/pre-post-increment-parameter.vala
new file mode 100644
index 000000000..0cd410126
--- /dev/null
+++ b/tests/control-flow/pre-post-increment-parameter.vala
@@ -0,0 +1,77 @@
+void test_parameter (int parameter) {
+ // incrementing
+ {
+ parameter = 1;
+ int res = parameter + parameter++;
+ assert (res == 2);
+ assert (parameter == 2);
+ }
+ {
+ parameter = 1;
+ int res = parameter++ + parameter;
+ assert (res == 3);
+ assert (parameter == 2);
+ }
+ {
+ parameter = 1;
+ int res = parameter + ++parameter;
+ assert (res == 3);
+ assert (parameter == 2);
+ }
+ {
+ parameter = 1;
+ int res = ++parameter + parameter;
+ assert (res == 4);
+ assert (parameter == 2);
+ }
+ {
+ parameter = 1;
+ assert (parameter++ == 1);
+ assert (parameter == 2);
+ }
+ {
+ parameter = 1;
+ assert (++parameter == 2);
+ assert (parameter == 2);
+ }
+
+ // decrementing
+ {
+ parameter = 1;
+ int res = parameter + parameter--;
+ assert (res == 2);
+ assert (parameter == 0);
+ }
+ {
+ parameter = 1;
+ int res = parameter-- + parameter;
+ assert (res == 1);
+ assert (parameter == 0);
+ }
+ {
+ parameter = 1;
+ int res = parameter + --parameter;
+ assert (res == 1);
+ assert (parameter == 0);
+ }
+ {
+ parameter = 1;
+ int res = --parameter + parameter;
+ assert (res == 0);
+ assert (parameter == 0);
+ }
+ {
+ parameter = 1;
+ assert (parameter-- == 1);
+ assert (parameter == 0);
+ }
+ {
+ parameter = 1;
+ assert (--parameter == 0);
+ assert (parameter == 0);
+ }
+}
+
+void main () {
+ test_parameter (1);
+}
diff --git a/tests/control-flow/pre-post-increment-property.vala b/tests/control-flow/pre-post-increment-property.vala
new file mode 100644
index 000000000..148506c02
--- /dev/null
+++ b/tests/control-flow/pre-post-increment-property.vala
@@ -0,0 +1,152 @@
+class Foo {
+ public int property { get; set; }
+
+ public Foo () {
+ // incrementing
+ {
+ property = 1;
+ int res = property + property++;
+ assert (res == 2);
+ assert (property == 2);
+ }
+ {
+ property = 1;
+ int res = property++ + property;
+ assert (res == 3);
+ assert (property == 2);
+ }
+ {
+ property = 1;
+ int res = property + ++property;
+ assert (res == 3);
+ assert (property == 2);
+ }
+ {
+ property = 1;
+ int res = ++property + property;
+ assert (res == 4);
+ assert (property == 2);
+ }
+ {
+ property = 1;
+ assert (property++ == 1);
+ assert (property == 2);
+ }
+ {
+ property = 1;
+ assert (++property == 2);
+ assert (property == 2);
+ }
+
+ // decrementing
+ {
+ property = 1;
+ int res = property + property--;
+ assert (res == 2);
+ assert (property == 0);
+ }
+ {
+ property = 1;
+ int res = property-- + property;
+ assert (res == 1);
+ assert (property == 0);
+ }
+ {
+ property = 1;
+ int res = property + --property;
+ assert (res == 1);
+ assert (property == 0);
+ }
+ {
+ property = 1;
+ int res = --property + property;
+ assert (res == 0);
+ assert (property == 0);
+ }
+ {
+ property = 1;
+ assert (property-- == 1);
+ assert (property == 0);
+ }
+ {
+ property = 1;
+ assert (--property == 0);
+ assert (property == 0);
+ }
+ }
+}
+
+void main () {
+ var foo = new Foo ();
+ // incrementing
+ {
+ foo.property = 1;
+ int res = foo.property + foo.property++;
+ assert (res == 2);
+ assert (foo.property == 2);
+ }
+ {
+ foo.property = 1;
+ int res = foo.property++ + foo.property;
+ assert (res == 3);
+ assert (foo.property == 2);
+ }
+ {
+ foo.property = 1;
+ int res = foo.property + ++foo.property;
+ assert (res == 3);
+ assert (foo.property == 2);
+ }
+ {
+ foo.property = 1;
+ int res = ++foo.property + foo.property;
+ assert (res == 4);
+ assert (foo.property == 2);
+ }
+ {
+ foo.property = 1;
+ assert (foo.property++ == 1);
+ assert (foo.property == 2);
+ }
+ {
+ foo.property = 1;
+ assert (++foo.property == 2);
+ assert (foo.property == 2);
+ }
+
+ // decrementing
+ {
+ foo.property = 1;
+ int res = foo.property + foo.property--;
+ assert (res == 2);
+ assert (foo.property == 0);
+ }
+ {
+ foo.property = 1;
+ int res = foo.property-- + foo.property;
+ assert (res == 1);
+ assert (foo.property == 0);
+ }
+ {
+ foo.property = 1;
+ int res = foo.property + --foo.property;
+ assert (res == 1);
+ assert (foo.property == 0);
+ }
+ {
+ foo.property = 1;
+ int res = --foo.property + foo.property;
+ assert (res == 0);
+ assert (foo.property == 0);
+ }
+ {
+ foo.property = 1;
+ assert (foo.property-- == 1);
+ assert (foo.property == 0);
+ }
+ {
+ foo.property = 1;
+ assert (--foo.property == 0);
+ assert (foo.property == 0);
+ }
+}