initial commit
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package simql
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/alecthomas/assert/v2"
|
||||
)
|
||||
|
||||
func TestWhere(t *testing.T) {
|
||||
type TestCase struct {
|
||||
In string
|
||||
IsValid bool
|
||||
Glue string
|
||||
Column string
|
||||
Operator string
|
||||
Value any
|
||||
}
|
||||
|
||||
testCases := []TestCase{
|
||||
{In: "id = ?", IsValid: true, Column: "id", Operator: "="},
|
||||
{In: "id = 1234", IsValid: true, Column: "id", Operator: "=", Value: "1234"},
|
||||
{In: "and id = ?", IsValid: true, Glue: "and", Column: "id", Operator: "="},
|
||||
{In: "or id = ?", IsValid: true, Glue: "or", Column: "id", Operator: "="},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.In, func(t *testing.T) {
|
||||
w := Where(testCase.In)
|
||||
glue, column, operator, value, ok := w.Parse()
|
||||
|
||||
assert.Equal(t, testCase.IsValid, ok, "incorrect test case")
|
||||
assert.Equal(t, testCase.Glue, glue, "parsed glue incorrectly")
|
||||
assert.Equal(t, testCase.Column, column, "parsed column incorrectly")
|
||||
assert.Equal(t, testCase.Operator, operator, "parsed operator incorrectly")
|
||||
assert.Equal(t, testCase.Value, value, "parsed value incorrectly")
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user