string: fix contains behaviour (closes #5371)

pull/5382/head
yuyi 2020-06-14 17:24:15 +08:00 committed by GitHub
parent 7e0197c1b8
commit 2ef0f15b34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 0 deletions

View File

@ -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
} }

View File

@ -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() {