sq/libsq/ast/inspector_test.go

28 lines
651 B
Go
Raw Normal View History

2016-10-17 07:14:01 +03:00
package ast
import (
"testing"
"github.com/stretchr/testify/require"
2016-10-17 07:14:01 +03:00
)
func TestInspector_findTableSegments(t *testing.T) {
const q1 = `@mydb1 | .user | .uid, .username`
ast, err := buildInitialAST(t, q1)
2016-10-17 07:14:01 +03:00
require.Nil(t, err)
err = NewWalker(ast).AddVisitor(typeSelectorNode, narrowTblSel).Walk()
2016-10-17 07:14:01 +03:00
require.Nil(t, err)
insp := NewInspector(ast)
2016-10-17 07:14:01 +03:00
segs := ast.Segments()
require.Equal(t, 3, len(segs))
selSegs := insp.FindTableSegments()
require.Equal(t, 1, len(selSegs), "should be 1 table segment: the tbl sel segment")
finalSelSeg, err := insp.FindFinalTableSegment()
2016-10-17 07:14:01 +03:00
require.Nil(t, err)
require.Equal(t, selSegs[0], finalSelSeg)
}