string: fix contains behaviour (closes #5371)
parent
7e0197c1b8
commit
2ef0f15b34
|
@ -716,6 +716,9 @@ pub fn (s string) count(substr string) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (s string) contains(p string) bool {
|
pub fn (s string) contains(p string) bool {
|
||||||
|
if p.len == 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
s.index(p) or {
|
s.index(p) or {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -357,6 +357,8 @@ fn test_contains() {
|
||||||
s := 'view.v'
|
s := 'view.v'
|
||||||
assert s.contains('vi')
|
assert s.contains('vi')
|
||||||
assert !s.contains('random')
|
assert !s.contains('random')
|
||||||
|
assert ''.contains('')
|
||||||
|
assert 'abc'.contains('')
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_arr_contains() {
|
fn test_arr_contains() {
|
||||||
|
|
Loading…
Reference in New Issue