| 14 | ) |
| 15 | |
| 16 | func 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 | |
| 39 | func TestNamedExpr(t *testing.T) { |
| 40 | type Base struct { |