MCPcopy
hub / github.com/go-gorm/gorm / TestExpr

Function TestExpr

clause/expression_test.go:16–37  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestExpr(t *testing.T) {
17 results := []struct {
18 SQL string
19 Result string
20 Vars []interface{}
21 }{{
22 SQL: "create table ? (? ?, ? ?)",
23 Vars: []interface{}{clause.Table{Name: "users"}, clause.Column{Name: "id"}, clause.Expr{SQL: "int"}, clause.Column{Name: "name"}, clause.Expr{SQL: "text"}},
24 Result: "create table `users` (`id` int, `name` text)",
25 }}
26
27 for idx, result := range results {
28 t.Run(fmt.Sprintf("case #%v", idx), func(t *testing.T) {
29 user, _ := schema.Parse(&tests.User{}, &sync.Map{}, db.NamingStrategy)
30 stmt := &gorm.Statement{DB: db, Table: user.Table, Schema: user, Clauses: map[string]clause.Clause{}}
31 clause.Expr{SQL: result.SQL, Vars: result.Vars}.Build(stmt)
32 if stmt.SQL.String() != result.Result {
33 t.Errorf("generated SQL is not equal, expects %v, but got %v", result.Result, stmt.SQL.String())
34 }
35 })
36 }
37}
38
39func TestNamedExpr(t *testing.T) {
40 type Base struct {

Callers

nothing calls this directly

Calls 3

ParseFunction · 0.92
BuildMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected