1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

regex: implement negation groups, more flexibility for bsls, small fixes (#12981)

* removed memory allocations in cleaning during clear calls

* first test implementation of negative groups, more flexibility for bsls

* fixed bsls failed tests

* fmt

* added \n to regex tests
This commit is contained in:
penguindark
2021-12-27 21:18:48 +01:00
committed by GitHub
parent 14648fa41e
commit dadc965082
2 changed files with 248 additions and 38 deletions

View File

@ -760,3 +760,27 @@ fn test_long_query() {
//println("$start, $end")
assert start >= 0 && end == base_string.len
}
struct Test_negation_group {
src string
res bool
}
const(
negation_groups = [
Test_negation_group{'automobile',false},
Test_negation_group{'botomobile',true},
Test_negation_group{'auto_caravan',false},
Test_negation_group{'moto_mobile',true},
Test_negation_group{'pippole',true},
Test_negation_group{'boring test',false},
]
)
fn test_negation_groups() {
mut query := r"(?!auto)\w+le"
mut re := regex.regex_opt(query) or { panic(err) }
for test in negation_groups {
start, end := re.match_string(test.src)
assert (start >= 0) == test.res
}
}