[vala/wip/issue/1061: 4/4] tests: Add "pre-post-increment with side effect" tests to increase coverage
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/issue/1061: 4/4] tests: Add "pre-post-increment with side effect" tests to increase coverage
- Date: Thu, 13 Aug 2020 17:06:08 +0000 (UTC)
commit 8bab9d110ab18a693e81ccbe0619cb7b5471d54f
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Thu Aug 13 19:05:49 2020 +0200
tests: Add "pre-post-increment with side effect" tests to increase coverage
See https://gitlab.gnome.org/GNOME/vala/issues/1061
tests/Makefile.am | 4 +
tests/control-flow/pre-post-increment-field.vala | 75 ++++++++++
tests/control-flow/pre-post-increment-local.vala | 73 ++++++++++
.../control-flow/pre-post-increment-parameter.vala | 77 +++++++++++
.../control-flow/pre-post-increment-property.vala | 152 +++++++++++++++++++++
5 files changed, 381 insertions(+)
---
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);
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]