]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Add tests for enums annotated with [Flags]
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 26 Mar 2014 19:13:06 +0000 (20:13 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 26 Mar 2014 19:22:15 +0000 (20:22 +0100)
tests/Makefile.am
tests/enums/flags.vala [new file with mode: 0644]

index cbfd5809f417350725f4b6ce46f2130f274ddf6c..d8043323dcefc6772c96e1995b6205224a876567 100644 (file)
@@ -72,6 +72,7 @@ TESTS = \
        control-flow/bug665904.vala \
        control-flow/bug691514.vala     \
        enums/enums.vala \
+       enums/flags.vala \
        enums/bug673879.vala \
        structs/structs.vala \
        structs/gvalue.vala \
diff --git a/tests/enums/flags.vala b/tests/enums/flags.vala
new file mode 100644 (file)
index 0000000..52b439d
--- /dev/null
@@ -0,0 +1,31 @@
+using GLib;
+
+[Flags]
+enum Foo {
+       VAL1,
+       VAL2,
+       VAL3
+}
+
+void main () {
+       Foo foo, bar, baz;
+
+       foo = (Foo.VAL1 | Foo.VAL2 | Foo.VAL3);
+       bar = (Foo.VAL1 | Foo.VAL2);
+       baz = (bar | Foo.VAL3);
+
+       assert (Foo.VAL1 == 1 << 0);
+       assert (Foo.VAL2 == 1 << 1);
+       assert (Foo.VAL3 == 1 << 2);
+
+       assert (Foo.VAL1 in bar);
+       assert ((Foo.VAL1 | Foo.VAL2) in bar);
+       assert (!(Foo.VAL3 in bar));
+
+       assert (Foo.VAL1 in baz);
+       assert (Foo.VAL2 in baz);
+       assert (Foo.VAL3 in baz);
+
+       assert (bar in foo);
+}
+