onig.test
This file
Path
tests/onig.test
224 lines · 5.0 KiB
Last changed by
Advance past the whole codepoint after a zero-width regex match (#3586)WinkleMadbefore adoptionf1f39b4
History of this fileTake it
The walk stopped after 200 commits: lines older than fa6a2ff point at it.
website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff
lines 1–13why, one step back1# match builtin2[match("( )*"; "g")]3"abc"4[{"offset":0,"length":0,"string":"","captures":[{"offset":-1,"string":null,"length":0,"name":null}]},{"offset":1,"length":0,"string":"","captures":[{"offset":-1,"string":null,"length":0,"name":null}]},{"offset":2,"length":0,"string":"","captures":[{"offset":-1,"string":null,"length":0,"name":null}]},{"offset":3,"length":0,"string":"","captures":[{"offset":-1,"string":null,"length":0,"name":null}]}]56[match("( )*"; "gn")]7"abc"8[]910[match(""; "g")]11"ab"12[{"offset":0,"length":0,"string":"","captures":[]},{"offset":1,"length":0,"string":"","captures":[]},{"offset":2,"length":0,"string":"","captures":[]}]13Advance past the whole codepoint after a zero-width regex match (#3586)WinkleMadbefore adoptionf1f39b4
lines 14–26why, one step back14# global zero-width matches must not land inside a multibyte character15[match(""; "g") | .offset]16"aé€🚀b"17[0,1,2,3,4,5]1819gsub(""; "-")20"aé"21"-a-é-"2223[splits("")]24"aé"25["","a","é",""]26website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff
lines 27–207why, one step back27[match("a"; "gi")]28"āáàä"29[]3031[match(["(bar)"])]32"foo bar"33[{"offset": 4, "length": 3, "string": "bar", "captures":[{"offset": 4, "length": 3, "string": "bar", "name": null}]}]3435# offsets account for combining codepoints and multi-byte UTF-836[match("bar")]37"ā bar with a combining codepoint U+0304"38[{"offset": 3, "length": 3, "string": "bar", "captures":[]}]3940# matches with combining codepoints still count them in their length41[match("bār")]42"a bār"43[{"offset": 2, "length": 4, "string": "bār", "captures":[]}]4445[match(".+?\\b")]46"ā two-codepoint grapheme"47[{"offset": 0, "length": 2, "string": "ā", "captures":[]}]4849[match(["foo (?<bar123>bar)? foo", "ig"])]50"foo bar foo foo foo"51[{"offset": 0, "length": 11, "string": "foo bar foo", "captures":[{"offset": 4, "length": 3, "string": "bar", "name": "bar123"}]},{"offset":12, "length": 8, "string": "foo foo", "captures":[{"offset": -1, "length": 0, "string": null, "name": "bar123"}]}]5253# non-matched optional group54"a","b","c" | capture("(?<x>a)?b?")55null56{"x":"a"}57{"x":null}58{"x":null}5960"a","b","c" | match("(?<x>a)?b?")61null62{"offset":0,"length":1,"string":"a","captures":[{"offset":0,"length":1,"string":"a","name":"x"}]}63{"offset":0,"length":1,"string":"b","captures":[{"offset":-1,"string":null,"length":0,"name":"x"}]}64{"offset":0,"length":0,"string":"","captures":[{"offset":-1,"string":null,"length":0,"name":"x"}]}6566# same as above but allow empty match for group67"a","b","c" | capture("(?<x>a?)?b?")68null69{"x":"a"}70{"x":""}71{"x":""}7273"a","b","c" | match("(?<x>a?)?b?")74null75{"offset":0,"length":1,"string":"a","captures":[{"offset":0,"length":1,"string":"a","name":"x"}]}76{"offset":0,"length":1,"string":"b","captures":[{"offset":0,"string":"","length":0,"name":"x"}]}77{"offset":0,"length":0,"string":"","captures":[{"offset":0,"string":"","length":0,"name":"x"}]}7879#test builtin80[test("( )*"; "gn")]81"abc"82[false]8384[test("ā")]85"ā"86[true]8788capture("(?<a>[a-z]+)-(?<n>[0-9]+)")89"xyzzy-14"90{"a":"xyzzy","n":"14"}919293# jq-coded utilities built on match:94#95# The second element in these tests' inputs tests the case where the96# fromstring matches both the head and tail of the string97[.[] | sub(", "; ":")]98["a,b, c, d, e,f", ", a,b, c, d, e,f, "]99["a,b:c, d, e,f",":a,b, c, d, e,f, "]100101sub("^(?<head>.)"; "Head=\(.head) Tail=")102"abcdef"103"Head=a Tail=bcdef"104105[.[] | gsub(", "; ":")]106["a,b, c, d, e,f",", a,b, c, d, e,f, "]107["a,b:c:d:e,f",":a,b:c:d:e,f:"]108109gsub("(?<d>\\d)"; ":\(.d);")110"a1b2"111"a:1;b:2;"112113gsub("a";"b")114"aaaaa"115"bbbbb"116117gsub("(.*)"; ""; "x")118""119""120121gsub(""; "a"; "g")122""123"a"124125gsub("^"; ""; "g")126"a"127"a"128129gsub(""; "a"; "g")130"a"131"aaa"132133gsub("$"; "a"; "g")134"a"135"aa"136137gsub("^"; "a")138""139"a"140141gsub("(?=u)"; "u")142"qux"143"quux"144145gsub("^.*a"; "b")146"aaa"147"b"148149gsub("^.*?a"; "b")150"aaa"151"baa"152153# The following is for regression testing and should not be construed as a requirement:154[gsub("a"; "b", "c")]155"a"156["b","c"]157158[.[] | scan(", ")]159["a,b, c, d, e,f",", a,b, c, d, e,f, "]160[", ",", ",", ",", ",", ",", ",", ",", "]161162[.[]|[[sub(", *";":")], [gsub(", *";":")], [scan(", *")]]]163["a,b, c, d, e,f",", a,b, c, d, e,f, "]164[[["a:b, c, d, e,f"],["a:b:c:d:e:f"],[",",", ",", ",", ",","]],[[":a,b, c, d, e,f, "],[":a:b:c:d:e:f:"],[", ",",",", ",", ",", ",",",", "]]]165166[.[]|[[sub(", +";":")], [gsub(", +";":")], [scan(", +")]]]167["a,b, c, d, e,f",", a,b, c, d, e,f, "]168[[["a,b:c, d, e,f"],["a,b:c:d:e,f"],[", ",", ",", "]],[[":a,b, c, d, e,f, "],[":a,b:c:d:e,f:"],[", ",", ",", ",", ",", "]]]169170[.[] | scan("b+"; "i")]171["","bBb","abcABBBCabbbc"]172["bBb","b","BBB","bbb"]173174# reference to named captures175gsub("(?<x>.)[^a]*"; "+\(.x)-")176"Abcabc"177"+A-+a-"178179gsub("(?<x>.)(?<y>[0-9])"; "\(.x|ascii_downcase)\(.y)")180"A1 B2 CD"181"a1 b2 CD"182183gsub("\\b(?<x>.)"; "\(.x|ascii_downcase)")184"ABC DEF"185"aBC dEF"186187gsub("[^a-z]*(?<x>[a-z]*)"; "Z\(.x)")188"123foo456bar"189"ZfooZbarZ"190191# utf-8192sub("(?<x>.)"; "\(.x)!")193"’"194"’!"195196[sub("a"; "b", "c")]197"a"198["b","c"]199200[sub("(?<a>.)"; "\(.a|ascii_upcase)", "\(.a|ascii_downcase)", "c")]201"aB"202["AB","aB","cB"]203204[gsub("(?<a>.)"; "\(.a|ascii_upcase)", "\(.a|ascii_downcase)", "c")]205"aB"206["AB","ab","cc"]207Refactor splits/2 using foreach syntax (remove private filter _nwise) (#3260)itchynybefore adoptionb088e83
line 208why, one step back208# splitswebsite: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff
lines 209–211why, one step back209[splits("")]210"ab"211["","a","b",""]Refactor splits/2 using foreach syntax (remove private filter _nwise) (#3260)itchynybefore adoptionb088e83
lines 212–223why, one step back212213[splits("c")]214"ab"215["ab"]216217[splits("a+"; "i")]218"abAABBabA"219["","b","BB","b",""]220221[splits("b+"; "i")]222"abAABBabA"223["a","AA","a","A"]website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff
line 224why, one step back224