Skip to content

Commit

Permalink
Fix func call line breaks in String() (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislas-m authored Jul 15, 2019
1 parent b49948b commit 6aa8987
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
3 changes: 0 additions & 3 deletions ast/call_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ func (ce *CallExpression) String() string {
out.WriteString(ce.ElseBlock.String())
out.WriteString(" }")
}
if ce.Block != nil || ce.ElseBlock != nil {
out.WriteString("\n")
}

return out.String()
}
21 changes: 17 additions & 4 deletions ast/program.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package ast

import "bytes"
import (
"bytes"
"strings"
)

type Program struct {
Statements []Statement
Expand All @@ -9,12 +12,12 @@ type Program struct {
func (p *Program) TokenLiteral() string {
if len(p.Statements) > 0 {
return p.Statements[0].TokenLiteral()
} else {
return ""
}
return ""
}

func (p *Program) String() string {
// InnerText gets the raw string representation of the program's contents.
func (p *Program) InnerText() string {
var out bytes.Buffer

for _, s := range p.Statements {
Expand All @@ -23,3 +26,13 @@ func (p *Program) String() string {

return out.String()
}

func (p *Program) String() string {
var out bytes.Buffer

for _, s := range p.Statements {
out.WriteString(s.String() + "\n")
}

return strings.TrimRight(out.String(), "\n")
}
5 changes: 3 additions & 2 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func Test_OperatorPrecedence(t *testing.T) {
program, err := Parse("<%" + tt.input + "%>")
r.NoError(err)

r.Equal(tt.expected, program.String())
r.Equal(tt.expected, program.InnerText())
}
}

Expand Down Expand Up @@ -1002,7 +1002,8 @@ create_table("users_2", {"timestamps": false}) {
t.Column("price", "numeric", {"null": true, "default": "1.00"})
t.Column("email", "string", {"default": "[email protected]", "size": 50})
}
`
drop_column("table_name", "column1_name")
drop_column("table_name", "column2_name")`
p, err := Parse("<%" + input + "%>")
r.NoError(err)
r.Equal(input, p.String())
Expand Down

0 comments on commit 6aa8987

Please sign in to comment.