diff options
Diffstat (limited to 'test/testdata/eval-okay-regex-split.nix')
-rw-r--r-- | test/testdata/eval-okay-regex-split.nix | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/testdata/eval-okay-regex-split.nix b/test/testdata/eval-okay-regex-split.nix new file mode 100644 index 0000000..0073e05 --- /dev/null +++ b/test/testdata/eval-okay-regex-split.nix | |||
@@ -0,0 +1,48 @@ | |||
1 | with builtins; | ||
2 | |||
3 | # Non capturing regex returns empty lists | ||
4 | assert split "foobar" "foobar" == ["" [] ""]; | ||
5 | assert split "fo*" "f" == ["" [] ""]; | ||
6 | assert split "fo+" "f" == ["f"]; | ||
7 | assert split "fo*" "fo" == ["" [] ""]; | ||
8 | assert split "fo*" "foo" == ["" [] ""]; | ||
9 | assert split "fo+" "foo" == ["" [] ""]; | ||
10 | assert split "fo{1,2}" "foo" == ["" [] ""]; | ||
11 | assert split "fo{1,2}" "fooo" == ["" [] "o"]; | ||
12 | assert split "fo*" "foobar" == ["" [] "bar"]; | ||
13 | |||
14 | # Capturing regex returns a list of sub-matches | ||
15 | assert split "(fo*)" "f" == ["" ["f"] ""]; | ||
16 | assert split "(fo+)" "f" == ["f"]; | ||
17 | assert split "(fo*)" "fo" == ["" ["fo"] ""]; | ||
18 | assert split "(f)(o*)" "f" == ["" ["f" ""] ""]; | ||
19 | assert split "(f)(o*)" "foo" == ["" ["f" "oo"] ""]; | ||
20 | assert split "(fo+)" "foo" == ["" ["foo"] ""]; | ||
21 | assert split "(fo{1,2})" "foo" == ["" ["foo"] ""]; | ||
22 | assert split "(fo{1,2})" "fooo" == ["" ["foo"] "o"]; | ||
23 | assert split "(fo*)" "foobar" == ["" ["foo"] "bar"]; | ||
24 | |||
25 | # Matches are greedy. | ||
26 | assert split "(o+)" "oooofoooo" == ["" ["oooo"] "f" ["oooo"] ""]; | ||
27 | |||
28 | # Matches multiple times. | ||
29 | assert split "(b)" "foobarbaz" == ["foo" ["b"] "ar" ["b"] "az"]; | ||
30 | |||
31 | # Split large strings containing newlines. null are inserted when a | ||
32 | # pattern within the current did not match anything. | ||
33 | assert split "[[:space:]]+|([',.!?])" '' | ||
34 | Nix Rocks! | ||
35 | That's why I use it. | ||
36 | '' == [ | ||
37 | "Nix" [ null ] "Rocks" ["!"] "" [ null ] | ||
38 | "That" ["'"] "s" [ null ] "why" [ null ] "I" [ null ] "use" [ null ] "it" ["."] "" [ null ] | ||
39 | "" | ||
40 | ]; | ||
41 | |||
42 | # Documentation examples | ||
43 | assert split "(a)b" "abc" == [ "" [ "a" ] "c" ]; | ||
44 | assert split "([ac])" "abc" == [ "" [ "a" ] "b" [ "c" ] "" ]; | ||
45 | assert split "(a)|(c)" "abc" == [ "" [ "a" null ] "b" [ null "c" ] "" ]; | ||
46 | assert split "([[:upper:]]+)" " FOO " == [ " " [ "FOO" ] " " ]; | ||
47 | |||
48 | true | ||