mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v.transformer: fix string always escaped by transformer (#12603)
This commit is contained in:
parent
6d6a23a1c9
commit
fe37da31a8
@ -1,3 +1,39 @@
|
||||
const ca = r'x\n'
|
||||
|
||||
const cb = 'x\n'
|
||||
|
||||
const cc = ca + cb
|
||||
|
||||
const cd = cc + cc
|
||||
|
||||
const ce = cd + cd
|
||||
|
||||
fn test_raw_string_backslash() {
|
||||
assert r'\' == r'\'
|
||||
}
|
||||
|
||||
fn test_raw_string_not_escaped_by_transformer() {
|
||||
assert r'a\nb' + r'a\nb' == r'a\nba\nb'
|
||||
assert 'a\nb' + r'a\nb' == 'a\nba\\nb'
|
||||
}
|
||||
|
||||
// this test will cause test failure (see #12604)
|
||||
// fn test_many_pluses() {
|
||||
// a := r'x\n'
|
||||
// assert a == ca
|
||||
// b := 'x\n'
|
||||
// assert b == cb
|
||||
// c := a + b
|
||||
// assert c == cc // this fails
|
||||
// d := c + c
|
||||
// assert d == cd
|
||||
// e := d + d
|
||||
// assert e == ce
|
||||
// println(e)
|
||||
// result := r'x\nx
|
||||
// x\nx
|
||||
// x\nx
|
||||
// x\nx
|
||||
// '
|
||||
// assert e == result
|
||||
// }
|
||||
|
@ -2,6 +2,7 @@ module transformer
|
||||
|
||||
import v.pref
|
||||
import v.ast
|
||||
import v.util
|
||||
|
||||
pub struct Transformer {
|
||||
pref &pref.Preferences
|
||||
@ -379,10 +380,10 @@ pub fn (t Transformer) infix_expr(original ast.InfixExpr) ast.Expr {
|
||||
}
|
||||
}
|
||||
.plus {
|
||||
return ast.StringLiteral{
|
||||
val: left_node.val + right_node.val
|
||||
pos: pos
|
||||
}
|
||||
return if t.pref.backend == .c { ast.Expr(ast.StringLiteral{
|
||||
val: util.smart_quote(left_node.val, left_node.is_raw) + util.smart_quote(right_node.val, right_node.is_raw)
|
||||
pos: pos
|
||||
}) } else { ast.Expr(node) }
|
||||
}
|
||||
else {
|
||||
return node
|
||||
|
Loading…
Reference in New Issue
Block a user