aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-02-04 16:09:06 -0700
committerAndrew Kelley <superjoe30@gmail.com>2016-02-04 16:09:06 -0700
commita4cba900e53154abd5595bacf709fe8fdcc86b27 (patch)
tree906b7b238f5f5d3797d04180c137f9829ca43944 /test
parent5490f907fe4b5c8323eaf917b1ead8760c9eca34 (diff)
downloadzig-a4cba900e53154abd5595bacf709fe8fdcc86b27.tar.gz
zig-a4cba900e53154abd5595bacf709fe8fdcc86b27.zip
no namespace required when switching on enum
See #43
Diffstat (limited to 'test')
-rw-r--r--test/run_tests.cpp26
-rw-r--r--test/self_hosted.zig34
2 files changed, 26 insertions, 34 deletions
diff --git a/test/run_tests.cpp b/test/run_tests.cpp
index ef131b8ed2..f0c3a77871 100644
--- a/test/run_tests.cpp
+++ b/test/run_tests.cpp
@@ -1157,32 +1157,6 @@ fn fn3() -> u32 {7}
fn fn4() -> u32 {8}
)SOURCE", "5\n6\n7\n8\n");
- add_simple_case("switch statement", R"SOURCE(
-import "std.zig";
-
-enum Foo {
- A,
- B,
- C,
- D,
-}
-
-pub fn main(args: [][]u8) -> %void {
- const foo = Foo.C;
- const val: i32 = switch (foo) {
- Foo.A => 1,
- Foo.B => 2,
- Foo.C => 3,
- Foo.D => 4,
- };
- if (val != 3) {
- %%stdout.printf("BAD\n");
- }
-
- %%stdout.printf("OK\n");
-}
- )SOURCE", "OK\n");
-
add_simple_case("const number literal", R"SOURCE(
import "std.zig";
diff --git a/test/self_hosted.zig b/test/self_hosted.zig
index 2181a5e2b6..5fefbdd112 100644
--- a/test/self_hosted.zig
+++ b/test/self_hosted.zig
@@ -59,14 +59,14 @@ fn constant_enum_with_payload() {
fn should_be_empty(x: AnEnumWithPayload) {
switch (x) {
- AnEnumWithPayload.Empty => {},
+ Empty => {},
else => unreachable{},
}
}
fn should_be_not_empty(x: AnEnumWithPayload) {
switch (x) {
- AnEnumWithPayload.Empty => unreachable{},
+ Empty => unreachable{},
else => {},
}
}
@@ -111,9 +111,9 @@ fn non_const_cast_bool_to_int(t: bool, f: bool) {
fn switch_on_enum() {
const fruit = Fruit.Orange;
switch (fruit) {
- Fruit.Apple => unreachable{},
- Fruit.Orange => {},
- Fruit.Banana => unreachable{},
+ Apple => unreachable{},
+ Orange => {},
+ Banana => unreachable{},
}
non_const_switch_on_enum(fruit);
}
@@ -124,8 +124,26 @@ enum Fruit {
}
fn non_const_switch_on_enum(fruit: Fruit) {
switch (fruit) {
- Fruit.Apple => unreachable{},
- Fruit.Orange => {},
- Fruit.Banana => unreachable{},
+ Apple => unreachable{},
+ Orange => {},
+ Banana => unreachable{},
}
}
+
+#attribute("test")
+fn switch_statement() {
+ const foo = SwitchStatmentFoo.C;
+ const val: i32 = switch (foo) {
+ A => 1,
+ B => 2,
+ C => 3,
+ D => 4,
+ };
+ if (val != 3) unreachable{};
+}
+enum SwitchStatmentFoo {
+ A,
+ B,
+ C,
+ D,
+}