sq/libsq/ast/inspector_test.go
Neil O'Toole 7396aadb9e
#12: multiple joins (#280)
* The query language now supports multiple joins.
2023-07-03 09:34:19 -06:00

28 lines
651 B
Go

package ast
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestInspector_findTableSegments(t *testing.T) {
const q1 = `@mydb1 | .user | .uid, .username`
ast, err := buildInitialAST(t, q1)
require.Nil(t, err)
err = NewWalker(ast).AddVisitor(typeSelectorNode, narrowTblSel).Walk()
require.Nil(t, err)
insp := NewInspector(ast)
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()
require.Nil(t, err)
require.Equal(t, selSegs[0], finalSelSeg)
}