aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorBrian Anderson <[email protected]>2011-04-02 19:32:34 -0400
committerBrian Anderson <[email protected]>2011-04-02 20:35:51 -0400
commit1326d424c96479864e80b25e24994d7cd5085920 (patch)
tree376f880acd662ec52f8624cc65a02f3f8eb8e82a /src/test
parentAdd FIXMEs around type handling in trans_if, trans_alt (diff)
downloadrust-1326d424c96479864e80b25e24994d7cd5085920.tar.xz
rust-1326d424c96479864e80b25e24994d7cd5085920.zip
Add more tests for alt expressions
Diffstat (limited to 'src/test')
-rw-r--r--src/test/run-pass/expr-alt-box.rs27
-rw-r--r--src/test/run-pass/expr-alt-struct.rs35
-rw-r--r--src/test/run-pass/expr-alt.rs51
3 files changed, 111 insertions, 2 deletions
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();
}