summaryrefslogtreecommitdiff
path: root/tests/structs
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2019-03-25 12:46:15 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2019-03-25 13:57:13 +0100
commit7d771a0c07d63cb7605cbdc28dd8df50719731f8 (patch)
treeace6b2288faa24b4fcc7b4596acb93ede097692c /tests/structs
parent2d9c89eff5bcded0ae9c9807a33d10b97b18aaaa (diff)
downloadvala-7d771a0c07d63cb7605cbdc28dd8df50719731f8.tar.gz
codegen: Move implicit GValue cast for comparison to BinaryExpression
Handle "==" and "!=" only as it was done before. This generates correct c-code for boxed simple-types and will perform value-based comparisons. See https://bugzilla.gnome.org/show_bug.cgi?id=585063
Diffstat (limited to 'tests/structs')
-rw-r--r--tests/structs/gvalue-implicit-comparison.vala98
1 files changed, 98 insertions, 0 deletions
diff --git a/tests/structs/gvalue-implicit-comparison.vala b/tests/structs/gvalue-implicit-comparison.vala
new file mode 100644
index 000000000..91865fbcf
--- /dev/null
+++ b/tests/structs/gvalue-implicit-comparison.vala
@@ -0,0 +1,98 @@
+Value get_value (Value v) {
+ return v;
+}
+
+Value? get_nullable_value (Value? v) {
+ return v;
+}
+
+void main () {
+ {
+ Value v = Value (typeof (int));
+ v.set_int (42);
+ if (v == 42) {
+ } else {
+ assert_not_reached ();
+ }
+ if (42 == v) {
+ } else {
+ assert_not_reached ();
+ }
+ }
+ {
+ Value? v = Value (typeof (int));
+ v.set_int (42);
+ if (v == 42) {
+ } else {
+ assert_not_reached ();
+ }
+ if (42 == v) {
+ } else {
+ assert_not_reached ();
+ }
+ }
+ {
+ Value v = Value (typeof (string));
+ v.set_string ("foo");
+ if (v == "foo") {
+ } else {
+ assert_not_reached ();
+ }
+ if ("foo" == v) {
+ } else {
+ assert_not_reached ();
+ }
+ }
+ {
+ Value? v = Value (typeof (string));
+ v.set_string ("foo");
+ if (v == "foo") {
+ } else {
+ assert_not_reached ();
+ }
+ if ("foo" == v) {
+ } else {
+ assert_not_reached ();
+ }
+ }
+ {
+ Value v = Value (typeof (int));
+ v.set_int (23);
+ if (get_value (v) != 23) {
+ assert_not_reached ();
+ }
+ if (23 != get_value (v)) {
+ assert_not_reached ();
+ }
+ }
+ {
+ Value? v = Value (typeof (int));
+ v.set_int (23);
+ if (get_nullable_value (v) != 23) {
+ assert_not_reached ();
+ }
+ if (23 != get_nullable_value (v)) {
+ assert_not_reached ();
+ }
+ }
+ {
+ Value v = Value (typeof (string));
+ v.set_string ("bar");
+ if (get_value (v) != "bar") {
+ assert_not_reached ();
+ }
+ if ("bar" != get_value (v)) {
+ assert_not_reached ();
+ }
+ }
+ {
+ Value? v = Value (typeof (string));
+ v.set_string ("bar");
+ if (get_nullable_value (v) != "bar") {
+ assert_not_reached ();
+ }
+ if ("bar" != get_nullable_value (v)) {
+ assert_not_reached ();
+ }
+ }
+}