| 1 | use v6; |
|---|
| 2 | |
|---|
| 3 | use Test; |
|---|
| 4 | |
|---|
| 5 | =begin kwid |
|---|
| 6 | |
|---|
| 7 | = DESCRIPTION |
|---|
| 8 | |
|---|
| 9 | Tests that the C<any()> and list quoting constructs |
|---|
| 10 | play well together and match well. |
|---|
| 11 | |
|---|
| 12 | The following should match: |
|---|
| 13 | |
|---|
| 14 | "foo" ~~ any <foo bar baz> |
|---|
| 15 | "foo" ~~ any(<foo bar baz>) |
|---|
| 16 | "bar" ~~ any <foo bar baz> |
|---|
| 17 | "bar" ~~ any(<foo bar baz>) |
|---|
| 18 | |
|---|
| 19 | The following should not match: |
|---|
| 20 | |
|---|
| 21 | "fo" ~~ any <foo bar baz> |
|---|
| 22 | "oo" ~~ any <foo bar baz> |
|---|
| 23 | "bar b" ~~ any <foo bar baz> |
|---|
| 24 | "bar baz" ~~ any(<foo bar baz>) |
|---|
| 25 | |
|---|
| 26 | Note: There is a small caveat regarding the convenient |
|---|
| 27 | C<< any <foo bar baz> >> syntax, if not used with parentheses: |
|---|
| 28 | |
|---|
| 29 | say( any <foo bar baz>,"Hello World") |
|---|
| 30 | |
|---|
| 31 | is different from |
|---|
| 32 | |
|---|
| 33 | say( (any <foo bar baz>), "Hello World") |
|---|
| 34 | |
|---|
| 35 | =end kwid |
|---|
| 36 | |
|---|
| 37 | my @matching_strings = <foo bar>; |
|---|
| 38 | my @nonmatching_strings = ('fo','foo ', 'foo bar baz', 'oo', 'bar b', 'bar baz'); |
|---|
| 39 | |
|---|
| 40 | plan ((+@matching_strings+@nonmatching_strings)*2); |
|---|
| 41 | |
|---|
| 42 | for @matching_strings -> $str { |
|---|
| 43 | ok( $str ~~ (any <foo bar baz>), "'$str' matches any <foo bar baz>" ); |
|---|
| 44 | ok( $str ~~ any(<foo bar baz>), "'$str' matches any(<foo bar baz>)" ); |
|---|
| 45 | }; |
|---|
| 46 | |
|---|
| 47 | for @nonmatching_strings -> $str { |
|---|
| 48 | ok( ($str !~~ any <foo bar baz>), "'$str' does not match any <foo bar baz>" ); |
|---|
| 49 | ok( $str !~~ any(<foo bar baz>), "'$str' does not match any(<foo bar baz>)" ); |
|---|
| 50 | }; |
|---|