diff options
| author | Matthew Kuo <matthew.kuo@dialexa.com> | 2020-03-04 01:09:53 -0600 |
|---|---|---|
| committer | Matthew Kuo <matthew.kuo@dialexa.com> | 2020-03-04 01:17:41 -0600 |
| commit | 54561148581f002793ab42893de4e3f7c26bd7ed (patch) | |
| tree | f5200a8a091cf5b81361a4c8d0ead01ae137b8e4 /src/test/ui/or-patterns | |
| parent | 592e9c37008c2389451d28874a748f5b38612ca5 (diff) | |
| download | rust-54561148581f002793ab42893de4e3f7c26bd7ed.tar.gz rust-54561148581f002793ab42893de4e3f7c26bd7ed.zip | |
test(pattern): add tests for combinations of pattern features
Reference issue #67311 Tests combinations of the following pattern features: - bindings_after_at - or_patterns - slice_patterns - box_patterns
Diffstat (limited to 'src/test/ui/or-patterns')
| -rw-r--r-- | src/test/ui/or-patterns/box-patterns.rs | 37 | ||||
| -rw-r--r-- | src/test/ui/or-patterns/slice-patterns.rs | 42 |
2 files changed, 79 insertions, 0 deletions
diff --git a/src/test/ui/or-patterns/box-patterns.rs b/src/test/ui/or-patterns/box-patterns.rs new file mode 100644 index 00000000000..aafd4799383 --- /dev/null +++ b/src/test/ui/or-patterns/box-patterns.rs @@ -0,0 +1,37 @@ +// Test or-patterns with box-patterns + +// run-pass + +#![feature(or_patterns)] +#![feature(box_patterns)] + +#[derive(Debug, PartialEq)] +enum MatchArm { + Arm(usize), + Wild, +} + +#[derive(Debug)] +enum Test { + Foo, + Bar, + Baz, + Qux, +} + +fn test(x: Option<Box<Test>>) -> MatchArm { + match x { + Some(box Test::Foo | box Test::Bar) => MatchArm::Arm(0), + Some(box Test::Baz) => MatchArm::Arm(1), + Some(_) => MatchArm::Arm(2), + _ => MatchArm::Wild, + } +} + +fn main() { + assert_eq!(test(Some(Box::new(Test::Foo))), MatchArm::Arm(0)); + assert_eq!(test(Some(Box::new(Test::Bar))), MatchArm::Arm(0)); + assert_eq!(test(Some(Box::new(Test::Baz))), MatchArm::Arm(1)); + assert_eq!(test(Some(Box::new(Test::Qux))), MatchArm::Arm(2)); + assert_eq!(test(None), MatchArm::Wild); +} diff --git a/src/test/ui/or-patterns/slice-patterns.rs b/src/test/ui/or-patterns/slice-patterns.rs new file mode 100644 index 00000000000..2f2e865d985 --- /dev/null +++ b/src/test/ui/or-patterns/slice-patterns.rs @@ -0,0 +1,42 @@ +// Test or-patterns with slice-patterns + +// run-pass + +#![feature(or_patterns)] + +#[derive(Debug, PartialEq)] +enum MatchArm { + Arm(usize), + Wild, +} + +#[derive(Debug)] +enum Test { + Foo, + Bar, + Baz, + Qux, +} + +fn test(foo: &[Option<Test>]) -> MatchArm { + match foo { + [.., Some(Test::Foo | Test::Qux)] => MatchArm::Arm(0), + [Some(Test::Foo), .., Some(Test::Bar | Test::Baz)] => MatchArm::Arm(1), + [.., Some(Test::Bar | Test::Baz), _] => MatchArm::Arm(2), + _ => MatchArm::Wild, + } +} + +fn main() { + let foo = vec![ + Some(Test::Foo), + Some(Test::Bar), + Some(Test::Baz), + Some(Test::Qux), + ]; + + assert_eq!(test(&foo), MatchArm::Arm(0)); + assert_eq!(test(&foo[..3]), MatchArm::Arm(1)); + assert_eq!(test(&foo[1..3]), MatchArm::Arm(2)); + assert_eq!(test(&foo[4..]), MatchArm::Wild); +} |
