-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
array.reverse(array)
and strings.reverse(string)
built-in fun…
…ctions. (#4161) The function `array.reverse` takes an array as an argument, and returns an array with a reversed order of elements. The function `strings.reverse` takes a string as an argument, and returns a string with a reversed order of unicode code points. WASM support is included for both built-ins. Fixes #3736 Signed-off-by: Kristian Svalland <kristian.svalland@gmail.com>
- Loading branch information
1 parent
328ffcd
commit 6f81c4a
Showing
13 changed files
with
280 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
cases: | ||
- note: 'array/reverse_123' | ||
query: data.test.p = x | ||
data: | ||
foo: | ||
- 1 | ||
- 2 | ||
- 3 | ||
modules: | ||
- | | ||
package test | ||
p := array.reverse(data.foo) | ||
want_result: | ||
- x: | ||
- 3 | ||
- 2 | ||
- 1 | ||
- note: 'array/reverse_empty' | ||
query: data.test.p = x | ||
data: | ||
foo: [] | ||
modules: | ||
- | | ||
package test | ||
p := array.reverse(data.foo) | ||
want_result: | ||
- x: [] | ||
- note: 'array/reverse_object_error' | ||
query: data.test.p = x | ||
data: | ||
foo: | ||
bar: baz | ||
baz: bar | ||
modules: | ||
- | | ||
package test | ||
p := array.reverse(data.foo) | ||
want_error: "array.reverse: operand 1 must be array but got object" | ||
want_error_code: eval_type_error | ||
strict_error: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
cases: | ||
- note: 'strings/reverse_bar' | ||
query: data.test.p = x | ||
data: | ||
foo: "bar" | ||
modules: | ||
- | | ||
package test | ||
p := strings.reverse(data.foo) | ||
want_result: | ||
- x: "rab" | ||
- note: 'strings/reverse_unicode_multi_char_emojii' | ||
query: data.test.p = x | ||
data: | ||
# The "Keycap Digit Two" consists of three codepoints: [2 U+32, U+FE0F, U+20E3] | ||
# Other examples of such emojies are smileys with defined skin-color | ||
# In the current implementation, we reverse strings at the level of codepoints, not Glyphs | ||
foo: "2️⃣" | ||
modules: | ||
- | | ||
package test | ||
p := strings.reverse(data.foo) | ||
want_result: | ||
- x: "⃣️2" | ||
- note: 'strings/reverse_unicode' | ||
query: data.test.p = x | ||
data: | ||
foo: "1😀𝛾" | ||
modules: | ||
- | | ||
package test | ||
p := strings.reverse(data.foo) | ||
want_result: | ||
- x: "𝛾😀1" | ||
- note: 'strings/reverse_empty' | ||
query: data.test.p = x | ||
data: | ||
foo: "" | ||
modules: | ||
- | | ||
package test | ||
p := strings.reverse(data.foo) | ||
want_result: | ||
- x: "" | ||
- note: 'strings/reverse_number_error' | ||
query: data.test.p = x | ||
data: | ||
foo: 123 | ||
modules: | ||
- | | ||
package test | ||
p := strings.reverse(data.foo) | ||
want_error: "reverse: operand 1 must be string but got number" | ||
want_error_code: eval_type_error | ||
strict_error: true | ||
- note: 'strings/reverse_object_error' | ||
query: data.test.p = x | ||
data: | ||
foo: | ||
bar: baz | ||
modules: | ||
- | | ||
package test | ||
p := strings.reverse(data.foo) | ||
want_error: "reverse: operand 1 must be string but got object" | ||
want_error_code: eval_type_error | ||
strict_error: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.