]> git.lizzy.rs Git - rust.git/commitdiff
Add tests for parsing of patterns
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Fri, 3 Apr 2015 02:56:27 +0000 (05:56 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Fri, 3 Apr 2015 02:56:27 +0000 (05:56 +0300)
16 files changed:
src/test/compile-fail/issue-22426-1.rs [deleted file]
src/test/compile-fail/issue-22426-2.rs [deleted file]
src/test/compile-fail/issue-22426-3.rs [deleted file]
src/test/parse-fail/pat-lt-bracket-1.rs [new file with mode: 0644]
src/test/parse-fail/pat-lt-bracket-2.rs [new file with mode: 0644]
src/test/parse-fail/pat-lt-bracket-3.rs [new file with mode: 0644]
src/test/parse-fail/pat-lt-bracket-4.rs [new file with mode: 0644]
src/test/parse-fail/pat-lt-bracket-5.rs [new file with mode: 0644]
src/test/parse-fail/pat-lt-bracket-6.rs [new file with mode: 0644]
src/test/parse-fail/pat-lt-bracket-7.rs [new file with mode: 0644]
src/test/parse-fail/pat-ranges-1.rs [new file with mode: 0644]
src/test/parse-fail/pat-ranges-2.rs [new file with mode: 0644]
src/test/parse-fail/pat-ranges-3.rs [new file with mode: 0644]
src/test/parse-fail/pat-ranges-4.rs [new file with mode: 0644]
src/test/run-pass/issue-22546.rs [new file with mode: 0644]
src/test/run-pass/pat-ranges.rs [new file with mode: 0644]

diff --git a/src/test/compile-fail/issue-22426-1.rs b/src/test/compile-fail/issue-22426-1.rs
deleted file mode 100644 (file)
index 6d3d120..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2015 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() {
-  match 42 {
-    x < 7 => (),
-   //~^ error: expected one of `=>`, `@`, `if`, or `|`, found `<`
-    _ => ()
-  }
-}
diff --git a/src/test/compile-fail/issue-22426-2.rs b/src/test/compile-fail/issue-22426-2.rs
deleted file mode 100644 (file)
index 6a06530..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright 2015 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 a(B<) {}
-   //~^ error: expected one of `:` or `@`, found `<`
diff --git a/src/test/compile-fail/issue-22426-3.rs b/src/test/compile-fail/issue-22426-3.rs
deleted file mode 100644 (file)
index 8ea2bcf..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2015 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.
-
-struct Foo<T>(T, T);
-
-impl<T> Foo<T> {
-    fn foo(&self) {
-        match *self {
-            Foo<T>(x, y) => {
-            //~^ error: expected one of `=>`, `@`, `if`, or `|`, found `<`
-              println!("Goodbye, World!")
-            }
-        }
-    }
-}
diff --git a/src/test/parse-fail/pat-lt-bracket-1.rs b/src/test/parse-fail/pat-lt-bracket-1.rs
new file mode 100644 (file)
index 0000000..6d3d120
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright 2015 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() {
+  match 42 {
+    x < 7 => (),
+   //~^ error: expected one of `=>`, `@`, `if`, or `|`, found `<`
+    _ => ()
+  }
+}
diff --git a/src/test/parse-fail/pat-lt-bracket-2.rs b/src/test/parse-fail/pat-lt-bracket-2.rs
new file mode 100644 (file)
index 0000000..6a06530
--- /dev/null
@@ -0,0 +1,12 @@
+// Copyright 2015 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 a(B<) {}
+   //~^ error: expected one of `:` or `@`, found `<`
diff --git a/src/test/parse-fail/pat-lt-bracket-3.rs b/src/test/parse-fail/pat-lt-bracket-3.rs
new file mode 100644 (file)
index 0000000..8ea2bcf
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright 2015 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.
+
+struct Foo<T>(T, T);
+
+impl<T> Foo<T> {
+    fn foo(&self) {
+        match *self {
+            Foo<T>(x, y) => {
+            //~^ error: expected one of `=>`, `@`, `if`, or `|`, found `<`
+              println!("Goodbye, World!")
+            }
+        }
+    }
+}
diff --git a/src/test/parse-fail/pat-lt-bracket-4.rs b/src/test/parse-fail/pat-lt-bracket-4.rs
new file mode 100644 (file)
index 0000000..3d9b492
--- /dev/null
@@ -0,0 +1,21 @@
+// Copyright 2015 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.
+
+enum BtNode {
+    Node(u32,Box<BtNode>,Box<BtNode>),
+    Leaf(u32),
+}
+
+fn main() {
+    let y = match x {
+        Foo<T>::A(value) => value, //~ error: expected one of `=>`, `@`, `if`, or `|`, found `<`
+        Foo<T>::B => 7,
+    };
+}
diff --git a/src/test/parse-fail/pat-lt-bracket-5.rs b/src/test/parse-fail/pat-lt-bracket-5.rs
new file mode 100644 (file)
index 0000000..3345845
--- /dev/null
@@ -0,0 +1,13 @@
+// Copyright 2015 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() {
+    let v[0] = v[1]; //~ error: expected one of `:`, `;`, `=`, or `@`, found `[`
+}
diff --git a/src/test/parse-fail/pat-lt-bracket-6.rs b/src/test/parse-fail/pat-lt-bracket-6.rs
new file mode 100644 (file)
index 0000000..72fdae8
--- /dev/null
@@ -0,0 +1,13 @@
+// Copyright 2015 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() {
+    let Test(&desc[..]) = x; //~ error: expected one of `,` or `@`, found `[`
+}
diff --git a/src/test/parse-fail/pat-lt-bracket-7.rs b/src/test/parse-fail/pat-lt-bracket-7.rs
new file mode 100644 (file)
index 0000000..c7731d1
--- /dev/null
@@ -0,0 +1,13 @@
+// Copyright 2015 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() {
+    for thing(x[]) {} //~ error: expected one of `,` or `@`, found `[`
+}
diff --git a/src/test/parse-fail/pat-ranges-1.rs b/src/test/parse-fail/pat-ranges-1.rs
new file mode 100644 (file)
index 0000000..e1cbb96
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright 2015 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.
+
+// Parsing of range patterns
+
+fn main() {
+    let macropus!() ... 11 = 12; //~ error: expected one of `:`, `;`, or `=`, found `...`
+}
diff --git a/src/test/parse-fail/pat-ranges-2.rs b/src/test/parse-fail/pat-ranges-2.rs
new file mode 100644 (file)
index 0000000..04ad5ff
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright 2015 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.
+
+// Parsing of range patterns
+
+fn main() {
+    let 10 ... makropulos!() = 12; //~ error: expected one of `::`, `:`, `;`, or `=`, found `!`
+}
diff --git a/src/test/parse-fail/pat-ranges-3.rs b/src/test/parse-fail/pat-ranges-3.rs
new file mode 100644 (file)
index 0000000..5f7aac7
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright 2015 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.
+
+// Parsing of range patterns
+
+fn main() {
+    let 10 ... 10 + 3 = 12; //~ expected one of `:`, `;`, or `=`, found `+`
+}
diff --git a/src/test/parse-fail/pat-ranges-4.rs b/src/test/parse-fail/pat-ranges-4.rs
new file mode 100644 (file)
index 0000000..50dcb89
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright 2015 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.
+
+// Parsing of range patterns
+
+fn main() {
+    let 10 - 3 ... 10 = 8; //~ error: expected one of `...`, `:`, `;`, or `=`, found `-`
+}
diff --git a/src/test/run-pass/issue-22546.rs b/src/test/run-pass/issue-22546.rs
new file mode 100644 (file)
index 0000000..b3cb8a7
--- /dev/null
@@ -0,0 +1,54 @@
+// Copyright 2015 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.
+
+// Parsing patterns with paths with type parameters (issue #22544)
+
+use std::default::Default;
+
+#[derive(Default)]
+pub struct Foo<T>(T, T);
+
+impl<T: ::std::fmt::Display> Foo<T> {
+    fn foo(&self) {
+        match *self {
+            Foo::<T>(ref x, ref y) => println!("Goodbye, World! {} {}", x, y)
+        }
+    }
+}
+
+trait Tr {
+    type U;
+}
+
+impl<T> Tr for Foo<T> {
+    type U = T;
+}
+
+struct Wrapper<T> {
+    value: T
+}
+
+fn main() {
+    let Foo::<i32>(a, b) = Default::default();
+
+    let f = Foo(2,3);
+    f.foo();
+
+    let w = Wrapper { value: Foo(10u8, 11u8) };
+    match w {
+        Wrapper::<Foo<u8>> { value: Foo(10, 11) } => {},
+        ::Wrapper::<<Foo<_> as Tr>::U> { value: Foo::<u8>(11, 16) } => { panic!() },
+        _ => { panic!() }
+    }
+
+    if let None::<u8> = Some(8) {
+        panic!();
+    }
+}
diff --git a/src/test/run-pass/pat-ranges.rs b/src/test/run-pass/pat-ranges.rs
new file mode 100644 (file)
index 0000000..9649895
--- /dev/null
@@ -0,0 +1,23 @@
+// Copyright 2015 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.
+
+// Parsing of range patterns
+
+const NUM1: i32 = 10;
+
+mod m {
+    pub const NUM2: i32 = 16;
+}
+
+fn main() {
+    if let NUM1 ... m::NUM2 = 10 {} else { panic!() }
+    if let ::NUM1 ... ::m::NUM2 = 11 {} else { panic!() }
+    if let -13 ... -10 = 12 { panic!() } else {}
+}