-
-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support string concatenation. (#6576)
* Add string concatenation. * Add string concat function. * Add string concat() and tests. * Apply suggestions from code review Co-authored-by: _tud <98935832+UnderscoreTud@users.noreply.github.com> Co-authored-by: Ayham Al Ali <20037329+AyhamAl-Ali@users.noreply.github.com> * Update src/main/java/ch/njol/skript/classes/data/DefaultOperations.java Co-authored-by: _tud <98935832+UnderscoreTud@users.noreply.github.com> * Variables? We don't need assertion output variables where we're going! (Thanks for your PR sovde) --------- Co-authored-by: _tud <98935832+UnderscoreTud@users.noreply.github.com> Co-authored-by: Ayham Al Ali <20037329+AyhamAl-Ali@users.noreply.github.com>
- Loading branch information
1 parent
e4c0a15
commit 5928f8c
Showing
4 changed files
with
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
test "string concatenation": | ||
|
||
# string + string | ||
assert "hello " + "there" is "hello there" with "string + string concat failed" | ||
assert "foo" + "bar" is "foobar" with "string + string concat failed" | ||
assert "foo" + " " + "bar" is "foo bar" with "string + string + string concat failed" | ||
assert "hello" + " " + "there" is "hello there" with "string + string + string concat failed" | ||
|
||
# ? + string | ||
set {_var} to "hello" | ||
set {_var} to {_var} + " there" | ||
assert {_var} is "hello there" with "var + string concat failed" | ||
|
||
# ? + string | ||
set {_var1} to "hello " | ||
set {_var2} to "there" | ||
assert {_var1} + {_var2} is "hello there" with "var + var concat failed" | ||
|
||
# variable-string + string | ||
set {_var} to "hello" | ||
assert "%{_var}% " + "there" is "hello there" with "var-string + string concat failed" | ||
|
||
# string + number = <none> | ||
# parser prevents us adding "foo" + 1 or comparing "foo" + 1 with a string | ||
# we test the edge case where somebody slips past us! | ||
set {_var} to 1 | ||
set {_var} to "foo" + {_var} | ||
assert {_var} doesn't exist with "string + number concat succeeded" |
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,31 @@ | ||
|
||
test "concat() function": | ||
|
||
# string + string | ||
assert concat("hello ", "there") is "hello there" with "string + string concat() failed" | ||
assert concat("foo", "bar") is "foobar" with "string + string concat() failed" | ||
assert concat("foo", " ", "bar") is "foo bar" with "string + string + string concat() failed" | ||
assert concat("hello", " ", "there") is "hello there" with "string + string + string concat() failed" | ||
assert concat("a", "b", "c", "d", "e") is "abcde" with "5 strings concat() failed" | ||
|
||
# ? + string | ||
set {_var} to "hello" | ||
set {_var} to concat({_var}, " there") | ||
assert {_var} is "hello there" with "var + string concat() failed" | ||
|
||
# ? + string | ||
set {_var1} to "hello " | ||
set {_var2} to "there" | ||
assert concat({_var1}, {_var2}) is "hello there" with "var + var concat() failed" | ||
|
||
# variable-string + string | ||
set {_var} to "hello" | ||
assert concat("%{_var}% ", "there") is "hello there" with "var-string + string concat() failed" | ||
|
||
# string + non-string | ||
# unlike the maths expression we CAN concat objects here! | ||
set {_var} to 1 | ||
set {_var} to concat("foo", {_var}) | ||
assert {_var} is "foo1" with "string + number concat() failed" | ||
assert concat("a", 1, "b", 2) is "a1b2" with "strings + numbers concat() failed" | ||
assert concat("my nice new ", stone sword) is "my nice new stone sword" with "string + item concat() failed" |