From: Rico Tzschichholz Date: Wed, 26 Mar 2014 19:13:06 +0000 (+0100) Subject: Add tests for enums annotated with [Flags] X-Git-Tag: 0.25.1~140 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d9dff687875a2ae033719799d8a77487917bd159;p=thirdparty%2Fvala.git Add tests for enums annotated with [Flags] --- diff --git a/tests/Makefile.am b/tests/Makefile.am index cbfd5809f..d8043323d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 000000000..52b439d24 --- /dev/null +++ b/tests/enums/flags.vala @@ -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); +} +