Skip to content

Commit

Permalink
ok, i think this precedences stuff is finally under control
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates committed Dec 22, 2017
1 parent 43a6d15 commit 6258824
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
8 changes: 8 additions & 0 deletions if_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ func Test_Render_If_Or(t *testing.T) {
r.Equal("hi", s)
}

func Test_Render_If_Or_False_False(t *testing.T) {
r := require.New(t)
input := `<%= if (1 == 2 || 2 == 1) { return "hi" } else { return "bye" } %>`
s, err := Render(input, NewContext())
r.NoError(err)
r.Equal("bye", s)
}

func Test_Render_If_Nil(t *testing.T) {
r := require.New(t)
input := `<%= if (names && len(names) >= 1) { %>hi<%} %>`
Expand Down
4 changes: 4 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ func Test_OperatorPrecedence(t *testing.T) {
"foo ~= bar",
"(foo ~= bar)",
},
{
"1 != 2 || 2 != 1",
"((1 != 2) || (2 != 1))",
},
}

for _, tt := range tests {
Expand Down
5 changes: 3 additions & 2 deletions parser/precedences.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "github.com/gobuffalo/plush/token"
const (
_ int = iota
LOWEST //
ANDOR // || or &&
EQUALS // ==
LESSGREATER // > or <
SUM // +
Expand All @@ -18,8 +19,8 @@ var precedences = map[token.Type]int{
token.EQ: EQUALS,
token.NOT_EQ: EQUALS,
token.MATCHES: EQUALS,
token.AND: EQUALS,
token.OR: EQUALS,
token.AND: ANDOR,
token.OR: ANDOR,
token.LT: LESSGREATER,
token.LTEQ: LESSGREATER,
token.GT: LESSGREATER,
Expand Down

0 comments on commit 6258824

Please sign in to comment.