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:
@ -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
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user