mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
regex: improve errors for edge cases (#13008)
* code cleaning, added more clear errors for dots and ORs * added failed match index for better find functions, updated tests * added index in match failed, updated tests * test cleaning * test check
This commit is contained in:
@ -18,7 +18,7 @@ const(
|
||||
match_test_suite = [
|
||||
// minus in CC
|
||||
TestItem{"d.def",r"abc.\.[\w\-]{,100}",-1,0},
|
||||
TestItem{"abc12345.asd",r"abc.\.[\w\-]{,100}",-1,0},
|
||||
TestItem{"abc12345.asd",r"abc.\.[\w\-]{,100}",-1,4},
|
||||
TestItem{"abca.exe",r"abc.\.[\w\-]{,100}",0,8},
|
||||
TestItem{"abc2.exe-test_12",r"abc.\.[\w\-]{,100}",0,16},
|
||||
TestItem{"abcdefGHK",r"[a-f]+\A+",0,9},
|
||||
@ -96,30 +96,30 @@ match_test_suite = [
|
||||
|
||||
// negative
|
||||
TestItem{"zthis ciao",r"((t[hieo]+se?)\s*)+",-1,0},
|
||||
TestItem{"this is a good.",r"thes",-1,0},
|
||||
TestItem{"test1post.pip.com, pera",r"[\w]+@([\w]+\.)+\w+",-1,0},
|
||||
TestItem{"this is a good.",r"thes",-1,2},
|
||||
TestItem{"test1post.pip.com, pera",r"[\w]+@([\w]+\.)+\w+",-1,9},
|
||||
TestItem{"this cpapaz adce",r"(c(pa)+z)(\s[\a]+){2}",-1,0},
|
||||
TestItem{"this cpapaz adce aabe third",r"(c(pa)+z)(\s[\a]+){2}$",-1,0},
|
||||
TestItem{"1234this cpapaz adce aabe ter",r"(c(pa)+z)(\s[\a]+){2}$",-1,0},
|
||||
TestItem{"cpapaz ole. pipipo,",r"^.*c.+ol?e.*p([ip])+o$",-1,0},
|
||||
TestItem{"/home/us_er/pippo/info-01.jpeg", r"(/?[-\w_]+)*\.txt$",-1,0}
|
||||
TestItem{"/home/us_er/pippo/info-01.jpeg", r"(/?[-\w_]+)*\.txt$",-1,26}
|
||||
|
||||
// check unicode
|
||||
TestItem{"this is a Ⅰ Ⅱ Ⅲ Ⅳ Ⅴ Ⅵ test",r".*a [Ⅰ-Ⅵ ]+",0,34},
|
||||
TestItem{"123Ⅰ Ⅱ Ⅲ Ⅳ Ⅴ Ⅵ test",r"[Ⅰ-Ⅴ\s]+",3,23},
|
||||
|
||||
// new edge cases
|
||||
TestItem{"12345678", r"[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]",-1,0},
|
||||
TestItem{"12345678", r"[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]",-1,8},
|
||||
TestItem{"12345678", r"[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]",0,8},
|
||||
TestItem{"123456789", r"^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$",0,9}
|
||||
TestItem{"12345678", r"^\d{8}$",0,8},
|
||||
TestItem{"12345678", r"^\d{7}$",-1,0},
|
||||
TestItem{"12345678", r"^\d{9}$",-1,0},
|
||||
TestItem{"12345678", r"^\d{9}$",-1,8},
|
||||
|
||||
TestItem{"eth", r"(oth)|(eth)",0,3},
|
||||
TestItem{"et", r"(oth)|(eth)",-1,0},
|
||||
TestItem{"et", r".*(oth)|(eth)",-1,0},
|
||||
TestItem{"peoth", r".*(ith)|(eth)",-1,0},
|
||||
TestItem{"et", r"(oth)|(eth)",-1,2},
|
||||
TestItem{"et", r".*(oth)|(eth)",-1,2},
|
||||
TestItem{"peoth", r".*(ith)|(eth)",-1,5},
|
||||
|
||||
TestItem{"poth", r"(eth)|(oth)",1,4},
|
||||
TestItem{"poth", r"(oth)|(eth)",1,4},
|
||||
@ -132,7 +132,7 @@ match_test_suite = [
|
||||
TestItem{"accccb deer", r"^a(.*)b d(.+)r",0,11},
|
||||
TestItem{"accccb deer", r"^a(.*)b d(.+)",0,11},
|
||||
TestItem{"accccb deer", r"^(.*)$",0,11},
|
||||
TestItem{"accccb deer", r"^a(.*)b d(.+)p",-1,0},
|
||||
TestItem{"accccb deer", r"^a(.*)b d(.+)p",-1,11},
|
||||
TestItem{"##.#....#.##.####...#.##", r".{18}[.#]",0,19},
|
||||
TestItem{"#.#......##.#..#..##........##....###...##...######.......#.....#..#......#...#........###.#..#.", r'.*#[.#]{4}##[.#]{4}##[.#]{4}###',0,49},
|
||||
|
||||
@ -328,19 +328,19 @@ find_all_test_suite = [
|
||||
[29, 49],
|
||||
['#....###...##...####']
|
||||
},
|
||||
Test_find_all{
|
||||
Test_find_all{
|
||||
"#.#......##.#..#..##........##....###...##...######.......#.....#..#......#...#........###.#..#.",
|
||||
r".*#[.#]{4}##[.#]{4}##[.#]{4}###",
|
||||
[0, 49],
|
||||
['#.#......##.#..#..##........##....###...##...####']
|
||||
},
|
||||
Test_find_all{
|
||||
Test_find_all{
|
||||
"1234 Aa dddd Aaf 12334 Aa opopo Aaf",
|
||||
r"Aa.+Aaf",
|
||||
[5, 16, 23, 35],
|
||||
['Aa dddd Aaf', 'Aa opopo Aaf']
|
||||
},
|
||||
Test_find_all{
|
||||
Test_find_all{
|
||||
"@for something @endfor @for something else @endfor altro testo @for body @endfor uno due @for senza dire più @endfor pippo",
|
||||
r"@for.+@endfor",
|
||||
[0, 22, 23, 50, 63, 80, 89, 117],
|
||||
|
Reference in New Issue
Block a user