#49: pretty printer wraps variables by curly braced in double-quoted strings
This commit is contained in:
parent
d2655bd75b
commit
6d554c0468
@ -553,8 +553,15 @@ func (p *Printer) printScalarEncapsedStringPart(n node.Node) {
|
|||||||
func (p *Printer) printScalarEncapsed(n node.Node) {
|
func (p *Printer) printScalarEncapsed(n node.Node) {
|
||||||
io.WriteString(p.w, "\"")
|
io.WriteString(p.w, "\"")
|
||||||
|
|
||||||
for _, nn := range n.(*scalar.Encapsed).Parts {
|
for _, part := range n.(*scalar.Encapsed).Parts {
|
||||||
p.Print(nn)
|
switch part.(type) {
|
||||||
|
case *scalar.EncapsedStringPart:
|
||||||
|
p.Print(part)
|
||||||
|
default:
|
||||||
|
io.WriteString(p.w, "{")
|
||||||
|
p.Print(part)
|
||||||
|
io.WriteString(p.w, "}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
io.WriteString(p.w, "\"")
|
io.WriteString(p.w, "\"")
|
||||||
@ -567,8 +574,15 @@ func (p *Printer) printScalarHeredoc(n node.Node) {
|
|||||||
io.WriteString(p.w, nn.Label)
|
io.WriteString(p.w, nn.Label)
|
||||||
io.WriteString(p.w, "\n")
|
io.WriteString(p.w, "\n")
|
||||||
|
|
||||||
for _, nn := range nn.Parts {
|
for _, part := range nn.Parts {
|
||||||
p.Print(nn)
|
switch part.(type) {
|
||||||
|
case *scalar.EncapsedStringPart:
|
||||||
|
p.Print(part)
|
||||||
|
default:
|
||||||
|
io.WriteString(p.w, "{")
|
||||||
|
p.Print(part)
|
||||||
|
io.WriteString(p.w, "}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
io.WriteString(p.w, strings.Trim(nn.Label, "\"'"))
|
io.WriteString(p.w, strings.Trim(nn.Label, "\"'"))
|
||||||
@ -1232,7 +1246,14 @@ func (p *Printer) printExprShellExec(n node.Node) {
|
|||||||
|
|
||||||
io.WriteString(p.w, "`")
|
io.WriteString(p.w, "`")
|
||||||
for _, part := range nn.Parts {
|
for _, part := range nn.Parts {
|
||||||
|
switch part.(type) {
|
||||||
|
case *scalar.EncapsedStringPart:
|
||||||
p.Print(part)
|
p.Print(part)
|
||||||
|
default:
|
||||||
|
io.WriteString(p.w, "{")
|
||||||
|
p.Print(part)
|
||||||
|
io.WriteString(p.w, "}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
io.WriteString(p.w, "`")
|
io.WriteString(p.w, "`")
|
||||||
}
|
}
|
||||||
|
@ -346,7 +346,7 @@ func TestPrintScalarEncapsed(t *testing.T) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
if o.String() != `"hello $var world"` {
|
if o.String() != `"hello {$var} world"` {
|
||||||
t.Errorf("TestPrintScalarEncapsed is failed\n")
|
t.Errorf("TestPrintScalarEncapsed is failed\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -365,7 +365,7 @@ func TestPrintScalarHeredoc(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
expected := `<<<LBL
|
expected := `<<<LBL
|
||||||
hello $var world
|
hello {$var} world
|
||||||
LBL`
|
LBL`
|
||||||
actual := o.String()
|
actual := o.String()
|
||||||
|
|
||||||
@ -1844,7 +1844,7 @@ func TestPrintShellExec(t *testing.T) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
expected := "`hello $world!`"
|
expected := "`hello {$world}!`"
|
||||||
actual := o.String()
|
actual := o.String()
|
||||||
|
|
||||||
if expected != actual {
|
if expected != actual {
|
||||||
|
Loading…
Reference in New Issue
Block a user