More string functions

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
Anand Krishnamoorthi
2023-02-28 01:19:44 -08:00
committed by Anand Krishnamoorthi
parent 27c5afd8ee
commit 3c3cd312fc
3 changed files with 221 additions and 9 deletions

View File

@@ -9,16 +9,16 @@ cases:
package test
# Arrays
a1 = concat(", ", ["Hello", "world"])
a1 = concat(", ", ["Hello", "world"])
a2 = concat("", ["Hello", "world"]) # empty delimiter
a3 = concat(",", []) # empty array
a4 = concat("", []) # empty array and delimiter
a4 = concat("", []) # empty array and delimiter
# Sets
s1 = concat(", ", {"world", "Hello"})
s2 = concat("", {"world", "Hello"}) # empty delimiter
s3 = concat(",", set()) # empty set
s4 = concat("", set()) # empty set and delimiter
s4 = concat("", set()) # empty set and delimiter
query: data.test
want_result:
@@ -40,7 +40,7 @@ cases:
y = concat(x, [])
query: data.test
want_result: {}
- note: undefined-collection
data: {}
modules:
@@ -50,7 +50,7 @@ cases:
y = concat(",", x)
query: data.test
want_result: {}
- note: invalid-null-delimiter
data: {}
modules: ["package test\nx=concat(null, [])"]
@@ -74,7 +74,7 @@ cases:
modules: ["package test\nx=concat([], [])"]
query: data.test
error: "`concat` expects string argument."
- note: invalid-set-delimiter
data: {}
modules: ["package test\nx=concat(set(), [])"]
@@ -86,4 +86,34 @@ cases:
modules: ["package test\nx=concat({}, [])"]
query: data.test
error: "`concat` expects string argument."
- note: invalid-null-collection
data: {}
modules: ["package test\nx=concat(\"\", null)"]
query: data.test
error: "`concat` expects array/set of strings."
- note: invalid-bool-collection
data: {}
modules: ["package test\nx=concat(\"\", true)"]
query: data.test
error: "`concat` expects array/set of strings."
- note: invalid-number-collection
data: {}
modules: ["package test\nx=concat(\"\", 1)"]
query: data.test
error: "`concat` expects array/set of strings."
- note: invalid-string-collection
data: {}
modules: ["package test\nx=concat(\"\", \"\")"]
query: data.test
error: "`concat` expects array/set of strings."
- note: invalid-object-collection
data: {}
modules: ["package test\nx=concat(\"\", {})"]
query: data.test
error: "`concat` expects array/set of strings."

View File

@@ -0,0 +1,116 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
cases:
- note: all
data: {}
modules:
- |
package test
v1 = endswith("Hello, world", "ld")
v2 = endswith("Hello world", "") # empty substring
v3 = endswith("", "ld") # empty string
v4 = endswith("", "") # empty substring and string
query: data.test
want_result:
v1: true
v2: true
v3: false
v4: true
- note: undefined-string
data: {}
modules:
- |
package test
x { false }
y = endswith(x, "")
query: data.test
want_result: {}
- note: undefined-substring
data: {}
modules:
- |
package test
x { false }
y = endswith(",", x)
query: data.test
want_result: {}
- note: invalid-null-string
data: {}
modules: ["package test\nx=endswith(null, ``)"]
query: data.test
error: "`endswith` expects string argument."
- note: invalid-bool-string
data: {}
modules: ["package test\nx=endswith(true, ``)"]
query: data.test
error: "`endswith` expects string argument."
- note: invalid-number-string
data: {}
modules: ["package test\nx=endswith(1, ``)"]
query: data.test
error: "`endswith` expects string argument."
- note: invalid-array-string
data: {}
modules: ["package test\nx=endswith([], ``)"]
query: data.test
error: "`endswith` expects string argument."
- note: invalid-set-string
data: {}
modules: ["package test\nx=endswith(set(), ``)"]
query: data.test
error: "`endswith` expects string argument."
- note: invalid-object-string
data: {}
modules: ["package test\nx=endswith({}, ``)"]
query: data.test
error: "`endswith` expects string argument."
- note: invalid-null-substring
data: {}
modules: ["package test\nx=endswith(``, null)"]
query: data.test
error: "`endswith` expects string argument."
- note: invalid-bool-substring
data: {}
modules: ["package test\nx=endswith(``, true)"]
query: data.test
error: "`endswith` expects string argument."
- note: invalid-number-substring
data: {}
modules: ["package test\nx=endswith(``, 1)"]
query: data.test
error: "`endswith` expects string argument."
- note: invalid-array-substring
data: {}
modules: ["package test\nx=endswith(``, [])"]
query: data.test
error: "`endswith` expects string argument."
- note: invalid-set-substring
data: {}
modules: ["package test\nx=endswith(``, set())"]
query: data.test
error: "`endswith` expects string argument."
- note: invalid-object-substring
data: {}
modules: ["package test\nx=endswith(``, {})"]
query: data.test
error: "`endswith` expects string argument."