| 22 | func covBoolPtr(v bool) *bool { return &v } |
| 23 | |
| 24 | func TestCreateIndexStatement_SQL(t *testing.T) { |
| 25 | stmt := &CreateIndexStatement{ |
| 26 | Name: "idx_users_email", |
| 27 | Table: "users", |
| 28 | Unique: true, |
| 29 | IfNotExists: true, |
| 30 | Using: "btree", |
| 31 | Columns: []IndexColumn{{Column: "email", Direction: "ASC"}, {Column: "name"}}, |
| 32 | Where: &BinaryExpression{Left: &Identifier{Name: "active"}, Operator: "=", Right: &LiteralValue{Value: "true"}}, |
| 33 | } |
| 34 | sql := stmt.SQL() |
| 35 | for _, want := range []string{"CREATE UNIQUE INDEX", "IF NOT EXISTS", "idx_users_email", "ON users", "USING btree", "email ASC", "WHERE"} { |
| 36 | if !strings.Contains(sql, want) { |
| 37 | t.Errorf("SQL() missing %q, got: %s", want, sql) |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | func TestAlterTableStatement_SQL(t *testing.T) { |
| 43 | stmt := &AlterTableStatement{ |