sq/libsq/ast/selector_test.go
Neil O'Toole db55986980
#307: Ingest cache (#354)
- Support for ingest cache, download cache, and progress bars.
2024-01-14 18:45:34 -07:00

54 lines
1002 B
Go

package ast
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/neilotoole/sq/libsq/core/lg/lgt"
"github.com/neilotoole/sq/testh/tu"
)
func TestColumnAlias(t *testing.T) {
t.Parallel()
testCases := []struct {
in string
wantErr bool
wantColName string
wantAlias string
}{
{
in: `@sakila | .actor | .first_name:given_name`,
wantColName: "first_name",
wantAlias: "given_name",
},
}
for _, tc := range testCases {
tc := tc
t.Run(tu.Name(tc.in), func(t *testing.T) {
t.Parallel()
log := lgt.New(t)
ast, err := Parse(log, tc.in)
if tc.wantErr {
require.Error(t, err)
return
}
require.NoError(t, err)
insp := NewInspector(ast)
nodes := insp.FindNodes(typeColSelectorNode)
require.Equal(t, 1, len(nodes))
colSel, ok := nodes[0].(*ColSelectorNode)
require.True(t, ok)
require.Equal(t, tc.wantColName, colSel.ColName())
require.Equal(t, tc.wantAlias, colSel.Alias())
})
}
}