Files
sqimple/where_test.go
2026-07-07 20:30:02 +01:00

39 lines
1.1 KiB
Go

package sqimple
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")
})
}
}