This repository has no description
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120package norm
import ( "testing")
func TestIdentExpr(t *testing.T) { ident := IdentExpr("username")
if ident.String() != "username" { t.Errorf("Expected 'username', got '%s'", ident.String()) }
if ident.Binds() != nil { t.Errorf("Expected nil binds, got %v", ident.Binds()) }
expr := ident.AsExpr() if expr.kind != exprKindIdent { t.Errorf("Expected exprKindIdent, got %d", expr.kind) }
if expr.String() != "username" { t.Errorf("Expected 'username', got '%s'", expr.String()) }}
func TestValueExpr(t *testing.T) { value := ValueExpr{inner: "test"}
if value.String() != "?" { t.Errorf("Expected '?', got '%s'", value.String()) }
if value.Binds()[0] != "test" { t.Errorf("Expected %q, got %v", []any{"test"}, value.Binds()) }
expr := value.AsExpr() if expr.kind != exprKindValue { t.Errorf("Expected exprKindValue, got %d", expr.kind) }}
func TestBinaryExpressions(t *testing.T) { tests := []struct { name string expr Expr expected string }{ {"Eq", Eq("age", 25), "(age) = (?)"}, {"Neq", Neq("status", "active"), "(status) <> (?)"}, {"Gt", Gt("score", 100), "(score) > (?)"}, {"Gte", Gte("rating", 4.5), "(rating) >= (?)"}, {"Lt", Lt("count", 10), "(count) < (?)"}, {"Lte", Lte("price", 99.99), "(price) <= (?)"}, }
for _, test := range tests { t.Run(test.name, func(t *testing.T) { if test.expr.String() != test.expected { t.Errorf("Expected '%s', got '%s'", test.expected, test.expr.String()) }
if test.expr.kind != exprKindBinary { t.Errorf("Expected exprKindBinary, got %d", test.expr.kind) } }) }}
func TestLogicalOperators(t *testing.T) { left := Eq("age", 25) right := Eq("status", "active")
andExpr := left.And(right) expectedAnd := "((age) = (?)) AND ((status) = (?))" if andExpr.String() != expectedAnd { t.Errorf("Expected '%s', got '%s'", expectedAnd, andExpr.String()) }
orExpr := left.Or(right) expectedOr := "((age) = (?)) OR ((status) = (?))" if orExpr.String() != expectedOr { t.Errorf("Expected '%s', got '%s'", expectedOr, orExpr.String()) }}
func TestComplexExpressions(t *testing.T) { age := Eq("age", 25) status := Eq("status", "active") score := Gt("score", 100)
complex := age. And(status). Or(score) expected := "(((age) = (?)) AND ((status) = (?))) OR ((score) > (?))"
if complex.String() != expected { t.Errorf("Expected '%s', got '%s'", expected, complex.String()) }}
// this just needs to compilefunc TestImplsInterfaces(t *testing.T) { sel := Select() _ = isCompiler(sel) & isBuilder(sel) & isExecer(sel) & isQuerier(sel)
del := Delete() _ = isCompiler(del) & isBuilder(del) & isExecer(del)
ins := Insert() _ = isCompiler(ins) & isBuilder(ins) & isExecer(ins)}
func isCompiler[S Compiler](S) int { return 0 }func isBuilder[S Builder](S) int { return 0 }func isExecer[S Execer](S) int { return 0 }func isQuerier[S Querier](S) int { return 0 }