Skip to content

Commit

Permalink
added more test cases to check #157 and side effects of #164
Browse files Browse the repository at this point in the history
  • Loading branch information
sio4 committed Oct 1, 2022
1 parent bc8587c commit a16e005
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
15 changes: 15 additions & 0 deletions if_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,18 @@ func Test_Render_If_Variable_Not_Set_But_Or_Condition_Right_Node_Is_True(t *test
r.NoError(err)
r.Equal("hi", s)
}

func Test_Condition_UnsetIsNil(t *testing.T) {
r := require.New(t)
ctx := NewContext()

input := `<%= paths == nil %>`
s, err := Render(input, ctx)
r.NoError(err)
r.Equal("true", s)

input = `<%= nil == paths %>`
s, err = Render(input, ctx)
r.NoError(err)
r.Equal("true", s)
}
41 changes: 41 additions & 0 deletions math_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,47 @@ func Test_Render_String_Math(t *testing.T) {
}
}

func Test_Render_Operator_UndefinedVar(t *testing.T) {
tests := []struct {
operator string
result interface{}
errorExpected bool
}{
{"+", "", true},
{"-", "", true},
{"/", "", true},
{"*", "", true},
{">", "", true},
{">=", "", true},
{"<=", "", true},
{"<", "", true},
{"==", "false", false},
{"!=", "true", false},
}
for _, tc := range tests {
t.Run(tc.operator, func(t *testing.T) {
r := require.New(t)
input := fmt.Sprintf("<%%= undefined %s 3 %%>", tc.operator)
s, err := Render(input, NewContext())
if tc.errorExpected {
r.Error(err, "undefined %s 3 --> '%v'", tc.operator, tc.result)
} else {
r.NoError(err, "undefined %s 3 --> '%v'", tc.operator, tc.result)
}
r.Equal(tc.result, s, "undefined %s 3", tc.operator)

input = fmt.Sprintf("<%%= 3 %s unknown %%>", tc.operator)
s, err = Render(input, NewContext())
if tc.errorExpected {
r.Error(err, "3 %s undefined --> '%v'", tc.operator, tc.result)
} else {
r.NoError(err, "3 %s undefined --> '%v'", tc.operator, tc.result)
}
r.Equal(tc.result, s, "undefined %s 3", tc.operator)
})
}
}

func Test_Render_String_Concat_Multiple(t *testing.T) {
r := require.New(t)

Expand Down

0 comments on commit a16e005

Please sign in to comment.