-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Gabor Boros <gabor.brs@gmail.com>
- Loading branch information
1 parent
c131f90
commit 5abe8e0
Showing
7 changed files
with
126 additions
and
2 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
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,51 @@ | ||
desc: Tests string formatting function | ||
tests: | ||
# Formatting at the middle of the text | ||
- cd: r.format("With great {noun} comes great responsibility.", {"noun": "power"}) | ||
rb: r.format("With great {noun} comes great responsibility.", {"noun" => "power"}) | ||
ot: "With great power comes great responsibility." | ||
# Formatting at the beginning and end of the text | ||
- cd: r.format("{with} great power comes great {what}", {"with": "With", "what": "responsibility"}) | ||
rb: r.format("{with} great power comes great {what}", {"with" => "With", "what" => "responsibility"}) | ||
ot: "With great power comes great responsibility." | ||
# Formatting with empty placeholder | ||
- cd: r.format("With great {} comes great responsibility.", {"": "power"}) | ||
rb: r.format("With great {} comes great responsibility.", {"" => "power"}) | ||
ot: "With great power comes great responsibility." | ||
# Parameter not found in text | ||
- cd: r.format("With great power comes great responsibility.", {"text": "test" }) | ||
rb: r.format("With great power comes great responsibility.", {"text" => "test" }) | ||
ot: "With great power comes great responsibility." | ||
# Using integers for formatting | ||
- cd: r.format("{bottles} bottles of beer on the wall.", {"bottles": 100}) | ||
rb: r.format("{bottles} bottles of beer on the wall.", {"bottles" => 100}) | ||
ot: "100 bottles of beer on the wall." | ||
# Using doubles for formatting | ||
- cd: r.format("{bottles} bottles of beer on the wall.", {"bottles": 99.12345}) | ||
rb: r.format("{bottles} bottles of beer on the wall.", {"bottles" => 99.12345}) | ||
ot: "99.12345 bottles of beer on the wall." | ||
# Using mixed values for formatting | ||
- cd: r.format("x is not in {list}", {"list": ["one", 2, 3.45678, {"nine": 9}]}) | ||
rb: r.format("x is not in {list}", {"list" => ["one", 2, 3.45678, {"nine" => 9}]}) | ||
ot: "x is not in ["one",2,3.45678,{"nine":9}]" | ||
# Placeholder not found in replacement parameters | ||
- cd: r.format("foo {bar} baz", {}) | ||
rb: r.format("foo {bar} baz", {}) | ||
ot: err('ReqlNonExistenceError', 'No attribute `bar` in object')) | ||
# Placeholder indicator curly braces is not closed | ||
- cd: r.format("foo {bar baz", {"bar": "bar" }) | ||
rb: r.format("foo {bar baz", {"bar" => "bar" }) | ||
ot: err('ReqlQueryLogicError', 'Parameter tag must be closed') | ||
# Placeholder indicator curly braces is not opened | ||
- cd: r.format("foo bar} baz", {"bar": "bar" }) | ||
rb: r.format("foo bar} baz", {"bar" => "bar" }) | ||
ot: err('ReqlQueryLogicError', 'No parameter tags to close') | ||
- cd: r.format("foo {{nested}} baz", {"nested": "bar" }) | ||
rb: r.format("foo {{nested}} baz", {"nested" => "bar" }) | ||
ot: err('ReqlQueryLogicError', 'Nested template parameters are not allowed') | ||
- cd: r.format("{foo} {bar} {baz}", ["foo", "bar", "baz"]) | ||
ot: err('ReqlQueryLogicError', 'Expected type OBJECT but found ARRAY') | ||
- cd: r.format("{foo} bar baz", "foo") | ||
ot: err('ReqlQueryLogicError', 'Expected type OBJECT but found STRING') | ||
- cd: r.format("{foo} bar baz", 1) | ||
ot: err('ReqlQueryLogicError', 'Expected type OBJECT but found NUMBER') |