diff options
Diffstat (limited to 'stdlib/source/test/lux/data/text/regex.lux')
-rw-r--r-- | stdlib/source/test/lux/data/text/regex.lux | 248 |
1 files changed, 124 insertions, 124 deletions
diff --git a/stdlib/source/test/lux/data/text/regex.lux b/stdlib/source/test/lux/data/text/regex.lux index f72c19030..3998f78f7 100644 --- a/stdlib/source/test/lux/data/text/regex.lux +++ b/stdlib/source/test/lux/data/text/regex.lux @@ -21,7 +21,7 @@ {1 ["." /]}) -(def: (should-pass regex input) +(def: (should_pass regex input) (-> (Parser Text) Text Bit) (|> input (<text>.run regex) @@ -31,7 +31,7 @@ _ #0))) -(def: (text-should-pass test regex input) +(def: (text_should_pass test regex input) (-> Text (Parser Text) Text Bit) (|> input (<text>.run regex) @@ -41,7 +41,7 @@ _ false))) -(def: (should-fail regex input) +(def: (should_fail regex input) (All [a] (-> (Parser a) Text Bit)) (|> input (<text>.run regex) @@ -51,220 +51,220 @@ _ false))) -(syntax: (should-check pattern regex input) - (meta.with-gensyms [g!message g!_] - (wrap (list (` (|> (~ input) - (<text>.run (~ regex)) - (case> (^ (#try.Success (~ pattern))) - true +(syntax: (should_check pattern regex input) + (meta.with_gensyms [g!message g!_] + (wrap (list (` (|> (~ input) + (<text>.run (~ regex)) + (case> (^ (#try.Success (~ pattern))) + true - (~ g!_) - false))))))) + (~ g!_) + false))))))) (def: basics Test (_.test "Can parse character literals." - (and (should-pass (/.regex "a") "a") - (should-fail (/.regex "a") ".") - (should-pass (/.regex "\.") ".") - (should-fail (/.regex "\.") "a")))) + (and (should_pass (/.regex "a") "a") + (should_fail (/.regex "a") ".") + (should_pass (/.regex "\.") ".") + (should_fail (/.regex "\.") "a")))) -(def: system-character-classes +(def: system_character_classes Test ($_ _.and (_.test "Can parse anything." - (should-pass (/.regex ".") "a")) + (should_pass (/.regex ".") "a")) (_.test "Can parse digits." - (and (should-pass (/.regex "\d") "0") - (should-fail (/.regex "\d") "m"))) + (and (should_pass (/.regex "\d") "0") + (should_fail (/.regex "\d") "m"))) (_.test "Can parse non digits." - (and (should-pass (/.regex "\D") "m") - (should-fail (/.regex "\D") "0"))) + (and (should_pass (/.regex "\D") "m") + (should_fail (/.regex "\D") "0"))) (_.test "Can parse white-space." - (and (should-pass (/.regex "\s") " ") - (should-fail (/.regex "\s") "m"))) + (and (should_pass (/.regex "\s") " ") + (should_fail (/.regex "\s") "m"))) (_.test "Can parse non white-space." - (and (should-pass (/.regex "\S") "m") - (should-fail (/.regex "\S") " "))) + (and (should_pass (/.regex "\S") "m") + (should_fail (/.regex "\S") " "))) (_.test "Can parse word characters." - (and (should-pass (/.regex "\w") "_") - (should-fail (/.regex "\w") "^"))) + (and (should_pass (/.regex "\w") "_") + (should_fail (/.regex "\w") "^"))) (_.test "Can parse non word characters." - (and (should-pass (/.regex "\W") ".") - (should-fail (/.regex "\W") "a"))) + (and (should_pass (/.regex "\W") ".") + (should_fail (/.regex "\W") "a"))) )) -(def: special-system-character-classes +(def: special_system_character_classes Test ($_ _.and (_.test "Lower-case." - (and (should-pass (/.regex "\p{Lower}") "m") - (should-fail (/.regex "\p{Lower}") "M"))) + (and (should_pass (/.regex "\p{Lower}") "m") + (should_fail (/.regex "\p{Lower}") "M"))) (_.test "Upper-case." - (and (should-pass (/.regex "\p{Upper}") "M") - (should-fail (/.regex "\p{Upper}") "m"))) + (and (should_pass (/.regex "\p{Upper}") "M") + (should_fail (/.regex "\p{Upper}") "m"))) (_.test "Alphabetic." - (and (should-pass (/.regex "\p{Alpha}") "M") - (should-fail (/.regex "\p{Alpha}") "0"))) + (and (should_pass (/.regex "\p{Alpha}") "M") + (should_fail (/.regex "\p{Alpha}") "0"))) (_.test "Numeric digits." - (and (should-pass (/.regex "\p{Digit}") "1") - (should-fail (/.regex "\p{Digit}") "n"))) + (and (should_pass (/.regex "\p{Digit}") "1") + (should_fail (/.regex "\p{Digit}") "n"))) (_.test "Alphanumeric." - (and (should-pass (/.regex "\p{Alnum}") "1") - (should-fail (/.regex "\p{Alnum}") "."))) + (and (should_pass (/.regex "\p{Alnum}") "1") + (should_fail (/.regex "\p{Alnum}") "."))) (_.test "Whitespace." - (and (should-pass (/.regex "\p{Space}") " ") - (should-fail (/.regex "\p{Space}") "."))) + (and (should_pass (/.regex "\p{Space}") " ") + (should_fail (/.regex "\p{Space}") "."))) (_.test "Hexadecimal." - (and (should-pass (/.regex "\p{HexDigit}") "a") - (should-fail (/.regex "\p{HexDigit}") "."))) + (and (should_pass (/.regex "\p{HexDigit}") "a") + (should_fail (/.regex "\p{HexDigit}") "."))) (_.test "Octal." - (and (should-pass (/.regex "\p{OctDigit}") "6") - (should-fail (/.regex "\p{OctDigit}") "."))) + (and (should_pass (/.regex "\p{OctDigit}") "6") + (should_fail (/.regex "\p{OctDigit}") "."))) (_.test "Blank." - (and (should-pass (/.regex "\p{Blank}") text.tab) - (should-fail (/.regex "\p{Blank}") "."))) + (and (should_pass (/.regex "\p{Blank}") text.tab) + (should_fail (/.regex "\p{Blank}") "."))) (_.test "ASCII." - (and (should-pass (/.regex "\p{ASCII}") text.tab) - (should-fail (/.regex "\p{ASCII}") (text.from-code (hex "1234"))))) + (and (should_pass (/.regex "\p{ASCII}") text.tab) + (should_fail (/.regex "\p{ASCII}") (text.from_code (hex "1234"))))) (_.test "Control characters." - (and (should-pass (/.regex "\p{Contrl}") (text.from-code (hex "12"))) - (should-fail (/.regex "\p{Contrl}") "a"))) + (and (should_pass (/.regex "\p{Contrl}") (text.from_code (hex "12"))) + (should_fail (/.regex "\p{Contrl}") "a"))) (_.test "Punctuation." - (and (should-pass (/.regex "\p{Punct}") "@") - (should-fail (/.regex "\p{Punct}") "a"))) + (and (should_pass (/.regex "\p{Punct}") "@") + (should_fail (/.regex "\p{Punct}") "a"))) (_.test "Graph." - (and (should-pass (/.regex "\p{Graph}") "@") - (should-fail (/.regex "\p{Graph}") " "))) + (and (should_pass (/.regex "\p{Graph}") "@") + (should_fail (/.regex "\p{Graph}") " "))) (_.test "Print." - (and (should-pass (/.regex "\p{Print}") (text.from-code (hex "20"))) - (should-fail (/.regex "\p{Print}") (text.from-code (hex "1234"))))) + (and (should_pass (/.regex "\p{Print}") (text.from_code (hex "20"))) + (should_fail (/.regex "\p{Print}") (text.from_code (hex "1234"))))) )) -(def: custom-character-classes +(def: custom_character_classes Test ($_ _.and (_.test "Can parse using custom character classes." - (and (should-pass (/.regex "[abc]") "a") - (should-fail (/.regex "[abc]") "m"))) + (and (should_pass (/.regex "[abc]") "a") + (should_fail (/.regex "[abc]") "m"))) (_.test "Can parse using character ranges." - (and (should-pass (/.regex "[a-z]") "a") - (should-pass (/.regex "[a-z]") "m") - (should-pass (/.regex "[a-z]") "z"))) + (and (should_pass (/.regex "[a-z]") "a") + (should_pass (/.regex "[a-z]") "m") + (should_pass (/.regex "[a-z]") "z"))) (_.test "Can combine character ranges." - (and (should-pass (/.regex "[a-zA-Z]") "a") - (should-pass (/.regex "[a-zA-Z]") "m") - (should-pass (/.regex "[a-zA-Z]") "z") - (should-pass (/.regex "[a-zA-Z]") "A") - (should-pass (/.regex "[a-zA-Z]") "M") - (should-pass (/.regex "[a-zA-Z]") "Z"))) + (and (should_pass (/.regex "[a-zA-Z]") "a") + (should_pass (/.regex "[a-zA-Z]") "m") + (should_pass (/.regex "[a-zA-Z]") "z") + (should_pass (/.regex "[a-zA-Z]") "A") + (should_pass (/.regex "[a-zA-Z]") "M") + (should_pass (/.regex "[a-zA-Z]") "Z"))) (_.test "Can negate custom character classes." - (and (should-fail (/.regex "[^abc]") "a") - (should-pass (/.regex "[^abc]") "m"))) + (and (should_fail (/.regex "[^abc]") "a") + (should_pass (/.regex "[^abc]") "m"))) (_.test "Can negate character ranges.." - (and (should-fail (/.regex "[^a-z]") "a") - (should-pass (/.regex "[^a-z]") "0"))) + (and (should_fail (/.regex "[^a-z]") "a") + (should_pass (/.regex "[^a-z]") "0"))) (_.test "Can parse negate combinations of character ranges." - (and (should-fail (/.regex "[^a-zA-Z]") "a") - (should-pass (/.regex "[^a-zA-Z]") "0"))) + (and (should_fail (/.regex "[^a-zA-Z]") "a") + (should_pass (/.regex "[^a-zA-Z]") "0"))) (_.test "Can make custom character classes more specific." (and (let [RE (/.regex "[a-z&&[def]]")] - (and (should-fail RE "a") - (should-pass RE "d"))) + (and (should_fail RE "a") + (should_pass RE "d"))) (let [RE (/.regex "[a-z&&[^bc]]")] - (and (should-pass RE "a") - (should-fail RE "b"))) + (and (should_pass RE "a") + (should_fail RE "b"))) (let [RE (/.regex "[a-z&&[^m-p]]")] - (and (should-pass RE "a") - (should-fail RE "m") - (should-fail RE "p"))))) + (and (should_pass RE "a") + (should_fail RE "m") + (should_fail RE "p"))))) )) (def: references Test (let [number (/.regex "\d+")] (_.test "Can build complex regexs by combining simpler ones." - (should-check ["809-345-6789" "809" "345" "6789"] + (should_check ["809-345-6789" "809" "345" "6789"] (/.regex "(\@<number>)-(\@<number>)-(\@<number>)") "809-345-6789")))) -(def: fuzzy-quantifiers +(def: fuzzy_quantifiers Test ($_ _.and (_.test "Can sequentially combine patterns." - (text-should-pass "aa" (/.regex "aa") "aa")) + (text_should_pass "aa" (/.regex "aa") "aa")) (_.test "Can match patterns optionally." - (and (text-should-pass "a" (/.regex "a?") "a") - (text-should-pass "" (/.regex "a?") ""))) + (and (text_should_pass "a" (/.regex "a?") "a") + (text_should_pass "" (/.regex "a?") ""))) (_.test "Can match a pattern 0 or more times." - (and (text-should-pass "aaa" (/.regex "a*") "aaa") - (text-should-pass "" (/.regex "a*") ""))) + (and (text_should_pass "aaa" (/.regex "a*") "aaa") + (text_should_pass "" (/.regex "a*") ""))) (_.test "Can match a pattern 1 or more times." - (and (text-should-pass "aaa" (/.regex "a+") "aaa") - (text-should-pass "a" (/.regex "a+") "a") - (should-fail (/.regex "a+") ""))) + (and (text_should_pass "aaa" (/.regex "a+") "aaa") + (text_should_pass "a" (/.regex "a+") "a") + (should_fail (/.regex "a+") ""))) )) -(def: crisp-quantifiers +(def: crisp_quantifiers Test ($_ _.and (_.test "Can match a pattern N times." - (and (text-should-pass "aa" (/.regex "a{2}") "aa") - (text-should-pass "a" (/.regex "a{1}") "a") - (should-fail (/.regex "a{3}") "aa"))) + (and (text_should_pass "aa" (/.regex "a{2}") "aa") + (text_should_pass "a" (/.regex "a{1}") "a") + (should_fail (/.regex "a{3}") "aa"))) (_.test "Can match a pattern at-least N times." - (and (text-should-pass "aa" (/.regex "a{1,}") "aa") - (text-should-pass "aa" (/.regex "a{2,}") "aa") - (should-fail (/.regex "a{3,}") "aa"))) + (and (text_should_pass "aa" (/.regex "a{1,}") "aa") + (text_should_pass "aa" (/.regex "a{2,}") "aa") + (should_fail (/.regex "a{3,}") "aa"))) (_.test "Can match a pattern at-most N times." - (and (text-should-pass "aa" (/.regex "a{,2}") "aa") - (text-should-pass "aa" (/.regex "a{,3}") "aa"))) + (and (text_should_pass "aa" (/.regex "a{,2}") "aa") + (text_should_pass "aa" (/.regex "a{,3}") "aa"))) (_.test "Can match a pattern between N and M times." - (and (text-should-pass "a" (/.regex "a{1,2}") "a") - (text-should-pass "aa" (/.regex "a{1,2}") "aa"))) + (and (text_should_pass "a" (/.regex "a{1,2}") "a") + (text_should_pass "aa" (/.regex "a{1,2}") "aa"))) )) (def: groups Test ($_ _.and (_.test "Can extract groups of sub-matches specified in a pattern." - (and (should-check ["abc" "b"] (/.regex "a(.)c") "abc") - (should-check ["abbbbbc" "bbbbb"] (/.regex "a(b+)c") "abbbbbc") - (should-check ["809-345-6789" "809" "345" "6789"] (/.regex "(\d{3})-(\d{3})-(\d{4})") "809-345-6789") - (should-check ["809-345-6789" "809" "6789"] (/.regex "(\d{3})-(?:\d{3})-(\d{4})") "809-345-6789") - (should-check ["809-809-6789" "809" "6789"] (/.regex "(\d{3})-\0-(\d{4})") "809-809-6789") - (should-check ["809-809-6789" "809" "6789"] (/.regex "(?<code>\d{3})-\k<code>-(\d{4})") "809-809-6789") - (should-check ["809-809-6789-6789" "809" "6789"] (/.regex "(?<code>\d{3})-\k<code>-(\d{4})-\0") "809-809-6789-6789"))) + (and (should_check ["abc" "b"] (/.regex "a(.)c") "abc") + (should_check ["abbbbbc" "bbbbb"] (/.regex "a(b+)c") "abbbbbc") + (should_check ["809-345-6789" "809" "345" "6789"] (/.regex "(\d{3})-(\d{3})-(\d{4})") "809-345-6789") + (should_check ["809-345-6789" "809" "6789"] (/.regex "(\d{3})-(?:\d{3})-(\d{4})") "809-345-6789") + (should_check ["809-809-6789" "809" "6789"] (/.regex "(\d{3})-\0-(\d{4})") "809-809-6789") + (should_check ["809-809-6789" "809" "6789"] (/.regex "(?<code>\d{3})-\k<code>-(\d{4})") "809-809-6789") + (should_check ["809-809-6789-6789" "809" "6789"] (/.regex "(?<code>\d{3})-\k<code>-(\d{4})-\0") "809-809-6789-6789"))) (_.test "Can specify groups within groups." - (should-check ["809-345-6789" "809" ["345-6789" "345" "6789"]] (/.regex "(\d{3})-((\d{3})-(\d{4}))") "809-345-6789")) + (should_check ["809-345-6789" "809" ["345-6789" "345" "6789"]] (/.regex "(\d{3})-((\d{3})-(\d{4}))") "809-345-6789")) )) (def: alternation Test ($_ _.and (_.test "Can specify alternative patterns." - (and (should-check ["a" (0 #0 [])] (/.regex "a|b") "a") - (should-check ["b" (0 #1 [])] (/.regex "a|b") "b") - (should-fail (/.regex "a|b") "c"))) + (and (should_check ["a" (0 #0 [])] (/.regex "a|b") "a") + (should_check ["b" (0 #1 [])] (/.regex "a|b") "b") + (should_fail (/.regex "a|b") "c"))) (_.test "Can have groups within alternations." - (and (should-check ["abc" (0 #0 ["b" "c"])] (/.regex "a(.)(.)|b(.)(.)") "abc") - (should-check ["bcd" (0 #1 ["c" "d"])] (/.regex "a(.)(.)|b(.)(.)") "bcd") - (should-fail (/.regex "a(.)(.)|b(.)(.)") "cde") + (and (should_check ["abc" (0 #0 ["b" "c"])] (/.regex "a(.)(.)|b(.)(.)") "abc") + (should_check ["bcd" (0 #1 ["c" "d"])] (/.regex "a(.)(.)|b(.)(.)") "bcd") + (should_fail (/.regex "a(.)(.)|b(.)(.)") "cde") - (should-check ["123-456-7890" (0 #0 ["123" "456-7890" "456" "7890"])] + (should_check ["123-456-7890" (0 #0 ["123" "456-7890" "456" "7890"])] (/.regex "(\d{3})-((\d{3})-(\d{4}))|b(.)d") "123-456-7890"))) )) @@ -276,12 +276,12 @@ (_.for [/.regex] ($_ _.and ..basics - ..system-character-classes - ..special-system-character-classes - ..custom-character-classes + ..system_character_classes + ..special_system_character_classes + ..custom_character_classes ..references - ..fuzzy-quantifiers - ..crisp-quantifiers + ..fuzzy_quantifiers + ..crisp_quantifiers ..groups ..alternation )) |