Skip to content

Commit b4788a7

Browse files
committed
test(pattern): harden tests for or-patterns with slice-patterns
Some of the nested OR paths were being missed
1 parent 5456114 commit b4788a7

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/test/ui/or-patterns/slice-patterns.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ enum Test {
2020

2121
fn test(foo: &[Option<Test>]) -> MatchArm {
2222
match foo {
23-
[.., Some(Test::Foo | Test::Qux)] => MatchArm::Arm(0),
24-
[Some(Test::Foo), .., Some(Test::Bar | Test::Baz)] => MatchArm::Arm(1),
23+
[.., Some(Test::Qux | Test::Foo)] => MatchArm::Arm(0),
24+
[Some(Test::Foo), .., Some(Test::Baz | Test::Bar)] => MatchArm::Arm(1),
2525
[.., Some(Test::Bar | Test::Baz), _] => MatchArm::Arm(2),
2626
_ => MatchArm::Wild,
2727
}
@@ -35,8 +35,18 @@ fn main() {
3535
Some(Test::Qux),
3636
];
3737

38+
// path 1a
3839
assert_eq!(test(&foo), MatchArm::Arm(0));
40+
// path 1b
41+
assert_eq!(test(&[Some(Test::Bar), Some(Test::Foo)]), MatchArm::Arm(0));
42+
// path 2a
3943
assert_eq!(test(&foo[..3]), MatchArm::Arm(1));
44+
// path 2b
45+
assert_eq!(test(&[Some(Test::Foo), Some(Test::Foo), Some(Test::Bar)]), MatchArm::Arm(1));
46+
// path 3a
4047
assert_eq!(test(&foo[1..3]), MatchArm::Arm(2));
48+
// path 3b
49+
assert_eq!(test(&[Some(Test::Bar), Some(Test::Baz), Some(Test::Baz), Some(Test::Bar)]), MatchArm::Arm(2));
50+
// path 4
4151
assert_eq!(test(&foo[4..]), MatchArm::Wild);
4252
}

src/test/ui/pattern/bindings-after-at/or-patterns-slice-patterns.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ enum Test {
2121

2222
fn test(foo: &[Option<Test>]) -> MatchArm {
2323
match foo {
24-
bar @ [Some(Test::Foo), .., Some(Test::Foo | Test::Qux)] => {
24+
bar @ [Some(Test::Foo), .., Some(Test::Qux | Test::Foo)] => {
2525
assert_eq!(bar, foo);
2626

2727
MatchArm::Arm(0)
@@ -36,8 +36,21 @@ fn test(foo: &[Option<Test>]) -> MatchArm {
3636
}
3737

3838
fn main() {
39-
let foo = vec![Some(Test::Foo), Some(Test::Bar), Some(Test::Baz), Some(Test::Qux)];
39+
let foo = vec![
40+
Some(Test::Foo),
41+
Some(Test::Bar),
42+
Some(Test::Baz),
43+
Some(Test::Qux),
44+
];
45+
46+
// path 1a
4047
assert_eq!(test(&foo), MatchArm::Arm(0));
48+
// path 1b
49+
assert_eq!(test(&[Some(Test::Foo), Some(Test::Bar), Some(Test::Foo)]), MatchArm::Arm(0));
50+
// path 2a
4151
assert_eq!(test(&foo[..3]), MatchArm::Arm(1));
52+
// path 2b
53+
assert_eq!(test(&[Some(Test::Bar), Some(Test::Qux), Some(Test::Baz)]), MatchArm::Arm(1));
54+
// path 3
4255
assert_eq!(test(&foo[1..2]), MatchArm::Wild);
4356
}

0 commit comments

Comments
 (0)