[vala] Add tests for enums annotated with [Flags]
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Add tests for enums annotated with [Flags]
- Date: Wed, 26 Mar 2014 19:22:55 +0000 (UTC)
commit d9dff687875a2ae033719799d8a77487917bd159
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Wed Mar 26 20:13:06 2014 +0100
Add tests for enums annotated with [Flags]
tests/Makefile.am | 1 +
tests/enums/flags.vala | 31 +++++++++++++++++++++++++++++++
2 files changed, 32 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index cbfd580..d804332 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 0000000..52b439d
--- /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);
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]