about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2016-03-06 15:54:44 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2016-05-26 11:11:58 +0300
commitc038b454239a30cb8a734bcb2ff8a7e5e543939a (patch)
tree978a7e11ebc682cb15f3f3decb256c0ae2ea15cd /src/test
parentd69aeaf662c637b454e8c7a5ddbd69b4978ec211 (diff)
downloadrust-c038b454239a30cb8a734bcb2ff8a7e5e543939a.tar.gz
rust-c038b454239a30cb8a734bcb2ff8a7e5e543939a.zip
Address review comments
Diffstat (limited to 'src/test')
-rw-r--r--src/test/parse-fail/pat-tuple-3.rs2
-rw-r--r--src/test/run-pass/pat-tuple-1.rs104
-rw-r--r--src/test/run-pass/pat-tuple-2.rs34
-rw-r--r--src/test/run-pass/pat-tuple-3.rs40
-rw-r--r--src/test/run-pass/pat-tuple-4.rs68
-rw-r--r--src/test/run-pass/pat-tuple-5.rs40
-rw-r--r--src/test/run-pass/pat-tuple-6.rs56
-rw-r--r--src/test/run-pass/pat-tuple.rs202
8 files changed, 343 insertions, 203 deletions
diff --git a/src/test/parse-fail/pat-tuple-3.rs b/src/test/parse-fail/pat-tuple-3.rs
index 95e44ae134c..029dc7a2956 100644
--- a/src/test/parse-fail/pat-tuple-3.rs
+++ b/src/test/parse-fail/pat-tuple-3.rs
@@ -12,6 +12,6 @@
 
 fn main() {
     match 0 {
-        (.., pat, ..) => {} //~ ERROR expected pattern, found `..`
+        (.., pat, ..) => {} //~ ERROR `..` can only be used once per tuple or tuple struct pattern
     }
 }
diff --git a/src/test/run-pass/pat-tuple-1.rs b/src/test/run-pass/pat-tuple-1.rs
new file mode 100644
index 00000000000..c3796210a8e
--- /dev/null
+++ b/src/test/run-pass/pat-tuple-1.rs
@@ -0,0 +1,104 @@
+// Copyright 2016 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.
+
+#![feature(dotdot_in_tuple_patterns)]
+
+fn tuple() {
+    let x = (1, 2, 3);
+    match x {
+        (a, b, ..) => {
+            assert_eq!(a, 1);
+            assert_eq!(b, 2);
+        }
+    }
+    match x {
+        (.., b, c) => {
+            assert_eq!(b, 2);
+            assert_eq!(c, 3);
+        }
+    }
+    match x {
+        (a, .., c) => {
+            assert_eq!(a, 1);
+            assert_eq!(c, 3);
+        }
+    }
+    match x {
+        (a, b, c) => {
+            assert_eq!(a, 1);
+            assert_eq!(b, 2);
+            assert_eq!(c, 3);
+        }
+    }
+    match x {
+        (a, b, c, ..) => {
+            assert_eq!(a, 1);
+            assert_eq!(b, 2);
+            assert_eq!(c, 3);
+        }
+    }
+    match x {
+        (.., a, b, c) => {
+            assert_eq!(a, 1);
+            assert_eq!(b, 2);
+            assert_eq!(c, 3);
+        }
+    }
+}
+
+fn tuple_struct() {
+    struct S(u8, u8, u8);
+
+    let x = S(1, 2, 3);
+    match x {
+        S(a, b, ..) => {
+            assert_eq!(a, 1);
+            assert_eq!(b, 2);
+        }
+    }
+    match x {
+        S(.., b, c) => {
+            assert_eq!(b, 2);
+            assert_eq!(c, 3);
+        }
+    }
+    match x {
+        S(a, .., c) => {
+            assert_eq!(a, 1);
+            assert_eq!(c, 3);
+        }
+    }
+    match x {
+        S(a, b, c) => {
+            assert_eq!(a, 1);
+            assert_eq!(b, 2);
+            assert_eq!(c, 3);
+        }
+    }
+    match x {
+        S(a, b, c, ..) => {
+            assert_eq!(a, 1);
+            assert_eq!(b, 2);
+            assert_eq!(c, 3);
+        }
+    }
+    match x {
+        S(.., a, b, c) => {
+            assert_eq!(a, 1);
+            assert_eq!(b, 2);
+            assert_eq!(c, 3);
+        }
+    }
+}
+
+fn main() {
+    tuple();
+    tuple_struct();
+}
diff --git a/src/test/run-pass/pat-tuple-2.rs b/src/test/run-pass/pat-tuple-2.rs
new file mode 100644
index 00000000000..881e96a9d78
--- /dev/null
+++ b/src/test/run-pass/pat-tuple-2.rs
@@ -0,0 +1,34 @@
+// Copyright 2016 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.
+
+#![feature(dotdot_in_tuple_patterns)]
+
+fn tuple() {
+    let x = (1,);
+    match x {
+        (2, ..) => panic!(),
+        (..) => ()
+    }
+}
+
+fn tuple_struct() {
+    struct S(u8);
+
+    let x = S(1);
+    match x {
+        S(2, ..) => panic!(),
+        S(..) => ()
+    }
+}
+
+fn main() {
+    tuple();
+    tuple_struct();
+}
diff --git a/src/test/run-pass/pat-tuple-3.rs b/src/test/run-pass/pat-tuple-3.rs
new file mode 100644
index 00000000000..94d33d41899
--- /dev/null
+++ b/src/test/run-pass/pat-tuple-3.rs
@@ -0,0 +1,40 @@
+// Copyright 2016 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.
+
+#![feature(dotdot_in_tuple_patterns)]
+
+fn tuple() {
+    let x = (1, 2, 3);
+    let branch = match x {
+        (1, 1, ..) => 0,
+        (1, 2, 3, ..) => 1,
+        (1, 2, ..) => 2,
+        _ => 3
+    };
+    assert_eq!(branch, 1);
+}
+
+fn tuple_struct() {
+    struct S(u8, u8, u8);
+
+    let x = S(1, 2, 3);
+    let branch = match x {
+        S(1, 1, ..) => 0,
+        S(1, 2, 3, ..) => 1,
+        S(1, 2, ..) => 2,
+        _ => 3
+    };
+    assert_eq!(branch, 1);
+}
+
+fn main() {
+    tuple();
+    tuple_struct();
+}
diff --git a/src/test/run-pass/pat-tuple-4.rs b/src/test/run-pass/pat-tuple-4.rs
new file mode 100644
index 00000000000..ffd82fea996
--- /dev/null
+++ b/src/test/run-pass/pat-tuple-4.rs
@@ -0,0 +1,68 @@
+// Copyright 2016 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.
+
+#![feature(dotdot_in_tuple_patterns)]
+
+fn tuple() {
+    let x = (1, 2, 3);
+    match x {
+        (1, 2, 4) => unreachable!(),
+        (0, 2, 3, ..) => unreachable!(),
+        (0, .., 3) => unreachable!(),
+        (0, ..) => unreachable!(),
+        (1, 2, 3) => (),
+        (_, _, _) => unreachable!(),
+    }
+    match x {
+        (..) => (),
+    }
+    match x {
+        (_, _, _, ..) => (),
+    }
+    match x {
+        (a, b, c) => {
+            assert_eq!(1, a);
+            assert_eq!(2, b);
+            assert_eq!(3, c);
+        }
+    }
+}
+
+fn tuple_struct() {
+    struct S(u8, u8, u8);
+
+    let x = S(1, 2, 3);
+    match x {
+        S(1, 2, 4) => unreachable!(),
+        S(0, 2, 3, ..) => unreachable!(),
+        S(0, .., 3) => unreachable!(),
+        S(0, ..) => unreachable!(),
+        S(1, 2, 3) => (),
+        S(_, _, _) => unreachable!(),
+    }
+    match x {
+        S(..) => (),
+    }
+    match x {
+        S(_, _, _, ..) => (),
+    }
+    match x {
+        S(a, b, c) => {
+            assert_eq!(1, a);
+            assert_eq!(2, b);
+            assert_eq!(3, c);
+        }
+    }
+}
+
+fn main() {
+    tuple();
+    tuple_struct();
+}
diff --git a/src/test/run-pass/pat-tuple-5.rs b/src/test/run-pass/pat-tuple-5.rs
new file mode 100644
index 00000000000..41c4d02abcb
--- /dev/null
+++ b/src/test/run-pass/pat-tuple-5.rs
@@ -0,0 +1,40 @@
+// Copyright 2016 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.
+
+#![feature(dotdot_in_tuple_patterns)]
+
+fn tuple() {
+    struct S;
+    struct Z;
+    struct W;
+    let x = (S, Z, W);
+    match x { (S, ..) => {} }
+    match x { (.., W) => {} }
+    match x { (S, .., W) => {} }
+    match x { (.., Z, _) => {} }
+}
+
+fn tuple_struct() {
+    struct SS(S, Z, W);
+
+    struct S;
+    struct Z;
+    struct W;
+    let x = SS(S, Z, W);
+    match x { SS(S, ..) => {} }
+    match x { SS(.., W) => {} }
+    match x { SS(S, .., W) => {} }
+    match x { SS(.., Z, _) => {} }
+}
+
+fn main() {
+    tuple();
+    tuple_struct();
+}
diff --git a/src/test/run-pass/pat-tuple-6.rs b/src/test/run-pass/pat-tuple-6.rs
new file mode 100644
index 00000000000..6f3f2b3aed5
--- /dev/null
+++ b/src/test/run-pass/pat-tuple-6.rs
@@ -0,0 +1,56 @@
+// Copyright 2016 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.
+
+#![feature(dotdot_in_tuple_patterns)]
+
+fn tuple() {
+    let x = (1, 2, 3, 4, 5);
+    match x {
+        (a, .., b, c) => {
+            assert_eq!(a, 1);
+            assert_eq!(b, 4);
+            assert_eq!(c, 5);
+        }
+    }
+    match x {
+        (a, b, c, .., d) => {
+            assert_eq!(a, 1);
+            assert_eq!(b, 2);
+            assert_eq!(c, 3);
+            assert_eq!(d, 5);
+        }
+    }
+}
+
+fn tuple_struct() {
+    struct S(u8, u8, u8, u8, u8);
+
+    let x = S(1, 2, 3, 4, 5);
+    match x {
+        S(a, .., b, c) => {
+            assert_eq!(a, 1);
+            assert_eq!(b, 4);
+            assert_eq!(c, 5);
+        }
+    }
+    match x {
+        S(a, b, c, .., d) => {
+            assert_eq!(a, 1);
+            assert_eq!(b, 2);
+            assert_eq!(c, 3);
+            assert_eq!(d, 5);
+        }
+    }
+}
+
+fn main() {
+    tuple();
+    tuple_struct();
+}
diff --git a/src/test/run-pass/pat-tuple.rs b/src/test/run-pass/pat-tuple.rs
deleted file mode 100644
index ccea068f715..00000000000
--- a/src/test/run-pass/pat-tuple.rs
+++ /dev/null
@@ -1,202 +0,0 @@
-// Copyright 2016 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.
-
-#![feature(dotdot_in_tuple_patterns)]
-
-fn b() {
-    let x = (1, 2, 3);
-    match x {
-        (a, b, ..) => {
-            assert_eq!(a, 1);
-            assert_eq!(b, 2);
-        }
-    }
-    match x {
-        (.., b, c) => {
-            assert_eq!(b, 2);
-            assert_eq!(c, 3);
-        }
-    }
-    match x {
-        (a, .., c) => {
-            assert_eq!(a, 1);
-            assert_eq!(c, 3);
-        }
-    }
-    match x {
-        (a, b, c) => {
-            assert_eq!(a, 1);
-            assert_eq!(b, 2);
-            assert_eq!(c, 3);
-        }
-    }
-}
-
-fn bs() {
-    struct S(u8, u8, u8);
-
-    let x = S(1, 2, 3);
-    match x {
-        S(a, b, ..) => {
-            assert_eq!(a, 1);
-            assert_eq!(b, 2);
-        }
-    }
-    match x {
-        S(.., b, c) => {
-            assert_eq!(b, 2);
-            assert_eq!(c, 3);
-        }
-    }
-    match x {
-        S(a, .., c) => {
-            assert_eq!(a, 1);
-            assert_eq!(c, 3);
-        }
-    }
-    match x {
-        S(a, b, c) => {
-            assert_eq!(a, 1);
-            assert_eq!(b, 2);
-            assert_eq!(c, 3);
-        }
-    }
-}
-
-fn c() {
-    let x = (1,);
-    match x {
-        (2, ..) => panic!(),
-        (..) => ()
-    }
-}
-
-fn cs() {
-    struct S(u8);
-
-    let x = S(1);
-    match x {
-        S(2, ..) => panic!(),
-        S(..) => ()
-    }
-}
-
-fn d() {
-    let x = (1, 2, 3);
-    let branch = match x {
-        (1, 1, ..) => 0,
-        (1, 2, 3, ..) => 1,
-        (1, 2, ..) => 2,
-        _ => 3
-    };
-    assert_eq!(branch, 1);
-}
-
-fn ds() {
-    struct S(u8, u8, u8);
-
-    let x = S(1, 2, 3);
-    let branch = match x {
-        S(1, 1, ..) => 0,
-        S(1, 2, 3, ..) => 1,
-        S(1, 2, ..) => 2,
-        _ => 3
-    };
-    assert_eq!(branch, 1);
-}
-
-fn f() {
-    let x = (1, 2, 3);
-    match x {
-        (1, 2, 4) => unreachable!(),
-        (0, 2, 3, ..) => unreachable!(),
-        (0, .., 3) => unreachable!(),
-        (0, ..) => unreachable!(),
-        (1, 2, 3) => (),
-        (_, _, _) => unreachable!(),
-    }
-    match x {
-        (..) => (),
-    }
-    match x {
-        (_, _, _, ..) => (),
-    }
-    match x {
-        (a, b, c) => {
-            assert_eq!(1, a);
-            assert_eq!(2, b);
-            assert_eq!(3, c);
-        }
-    }
-}
-
-fn fs() {
-    struct S(u8, u8, u8);
-
-    let x = S(1, 2, 3);
-    match x {
-        S(1, 2, 4) => unreachable!(),
-        S(0, 2, 3, ..) => unreachable!(),
-        S(0, .., 3) => unreachable!(),
-        S(0, ..) => unreachable!(),
-        S(1, 2, 3) => (),
-        S(_, _, _) => unreachable!(),
-    }
-    match x {
-        S(..) => (),
-    }
-    match x {
-        S(_, _, _, ..) => (),
-    }
-    match x {
-        S(a, b, c) => {
-            assert_eq!(1, a);
-            assert_eq!(2, b);
-            assert_eq!(3, c);
-        }
-    }
-}
-
-fn g() {
-    struct S;
-    struct Z;
-    struct W;
-    let x = (S, Z, W);
-    match x { (S, ..) => {} }
-    match x { (.., W) => {} }
-    match x { (S, .., W) => {} }
-    match x { (.., Z, _) => {} }
-}
-
-fn gs() {
-    struct SS(S, Z, W);
-
-    struct S;
-    struct Z;
-    struct W;
-    let x = SS(S, Z, W);
-    match x { SS(S, ..) => {} }
-    match x { SS(.., W) => {} }
-    match x { SS(S, .., W) => {} }
-    match x { SS(.., Z, _) => {} }
-}
-
-fn main() {
-    b();
-    bs();
-    c();
-    cs();
-    d();
-    ds();
-    f();
-    fs();
-    g();
-    gs();
-}