Added expression tests for source tracking
All checks were successful
/ test (push) Successful in 20s
All checks were successful
/ test (push) Successful in 20s
This commit is contained in:
parent
3995545f89
commit
27b49e22d7
1 changed files with 27 additions and 10 deletions
|
@ -31,16 +31,6 @@ func TestEachLeaf(t *testing.T) {
|
||||||
assert.Equal(t, err.Error(), "error")
|
assert.Equal(t, err.Error(), "error")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRemoveChild(t *testing.T) {
|
|
||||||
src := []byte("(1+2-3*4)+(5*6-7+8)")
|
|
||||||
tokens := token.Tokenize(src)
|
|
||||||
expr := expression.Parse(tokens)
|
|
||||||
left := expr.Children[0]
|
|
||||||
right := expr.Children[1]
|
|
||||||
expr.RemoveChild(left)
|
|
||||||
assert.Equal(t, expr.Children[0], right)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestNilExpression(t *testing.T) {
|
func TestNilExpression(t *testing.T) {
|
||||||
src := []byte("")
|
src := []byte("")
|
||||||
tokens := token.Tokenize(src)
|
tokens := token.Tokenize(src)
|
||||||
|
@ -53,4 +43,31 @@ func TestNilGroup(t *testing.T) {
|
||||||
tokens := token.Tokenize(src)
|
tokens := token.Tokenize(src)
|
||||||
expr := expression.Parse(tokens)
|
expr := expression.Parse(tokens)
|
||||||
assert.Nil(t, expr)
|
assert.Nil(t, expr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRemoveChild(t *testing.T) {
|
||||||
|
src := []byte("(1+2-3*4)+(5*6-7+8)")
|
||||||
|
tokens := token.Tokenize(src)
|
||||||
|
expr := expression.Parse(tokens)
|
||||||
|
left := expr.Children[0]
|
||||||
|
right := expr.Children[1]
|
||||||
|
expr.RemoveChild(left)
|
||||||
|
assert.Equal(t, expr.Children[0], right)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSource(t *testing.T) {
|
||||||
|
src := []byte("(1+2-3*4)+(5*6-7+8)")
|
||||||
|
tokens := token.Tokenize(src)
|
||||||
|
expr := expression.Parse(tokens)
|
||||||
|
assert.DeepEqual(t, expr.Source, tokens)
|
||||||
|
assert.DeepEqual(t, expr.Children[0].Source, tokens[1:8])
|
||||||
|
assert.DeepEqual(t, expr.Children[1].Source, tokens[11:18])
|
||||||
|
sources := []string{}
|
||||||
|
|
||||||
|
expr.EachLeaf(func(leaf *expression.Expression) error {
|
||||||
|
sources = append(sources, leaf.Source.String(src))
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
assert.DeepEqual(t, sources, []string{"1", "2", "3", "4", "5", "6", "7", "8"})
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue