feat: eval literal

This commit is contained in:
debugtalk
2021-10-03 19:46:09 +08:00
parent 5ac8647591
commit b7dbb6b5e7
4 changed files with 54 additions and 2 deletions

View File

@@ -315,3 +315,28 @@ func TestCallFunction(t *testing.T) {
t.Fail()
}
}
func TestLiteralEval(t *testing.T) {
testData := []struct {
expr string
expect interface{}
}{
{"123", 123},
{"1.23", 1.23},
{"-123", -123},
{"-1.23", -1.23},
{"abc", "abc"},
{"$var", "$var"},
{"", ""},
}
for _, data := range testData {
value, err := literalEval(data.expr)
if !assert.Nil(t, err) {
t.Fail()
}
if !assert.Equal(t, data.expect, value) {
t.Fail()
}
}
}