43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package sqimple
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/alecthomas/assert/v2"
|
|
)
|
|
|
|
func TestColumn(t *testing.T) {
|
|
type TestCase struct {
|
|
In string
|
|
IsValid bool
|
|
Column string
|
|
As string
|
|
}
|
|
|
|
testCases := []TestCase{
|
|
// Column only
|
|
{In: "*", IsValid: true, Column: "*"},
|
|
{In: "email", IsValid: true, Column: "email"},
|
|
{In: "customer.*", IsValid: true, Column: "customer.*"},
|
|
{In: "customer.email", IsValid: true, Column: "customer.email"},
|
|
// Column and alias
|
|
{In: "customer.email as email", IsValid: true, Column: "customer.email", As: "email"},
|
|
// Invalid format (spaces)
|
|
{In: "customer.email as email"},
|
|
{In: " customer.email as email"},
|
|
{In: "also as broken "},
|
|
// Invalid format (disallowed characters) - TODO
|
|
}
|
|
|
|
for _, testCase := range testCases {
|
|
t.Run(testCase.In, func(t *testing.T) {
|
|
c := Column(testCase.In)
|
|
column, as, ok := c.Parse()
|
|
|
|
assert.Equal(t, testCase.IsValid, ok, "incorrect test case")
|
|
assert.Equal(t, testCase.Column, column, "parsed column incorrectly")
|
|
assert.Equal(t, testCase.As, as, "parsed as incorrectly")
|
|
})
|
|
}
|
|
}
|