about summary refs log tree commit diff
path: root/src/test/run-pass
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-07-02 18:48:23 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-07-02 18:48:23 -0700
commitc4ac124edda29eabffc2acc3255aca1a0c2680f0 (patch)
tree488edf8d1734ab70c6556e322260ad98e0910f7a /src/test/run-pass
parentff1dd44b40a7243f43a8d32ba8bd6026197c320b (diff)
parentc8ae065182d19a098aa397fddcb4f4f4eccc0b32 (diff)
downloadrust-c4ac124edda29eabffc2acc3255aca1a0c2680f0.tar.gz
rust-c4ac124edda29eabffc2acc3255aca1a0c2680f0.zip
Merge remote-tracking branch 'origin/master' into 0.11.0-release
Conflicts:
	RELEASES.txt
Diffstat (limited to 'src/test/run-pass')
-rw-r--r--src/test/run-pass/issue-15104.rs21
-rw-r--r--src/test/run-pass/match-vec-alternatives.rs82
2 files changed, 103 insertions, 0 deletions
diff --git a/src/test/run-pass/issue-15104.rs b/src/test/run-pass/issue-15104.rs
new file mode 100644
index 00000000000..d2711339ccb
--- /dev/null
+++ b/src/test/run-pass/issue-15104.rs
@@ -0,0 +1,21 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() {
+    assert_eq!(count_members(&[1, 2, 3, 4]), 4);
+}
+
+fn count_members(v: &[uint]) -> uint {
+    match v {
+        []         => 0,
+        [_]        => 1,
+        [_x, ..xs] => 1 + count_members(xs)
+    }
+}
diff --git a/src/test/run-pass/match-vec-alternatives.rs b/src/test/run-pass/match-vec-alternatives.rs
new file mode 100644
index 00000000000..ffbc4e85cb6
--- /dev/null
+++ b/src/test/run-pass/match-vec-alternatives.rs
@@ -0,0 +1,82 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn match_vecs<'a, T>(l1: &'a [T], l2: &'a [T]) -> &'static str {
+    match (l1, l2) {
+        ([], []) => "both empty",
+        ([], [..]) | ([..], []) => "one empty",
+        ([..], [..]) => "both non-empty"
+    }
+}
+
+fn match_vecs_cons<'a, T>(l1: &'a [T], l2: &'a [T]) -> &'static str {
+    match (l1, l2) {
+        ([], []) => "both empty",
+        ([], [_, ..]) | ([_, ..], []) => "one empty",
+        ([_, ..], [_, ..]) => "both non-empty"
+    }
+}
+
+fn match_vecs_snoc<'a, T>(l1: &'a [T], l2: &'a [T]) -> &'static str {
+    match (l1, l2) {
+        ([], []) => "both empty",
+        ([], [.., _]) | ([.., _], []) => "one empty",
+        ([.., _], [.., _]) => "both non-empty"
+    }
+}
+
+fn match_nested_vecs_cons<'a, T>(l1: Option<&'a [T]>, l2: Result<&'a [T], ()>) -> &'static str {
+    match (l1, l2) {
+        (Some([]), Ok([])) => "Some(empty), Ok(empty)",
+        (Some([_, ..]), Ok(_)) | (Some([_, ..]), Err(())) => "Some(non-empty), any",
+        (None, Ok([])) | (None, Err(())) | (None, Ok([_])) => "None, Ok(less than one element)",
+        (None, Ok([_, _, ..])) => "None, Ok(at least two elements)",
+        _ => "other"
+    }
+}
+
+fn match_nested_vecs_snoc<'a, T>(l1: Option<&'a [T]>, l2: Result<&'a [T], ()>) -> &'static str {
+    match (l1, l2) {
+        (Some([]), Ok([])) => "Some(empty), Ok(empty)",
+        (Some([.., _]), Ok(_)) | (Some([.., _]), Err(())) => "Some(non-empty), any",
+        (None, Ok([])) | (None, Err(())) | (None, Ok([_])) => "None, Ok(less than one element)",
+        (None, Ok([.., _, _])) => "None, Ok(at least two elements)",
+        _ => "other"
+    }
+}
+
+fn main() {
+    assert_eq!(match_vecs(&[1i, 2], &[2i, 3]), "both non-empty");
+    assert_eq!(match_vecs(&[], &[1i, 2, 3, 4]), "one empty");
+    assert_eq!(match_vecs::<uint>(&[], &[]), "both empty");
+    assert_eq!(match_vecs(&[1i, 2, 3], &[]), "one empty");
+
+    assert_eq!(match_vecs_cons(&[1i, 2], &[2i, 3]), "both non-empty");
+    assert_eq!(match_vecs_cons(&[], &[1i, 2, 3, 4]), "one empty");
+    assert_eq!(match_vecs_cons::<uint>(&[], &[]), "both empty");
+    assert_eq!(match_vecs_cons(&[1i, 2, 3], &[]), "one empty");
+
+    assert_eq!(match_vecs_snoc(&[1i, 2], &[2i, 3]), "both non-empty");
+    assert_eq!(match_vecs_snoc(&[], &[1i, 2, 3, 4]), "one empty");
+    assert_eq!(match_vecs_snoc::<uint>(&[], &[]), "both empty");
+    assert_eq!(match_vecs_snoc(&[1i, 2, 3], &[]), "one empty");
+
+    assert_eq!(match_nested_vecs_cons(None, Ok(&[4u, 2u])), "None, Ok(at least two elements)");
+    assert_eq!(match_nested_vecs_cons::<uint>(None, Err(())), "None, Ok(less than one element)");
+    assert_eq!(match_nested_vecs_cons::<bool>(Some(&[]), Ok(&[])), "Some(empty), Ok(empty)");
+    assert_eq!(match_nested_vecs_cons(Some(&[1i]), Err(())), "Some(non-empty), any");
+    assert_eq!(match_nested_vecs_cons(Some(&[(42i, ())]), Ok(&[(1i, ())])), "Some(non-empty), any");
+
+    assert_eq!(match_nested_vecs_snoc(None, Ok(&[4u, 2u])), "None, Ok(at least two elements)");
+    assert_eq!(match_nested_vecs_snoc::<uint>(None, Err(())), "None, Ok(less than one element)");
+    assert_eq!(match_nested_vecs_snoc::<bool>(Some(&[]), Ok(&[])), "Some(empty), Ok(empty)");
+    assert_eq!(match_nested_vecs_snoc(Some(&[1i]), Err(())), "Some(non-empty), any");
+    assert_eq!(match_nested_vecs_snoc(Some(&[(42i, ())]), Ok(&[(1i, ())])), "Some(non-empty), any");
+}