|
1 |
| -using BlockScalars: @blk_str, block |
| 1 | +using BlockScalars: BlockScalars, @blk_str, block, interpolate |
2 | 2 | using Test
|
3 | 3 | using YAML: YAML
|
4 | 4 |
|
@@ -114,14 +114,32 @@ end
|
114 | 114 | end
|
115 | 115 | end
|
116 | 116 |
|
| 117 | + @testset "interpolate" begin |
| 118 | + @test interpolate("x") == "x" |
| 119 | + @test interpolate("\$x") == Expr(:string, :x) |
| 120 | + @test interpolate("\$(x)") == Expr(:string, :x) |
| 121 | + @test interpolate("\$(\"x\")") == Expr(:string, "x") |
| 122 | + |
| 123 | + @test interpolate("<\$x>") == Expr(:string, "<", :x, ">") |
| 124 | + @test interpolate("<\$(x)>") == Expr(:string, "<", :x, ">") |
| 125 | + |
| 126 | + # The quoting in these examples can result in exceptions being raised during parsing |
| 127 | + # if handled incorrectly. |
| 128 | + @test interpolate("\"\\n\"") == "\"\\n\"" |
| 129 | + @test interpolate("\$(join([\"a\", \"b\"], \", \"))") == Expr(:string, :(join(["a", "b"], ", "))) |
| 130 | + end |
117 | 131 |
|
118 | 132 | @testset "@blk_str" begin
|
119 |
| - @testset "invalid indicators" begin |
120 |
| - @test_throws LoadError macroexpand(@__MODULE__, :(@blk_str "" "fs_")) # Too many indicators |
121 |
| - @test_throws LoadError macroexpand(@__MODULE__, :(@blk_str "" "sf")) # Order matters |
122 |
| - @test_throws LoadError macroexpand(@__MODULE__, :(@blk_str "" "_s")) # Invalid style |
123 |
| - @test_throws LoadError macroexpand(@__MODULE__, :(@blk_str "" "f_")) # Invalid chomp |
124 |
| - @test_throws LoadError macroexpand(@__MODULE__, :(@blk_str "" "_")) # Invalid style/chomp |
| 133 | + @testset "quoting" begin |
| 134 | + # Use of double-quotes could cause failure if not handled properly: |
| 135 | + # `syntax: incomplete: invalid string syntax` |
| 136 | + @test blk"\"\n\"" == "\" \"" |
| 137 | + end |
| 138 | + |
| 139 | + @testset "string-interpolation" begin |
| 140 | + # If processing would accidentally take place in the interpolated code then |
| 141 | + # we could see "a b " as the result. |
| 142 | + @test blk"""$(join(("a", "b") .* "\n", ""))"""fc == "a b\n" |
125 | 143 | end
|
126 | 144 | end
|
127 | 145 | end
|
0 commit comments