✨ Added startsWith check to the match helper
no issue
This commit is contained in:
parent
a837cf0247
commit
3d08d00bdd
@ -57,6 +57,9 @@ const handleMatch = (data, operator, value) => {
|
||||
case '<=':
|
||||
result = data <= value;
|
||||
break;
|
||||
case 'startsWith':
|
||||
result = _.isString(data) && _.isString(value) && data.startsWith(value);
|
||||
break;
|
||||
default:
|
||||
result = data === value;
|
||||
}
|
||||
|
@ -246,6 +246,38 @@ describe('Match helper', function () {
|
||||
}, hash);
|
||||
});
|
||||
|
||||
describe('Explicit Starts With', function () {
|
||||
runTests({
|
||||
// Using string values
|
||||
'{{match empty "startsWith" ""}}': 'true',
|
||||
'{{match empty "startsWith" " "}}': 'false',
|
||||
'{{match string "startsWith" "Hello"}}': 'true',
|
||||
'{{match string "startsWith" "World"}}': 'false',
|
||||
'{{match string_true "startsWith" "tr"}}': 'true',
|
||||
'{{match string_false "startsWith" "tr"}}': 'false',
|
||||
'{{match safestring_string_false "startsWith" "fa"}}': 'true',
|
||||
'{{match safestring_string_true "startsWith" "fa"}}': 'false',
|
||||
'{{match string_five "startsWith" "5"}}': 'true',
|
||||
'{{match string_five "startsWith" "6"}}': 'false',
|
||||
'{{match object.foo "startsWith" "fo"}}': 'true',
|
||||
'{{match object.foo "startsWith" "ba"}}': 'false',
|
||||
'{{match array.[0] "startsWith" "fo"}}': 'true',
|
||||
'{{match array.[0] "startsWith" "ba"}}': 'false',
|
||||
|
||||
// Using non-string values
|
||||
'{{match zero "startsWith" 0}}': 'false',
|
||||
'{{match zero "startsWith" "0"}}': 'false',
|
||||
'{{match "1" "startsWith" one}}': 'false',
|
||||
'{{match null "startsWith" "null"}}': 'false',
|
||||
'{{match truthy_bool "startsWith" "tr"}}': 'false',
|
||||
'{{match safestring_bool_false "startsWith" "fa"}}': 'false',
|
||||
'{{match undefined "startsWith" "undefined"}}': 'false',
|
||||
'{{match unknown "startsWith" "unknown" }}': 'false',
|
||||
'{{match object "startsWith" "object" }}': 'false',
|
||||
'{{match array "startsWith" "array" }}': 'false'
|
||||
}, hash);
|
||||
});
|
||||
|
||||
// SafeStrings represent the original value as an object for example:
|
||||
// SafeString { string: true } vs SafeString { string: 'true' }
|
||||
// allows us to know if the original value was a boolean or a string
|
||||
|
Loading…
Reference in New Issue
Block a user