initial commit
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package simql
|
||||
|
||||
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")
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user