Skip to content

Commit

Permalink
fixed issue with and or precedence
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates committed Dec 22, 2017
1 parent 9fd9491 commit 43a6d15
Show file tree
Hide file tree
Showing 2 changed files with 10 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 @@ -38,6 +38,14 @@ func Test_Render_If_And(t *testing.T) {
r.Equal("", s)
}

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

func Test_Render_If_Or(t *testing.T) {
r := require.New(t)
input := `<%= if (false || true) { %>hi<%} %>`
Expand Down
4 changes: 2 additions & 2 deletions parser/precedences.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ var precedences = map[token.Type]int{
token.EQ: EQUALS,
token.NOT_EQ: EQUALS,
token.MATCHES: EQUALS,
token.AND: EQUALS,
token.OR: EQUALS,
token.LT: LESSGREATER,
token.LTEQ: LESSGREATER,
token.GT: LESSGREATER,
Expand All @@ -26,8 +28,6 @@ var precedences = map[token.Type]int{
token.MINUS: SUM,
token.SLASH: PRODUCT,
token.ASTERISK: PRODUCT,
token.AND: PRODUCT,
token.OR: PRODUCT,
token.LPAREN: CALL,
token.LBRACKET: INDEX,
}

0 comments on commit 43a6d15

Please sign in to comment.