From 1326d424c96479864e80b25e24994d7cd5085920 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sat, 2 Apr 2011 19:32:34 -0400 Subject: Add more tests for alt expressions --- src/test/run-pass/expr-alt-box.rs | 27 +++++++++++++++++++ src/test/run-pass/expr-alt-struct.rs | 35 +++++++++++++++++++++++++ src/test/run-pass/expr-alt.rs | 51 ++++++++++++++++++++++++++++++++++-- 3 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 src/test/run-pass/expr-alt-box.rs create mode 100644 src/test/run-pass/expr-alt-struct.rs (limited to 'src') diff --git a/src/test/run-pass/expr-alt-box.rs b/src/test/run-pass/expr-alt-box.rs new file mode 100644 index 00000000..2e7846f3 --- /dev/null +++ b/src/test/run-pass/expr-alt-box.rs @@ -0,0 +1,27 @@ +// xfail-boot +// -*- rust -*- + +// Tests for alt as expressions resulting in boxed types + +fn test_box() { + auto res = alt (true) { + case (true) { + @100 + } + }; + check (*res == 100); +} + +fn test_str() { + auto res = alt (true) { + case (true) { + "happy" + } + }; + check (res == "happy"); +} + +fn main() { + test_box(); + test_str(); +} \ No newline at end of file diff --git a/src/test/run-pass/expr-alt-struct.rs b/src/test/run-pass/expr-alt-struct.rs new file mode 100644 index 00000000..31406969 --- /dev/null +++ b/src/test/run-pass/expr-alt-struct.rs @@ -0,0 +1,35 @@ +// xfail-boot +// -*- rust -*- + +// Tests for alt as expressions resulting in structural types + +fn test_rec() { + auto res = alt (true) { + case (true) { + rec(i = 100) + } + }; + check (res == rec(i = 100)); +} + +fn test_tag() { + tag mood { + happy; + sad; + } + + auto res = alt (true) { + case (true) { + happy + } + case (false) { + sad + } + }; + check (res == happy); +} + +fn main() { + test_rec(); + test_tag(); +} \ No newline at end of file diff --git a/src/test/run-pass/expr-alt.rs b/src/test/run-pass/expr-alt.rs index 420ccbc9..4c10a7d9 100644 --- a/src/test/run-pass/expr-alt.rs +++ b/src/test/run-pass/expr-alt.rs @@ -3,7 +3,7 @@ // Tests for using alt as an expression -fn test() { +fn test_basic() { let bool res = alt (true) { case (true) { true @@ -25,6 +25,53 @@ fn test() { check (res); } +fn test_inferrence() { + auto res = alt (true) { + case (true) { + true + } + case (false) { + false + } + }; + check (res); +} + +fn test_alt_as_alt_head() { + // Yeah, this is kind of confusing ... + auto res = alt(alt (false) { case (true) { true } case (false) {false} }) { + case (true) { + false + } + case (false) { + true + } + }; + check (res); +} + +fn test_alt_as_block_result() { + auto res = alt (false) { + case (true) { + false + } + case (false) { + alt (true) { + case (true) { + true + } + case (false) { + false + } + } + } + }; + check (res); +} + fn main() { - test(); + test_basic(); + test_inferrence(); + test_alt_as_alt_head(); + test_alt_as_block_result(); } -- cgit v1.2.3