| 116 | } |
| 117 | |
| 118 | func TestAlterSequenceStatement_ToSQL(t *testing.T) { |
| 119 | tests := []struct { |
| 120 | name string |
| 121 | stmt *ast.AlterSequenceStatement |
| 122 | want string |
| 123 | }{ |
| 124 | { |
| 125 | name: "restart bare", |
| 126 | stmt: &ast.AlterSequenceStatement{ |
| 127 | Name: &ast.Identifier{Name: "s"}, |
| 128 | Options: ast.SequenceOptions{Restart: true}, |
| 129 | }, |
| 130 | want: "ALTER SEQUENCE s RESTART", |
| 131 | }, |
| 132 | { |
| 133 | name: "restart with value", |
| 134 | stmt: &ast.AlterSequenceStatement{ |
| 135 | Name: &ast.Identifier{Name: "s"}, |
| 136 | Options: ast.SequenceOptions{ |
| 137 | RestartWith: &ast.LiteralValue{Value: "1"}, |
| 138 | }, |
| 139 | }, |
| 140 | want: "ALTER SEQUENCE s RESTART WITH 1", |
| 141 | }, |
| 142 | { |
| 143 | name: "nil name does not panic", |
| 144 | stmt: &ast.AlterSequenceStatement{}, |
| 145 | want: "ALTER SEQUENCE ", |
| 146 | }, |
| 147 | } |
| 148 | for _, tt := range tests { |
| 149 | t.Run(tt.name, func(t *testing.T) { |
| 150 | got := tt.stmt.ToSQL() |
| 151 | if got != tt.want { |
| 152 | t.Errorf("ToSQL() = %q, want %q", got, tt.want) |
| 153 | } |
| 154 | }) |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | func TestSequencePool_RoundTrip(t *testing.T) { |
| 159 | s := ast.NewCreateSequenceStatement() |