JS: Fix buggy test cases

This commit is contained in:
Asger Feldthaus
2020-01-07 10:19:09 +00:00
parent 2d534163d0
commit 66a16d21a9
2 changed files with 7 additions and 5 deletions

View File

@@ -3,4 +3,6 @@
| tst.js:22:11:22:34 | ^(?:https?:\|ftp:\|file:)? | This regular expression always matches when used in a test $@, as it can match an empty substring. | tst.js:22:10:22:43 | /^(?:ht ... test(x) | here |
| tst.js:30:11:30:20 | (foo\|bar)? | This regular expression always matches when used in a test $@, as it can match an empty substring. | tst.js:30:10:30:29 | /(foo\|bar)?/.test(x) | here |
| tst.js:34:21:34:26 | (baz)? | This regular expression always matches when used in a test $@, as it can match an empty substring. | tst.js:34:10:34:35 | /^foo\|b ... test(x) | here |
| tst.js:58:20:58:25 | [a-z]* | This regular expression always the matches at index 0 when used $@, as it matches the empty substring. | tst.js:58:10:58:27 | x.search(/[a-z]*/) | here |
| tst.js:70:20:70:26 | ^(foo)? | This regular expression always the matches at index 0 when used $@, as it matches the empty substring. | tst.js:70:10:70:28 | x.search(/^(foo)?/) | here |
| tst.js:86:22:86:21 | | This regular expression always matches when used in a test $@, as it can match an empty substring. | tst.js:86:10:86:31 | new Reg ... test(x) | here |

View File

@@ -55,23 +55,23 @@ function emptyAlt3(x) {
}
function search(x) {
return /[a-z]*/.search(x); // NOT OK
return x.search(/[a-z]*/); // NOT OK
}
function search2(x) {
return /[a-z]/.search(x); // OK
return x.search(/[a-z]/); // OK
}
function lookahead(x) {
return /(?!x)/.search(x); // OK
return x.search(/(?!x)/); // OK
}
function searchPrefix(x) {
return /^foo?/.search(x); // NOT OK - `foo?` does not affect the returned index
return x.search(/^(foo)?/); // NOT OK - `foo?` does not affect the returned index
}
function searchSuffix(x) {
return /foo?$/.search(x); // OK - `foo?` affects the returned index
return x.search(/(foo)?$/); // OK - `foo?` affects the returned index
}
function wordBoundary(x) {