TestFormat_CreateSequence verifies that CREATE SEQUENCE statements are rendered by the dedicated formatter arm rather than falling back to stmtSQL/TokenLiteral.
(t *testing.T)
| 27 | // TestFormat_CreateSequence verifies that CREATE SEQUENCE statements are rendered |
| 28 | // by the dedicated formatter arm rather than falling back to stmtSQL/TokenLiteral. |
| 29 | func TestFormat_CreateSequence(t *testing.T) { |
| 30 | sql := "CREATE SEQUENCE user_id_seq START WITH 1 INCREMENT BY 1" |
| 31 | tree, err := gosqlx.ParseWithDialect(sql, keywords.DialectMariaDB) |
| 32 | if err != nil { |
| 33 | t.Fatalf("Parse error: %v", err) |
| 34 | } |
| 35 | if len(tree.Statements) == 0 { |
| 36 | t.Fatal("expected at least one statement") |
| 37 | } |
| 38 | stmt, ok := tree.Statements[0].(*ast.CreateSequenceStatement) |
| 39 | if !ok { |
| 40 | t.Fatalf("expected *ast.CreateSequenceStatement, got %T", tree.Statements[0]) |
| 41 | } |
| 42 | |
| 43 | opts := ast.FormatOptions{} |
| 44 | result := formatter.FormatStatement(stmt, opts) |
| 45 | upper := strings.ToUpper(result) |
| 46 | if !strings.Contains(upper, "CREATE") { |
| 47 | t.Errorf("expected CREATE in output, got: %q", result) |
| 48 | } |
| 49 | if !strings.Contains(upper, "SEQUENCE") { |
| 50 | t.Errorf("expected SEQUENCE in output, got: %q", result) |
| 51 | } |
| 52 | if !strings.Contains(result, "user_id_seq") { |
| 53 | t.Errorf("expected sequence name in output, got: %q", result) |
| 54 | } |
| 55 | if !strings.Contains(upper, "START WITH") { |
| 56 | t.Errorf("expected START WITH in output, got: %q", result) |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | // TestFormat_CreateSequence_IfNotExists verifies IF NOT EXISTS is rendered. |
| 61 | func TestFormat_CreateSequence_IfNotExists(t *testing.T) { |
nothing calls this directly
no test coverage detected