Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add string interpolation * Add string interpolation * Add error messages related to string interpolation Add new tests * Fix bug causing conditional expressions to be not parsed correctly when direcly embedded into interpolated expression (thanks to lofcz for pointing conditional expression scenario) Add some new tests --------- Co-authored-by: Pawel Oziomek <paweloziomek@o2.pl>
- Loading branch information
1 parent
1328529
commit f823a82
Showing
26 changed files
with
752 additions
and
43 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
1 change: 1 addition & 0 deletions
1
src/Scriban.Tests/TestFiles/020-interpolation/020-interpolation-error1.out.txt
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 @@ | ||
text(5,1) : error : Opened interpolated expression not closed on the same line. |
5 changes: 5 additions & 0 deletions
5
src/Scriban.Tests/TestFiles/020-interpolation/020-interpolation-error1.txt
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,5 @@ | ||
$"Interp: {2 + 4 # Interpolation not finished | ||
=== | ||
{{ | ||
$"Interp: {2 + 4 | ||
}End" }} |
3 changes: 3 additions & 0 deletions
3
src/Scriban.Tests/TestFiles/020-interpolation/020-interpolation-error2.out.txt
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,3 @@ | ||
text(4,18) : error : Error while parsing binary expression: Expecting a string continuation to the right of `}` instead of `}` in: <expression> operator <expression> | ||
text(4,18) : error : Invalid token found `}`. Expecting <EOL>/end of line. | ||
text(4,18) : error : Unexpected end of file while parsing a string not terminated by a " |
4 changes: 4 additions & 0 deletions
4
src/Scriban.Tests/TestFiles/020-interpolation/020-interpolation-error2.txt
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,4 @@ | ||
$"Interp: {2 + 4 # Interpolation not finished | ||
=== | ||
{{ | ||
$"Interp: {2 + 4}} |
33 changes: 33 additions & 0 deletions
33
src/Scriban.Tests/TestFiles/020-interpolation/020-interpolation.out.txt
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,33 @@ | ||
Scriban 5.8 can interpolate strings now | ||
Nested interpolation: 23new string | ||
UPPERCASE: 14 | ||
UPPERCASE: 14 | ||
Little more complex example: 2 Scriban 5 | ||
Interpolation at the beginning: 4 is 4 | ||
Pure string | ||
Another pure string | ||
2 8 string | ||
3 18 string | ||
4 60 string | ||
99 bottles | ||
{ is Curly Brace | ||
{ is Curly Brace | ||
{16} | ||
{49} | ||
{6 * 6} | ||
Interp 1: Interp 2: Interp 3 | ||
Interp 1: Interp 2: Interp 3 | ||
Interp 1: Concat 2: Interp 3 | ||
Interp 1: Interp 2: Interp 3 | ||
Concat 1: Interp 2: Interp 3 | ||
1. Interpolation 2. Concatenation | ||
1. Concatenation 2. Interpolation | ||
1. Concatenation 2. Interpolation 3. Concatenation | ||
Interpolation of the strings | ||
Another interpolation of the strings | ||
Yet another interpolation of the strings | ||
Really complex interpolated expression: 33. | ||
Scriban yes 5 can interpolate strings now | ||
yes 5 | ||
no | ||
Unary: -2 |
33 changes: 33 additions & 0 deletions
33
src/Scriban.Tests/TestFiles/020-interpolation/020-interpolation.txt
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,33 @@ | ||
{{ $"Scriban {4 + 1}.8 can interpolate strings now" }} | ||
{{ $"Nested interpolation: {23 + "new string"}" }} | ||
{{ $"Uppercase: {4 + 10}" | string.upcase }} | ||
{{ string.upcase $"Uppercase: {4 + 10}" }} | ||
{{ $'Little more complex example: {2 + " " + string.capitalize $"scriban {5}"}' }} | ||
Interpolation at the beginning: {{ $"{math.times 2 2} is 4" }} | ||
{{ $"Pure string" }} | ||
{{ $'Another pure string' }} | ||
{{ $"{2} {2 * 4} {"string"}" }} | ||
{{ $'{3} {3 * 6} {"string"}' }} | ||
{{ $"{4} {8 * 7.5} {'string'}" }} | ||
{{ $"{11 * 9} bottles"}} | ||
{{ $"\{ is Curly Brace"}} | ||
{{ $'\{ is Curly Brace'}} | ||
{{ $"\{{4 * 4}}" }} | ||
{{ $'\{{7 * 7}}' }} | ||
{{ $"\{6 * 6}" }} | ||
{{ $'Interp 1: {$"Interp {2}: {$'Interp {3}'}"}' }} | ||
{{ $"{$'Interp 1: {$"Interp {2}: {$'Interp {3}'}"}'}" }} | ||
{{ $"{$'Interp 1: {$"Concat " + 2 + $": {$'Interp {3}'}"}'}" }} | ||
{{ $"{$'{$"Interp {1}:"} Interp {2}:'} Interp {3}" }} | ||
{{ $"{$'{$"Concat " + 1 + ":"} Interp {2}:'} Interp {3}" }} | ||
{{ $"{2 / 2}. Interpolation " + "2. Concatenation" }} | ||
{{ "1. Concatenation " + $"{4 / 2}. Interpolation" }} | ||
{{ "1. Concatenation " + $"{4 / 2}. Interpolation " + "3. Concatenation" }} | ||
{{ $"Interpolation" + $" of the " + $"strings" }} | ||
{{ $"Another interpolation" + " of the " + $"strings" }} | ||
{{ "Yet another interpolation" + $" of the " + "strings" }} | ||
{{ $"Really complex interpolated expression: {2 * (4 + 3 + math.round 9.4) + (5 / (2 + 3))}" + "." }} | ||
{{ $"Scriban {( true ? $"yes {4 + 1}" : "no " + 4 )} can interpolate strings now" }} | ||
{{ true ? $"yes {4 + 1}" : "no" }} | ||
{{ false ? $"yes {4 + 1}" : $"no" }} | ||
{{ $"Unary: {-2}" }} |
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.