vibesql-parser 0.2.0

SQL parser for vibesql database engine
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
use super::super::*;

// ========================================================================
// Constraint Tests (Issue #214) - Column-level constraints
// ========================================================================

#[test]
fn test_parse_create_table_with_primary_key() {
    let result =
        Parser::parse_sql("CREATE TABLE users (id INTEGER PRIMARY KEY, name VARCHAR(100));");
    assert!(result.is_ok(), "Should parse column-level PRIMARY KEY");
    let stmt = result.unwrap();

    match stmt {
        vibesql_ast::Statement::CreateTable(create) => {
            assert_eq!(create.table_name, "users");
            assert_eq!(create.columns.len(), 2);
            assert_eq!(create.columns[0].name, "id");
            assert_eq!(create.columns[0].constraints.len(), 1);
            assert!(matches!(
                create.columns[0].constraints[0],
                vibesql_ast::ColumnConstraint {
                    kind: vibesql_ast::ColumnConstraintKind::PrimaryKey { on_conflict: None },
                    ..
                }
            ));
        }
        _ => panic!("Expected CREATE TABLE statement"),
    }
}

#[test]
fn test_parse_create_table_with_unique() {
    let result = Parser::parse_sql("CREATE TABLE users (email VARCHAR(100) UNIQUE);");
    assert!(result.is_ok(), "Should parse UNIQUE constraint");
    let stmt = result.unwrap();

    match stmt {
        vibesql_ast::Statement::CreateTable(create) => {
            assert_eq!(create.columns[0].constraints.len(), 1);
            assert!(matches!(
                create.columns[0].constraints[0],
                vibesql_ast::ColumnConstraint {
                    kind: vibesql_ast::ColumnConstraintKind::Unique { on_conflict: None },
                    ..
                }
            ));
        }
        _ => panic!("Expected CREATE TABLE statement"),
    }
}

#[test]
fn test_parse_create_table_with_check_constraint() {
    let result =
        Parser::parse_sql("CREATE TABLE products (price NUMERIC(10, 2) CHECK (price > 0));");
    assert!(result.is_ok(), "Should parse CHECK constraint");
    let stmt = result.unwrap();

    match stmt {
        vibesql_ast::Statement::CreateTable(create) => {
            assert_eq!(create.columns[0].constraints.len(), 1);
            assert!(matches!(
                create.columns[0].constraints[0],
                vibesql_ast::ColumnConstraint {
                    kind: vibesql_ast::ColumnConstraintKind::Check(_),
                    ..
                }
            ));
        }
        _ => panic!("Expected CREATE TABLE statement"),
    }
}

#[test]
fn test_parse_create_table_with_references() {
    let result =
        Parser::parse_sql("CREATE TABLE orders (customer_id INTEGER REFERENCES customers(id));");
    assert!(result.is_ok(), "Should parse REFERENCES constraint");
    let stmt = result.unwrap();

    match stmt {
        vibesql_ast::Statement::CreateTable(create) => {
            assert_eq!(create.columns[0].constraints.len(), 1);
            match &create.columns[0].constraints[0] {
                vibesql_ast::ColumnConstraint {
                    kind:
                        vibesql_ast::ColumnConstraintKind::References {
                            table,
                            column,
                            on_delete,
                            on_update,
                            ..
                        },
                    ..
                } => {
                    assert_eq!(table, "customers");
                    assert_eq!(column, &Some("id".to_string()));
                    assert!(on_delete.is_none());
                    assert!(on_update.is_none());
                }
                _ => panic!("Expected REFERENCES constraint"),
            }
        }
        _ => panic!("Expected CREATE TABLE statement"),
    }
}

#[test]
fn test_parse_create_table_with_multiple_constraints() {
    let result = Parser::parse_sql(
        "CREATE TABLE employees (
            id INTEGER PRIMARY KEY,
            email VARCHAR(100) UNIQUE,
            salary NUMERIC(10, 2) CHECK (salary > 0),
            department_id INTEGER REFERENCES departments(id)
        );",
    );
    assert!(result.is_ok(), "Should parse multiple column constraints");
    let stmt = result.unwrap();

    match stmt {
        vibesql_ast::Statement::CreateTable(create) => {
            assert_eq!(create.columns.len(), 4);

            // id has PRIMARY KEY
            assert_eq!(create.columns[0].constraints.len(), 1);
            assert!(matches!(
                create.columns[0].constraints[0],
                vibesql_ast::ColumnConstraint {
                    kind: vibesql_ast::ColumnConstraintKind::PrimaryKey { on_conflict: None },
                    ..
                }
            ));

            // email has UNIQUE
            assert_eq!(create.columns[1].constraints.len(), 1);
            assert!(matches!(
                create.columns[1].constraints[0],
                vibesql_ast::ColumnConstraint {
                    kind: vibesql_ast::ColumnConstraintKind::Unique { on_conflict: None },
                    ..
                }
            ));

            // salary has CHECK
            assert_eq!(create.columns[2].constraints.len(), 1);
            assert!(matches!(
                create.columns[2].constraints[0],
                vibesql_ast::ColumnConstraint {
                    kind: vibesql_ast::ColumnConstraintKind::Check(_),
                    ..
                }
            ));

            // department_id has REFERENCES
            assert_eq!(create.columns[3].constraints.len(), 1);
            assert!(matches!(
                create.columns[3].constraints[0],
                vibesql_ast::ColumnConstraint {
                    kind: vibesql_ast::ColumnConstraintKind::References { .. },
                    ..
                }
            ));
        }
        _ => panic!("Expected CREATE TABLE statement"),
    }
}

#[test]
fn test_parse_create_table_enum_with_key() {
    // Test for issue #1425: Parser should handle ENUM with KEY constraint
    let result = Parser::parse_sql(
        "CREATE TABLE t1c857 (
            c1 ENUM ('text667805', 'text667806') COMMENT 'text667808',
            c2 ENUM ('0b10000', 'text667809') KEY
        );",
    );
    assert!(result.is_ok(), "Should parse ENUM with KEY constraint");
    let stmt = result.unwrap();

    match stmt {
        vibesql_ast::Statement::CreateTable(create) => {
            assert_eq!(create.table_name, "t1c857");
            assert_eq!(create.columns.len(), 2);

            // c1 has COMMENT but no KEY
            assert_eq!(create.columns[0].name, "c1");
            assert_eq!(create.columns[0].comment, Some("text667808".to_string()));
            assert_eq!(create.columns[0].constraints.len(), 0);

            // c2 has KEY constraint
            assert_eq!(create.columns[1].name, "c2");
            assert_eq!(create.columns[1].constraints.len(), 1);
            assert!(matches!(
                create.columns[1].constraints[0],
                vibesql_ast::ColumnConstraint { kind: vibesql_ast::ColumnConstraintKind::Key, .. }
            ));
        }
        _ => panic!("Expected CREATE TABLE statement"),
    }
}

#[test]
fn test_parse_create_table_key_constraint() {
    // Test KEY constraint on various data types
    let result = Parser::parse_sql(
        "CREATE TABLE test_key (
            id INT PRIMARY KEY,
            value VARCHAR(100) KEY,
            status ENUM('active', 'inactive') KEY NOT NULL
        );",
    );
    assert!(result.is_ok(), "Should parse KEY constraint on various types");
    let stmt = result.unwrap();

    match stmt {
        vibesql_ast::Statement::CreateTable(create) => {
            assert_eq!(create.columns.len(), 3);

            // value has KEY
            assert!(create.columns[1]
                .constraints
                .iter()
                .any(|c| matches!(c.kind, vibesql_ast::ColumnConstraintKind::Key)));

            // status has KEY and NOT NULL
            assert!(create.columns[2]
                .constraints
                .iter()
                .any(|c| matches!(c.kind, vibesql_ast::ColumnConstraintKind::Key)));
            assert!(create.columns[2]
                .constraints
                .iter()
                .any(|c| matches!(c.kind, vibesql_ast::ColumnConstraintKind::NotNull)));
        }
        _ => panic!("Expected CREATE TABLE statement"),
    }
}

#[test]
fn test_parse_create_table_references_without_column() {
    // SQLite allows REFERENCES table without specifying the column
    // The column defaults to the primary key of the referenced table
    let result = Parser::parse_sql(
        "CREATE TABLE track (
            tid INTEGER PRIMARY KEY,
            aid INTEGER NOT NULL REFERENCES album,
            name TEXT
        );",
    );
    assert!(result.is_ok(), "Should parse REFERENCES without column specification");
    let stmt = result.unwrap();

    match stmt {
        vibesql_ast::Statement::CreateTable(create) => {
            assert_eq!(create.table_name, "track");
            assert_eq!(create.columns.len(), 3);

            // aid has NOT NULL and REFERENCES album (no column specified)
            assert_eq!(create.columns[1].name, "aid");
            assert_eq!(create.columns[1].constraints.len(), 2);

            // Find the REFERENCES constraint
            let refs_constraint = create.columns[1]
                .constraints
                .iter()
                .find(|c| matches!(c.kind, vibesql_ast::ColumnConstraintKind::References { .. }));

            assert!(refs_constraint.is_some(), "Should have REFERENCES constraint");
            match &refs_constraint.unwrap().kind {
                vibesql_ast::ColumnConstraintKind::References { table, column, .. } => {
                    assert_eq!(table, "album");
                    assert_eq!(column, &None); // Column not specified
                }
                _ => panic!("Expected REFERENCES constraint"),
            }
        }
        _ => panic!("Expected CREATE TABLE statement"),
    }
}

// ========================================================================
// DEFERRABLE Constraint Tests (Issue #4990) - Column-level
// ========================================================================

/// Test DEFERRABLE constraint on column-level REFERENCES
#[test]
fn test_parse_references_deferrable() {
    let result = Parser::parse_sql("CREATE TABLE t(a INTEGER REFERENCES p(x) DEFERRABLE)");
    assert!(result.is_ok(), "Should parse REFERENCES with DEFERRABLE: {:?}", result.err());
    let stmt = result.unwrap();

    match stmt {
        vibesql_ast::Statement::CreateTable(create) => {
            assert_eq!(create.columns[0].constraints.len(), 1);
            match &create.columns[0].constraints[0].kind {
                vibesql_ast::ColumnConstraintKind::References {
                    table, column, deferral, ..
                } => {
                    assert_eq!(table, "p");
                    assert_eq!(column, &Some("x".to_string()));
                    let deferral = deferral.expect("Should have deferral");
                    assert!(deferral.is_deferrable, "Should be deferrable");
                    assert!(!deferral.initially_deferred, "Should default to INITIALLY IMMEDIATE");
                }
                _ => panic!("Expected REFERENCES constraint"),
            }
        }
        _ => panic!("Expected CREATE TABLE statement"),
    }
}

/// Test NOT DEFERRABLE constraint on column-level REFERENCES
#[test]
fn test_parse_references_not_deferrable() {
    let result = Parser::parse_sql("CREATE TABLE t(a INTEGER REFERENCES p(x) NOT DEFERRABLE)");
    assert!(result.is_ok(), "Should parse REFERENCES with NOT DEFERRABLE: {:?}", result.err());
    let stmt = result.unwrap();

    match stmt {
        vibesql_ast::Statement::CreateTable(create) => {
            match &create.columns[0].constraints[0].kind {
                vibesql_ast::ColumnConstraintKind::References { deferral, .. } => {
                    let deferral = deferral.expect("Should have deferral");
                    assert!(!deferral.is_deferrable, "Should NOT be deferrable");
                    assert!(!deferral.initially_deferred, "initially_deferred should be false");
                }
                _ => panic!("Expected REFERENCES constraint"),
            }
        }
        _ => panic!("Expected CREATE TABLE statement"),
    }
}

/// Test DEFERRABLE INITIALLY DEFERRED on column-level REFERENCES
#[test]
fn test_parse_references_deferrable_initially_deferred() {
    let result = Parser::parse_sql(
        "CREATE TABLE t(a INTEGER REFERENCES p(x) DEFERRABLE INITIALLY DEFERRED)",
    );
    assert!(result.is_ok(), "Should parse DEFERRABLE INITIALLY DEFERRED: {:?}", result.err());
    let stmt = result.unwrap();

    match stmt {
        vibesql_ast::Statement::CreateTable(create) => {
            match &create.columns[0].constraints[0].kind {
                vibesql_ast::ColumnConstraintKind::References { deferral, .. } => {
                    let deferral = deferral.expect("Should have deferral");
                    assert!(deferral.is_deferrable, "Should be deferrable");
                    assert!(deferral.initially_deferred, "Should be INITIALLY DEFERRED");
                }
                _ => panic!("Expected REFERENCES constraint"),
            }
        }
        _ => panic!("Expected CREATE TABLE statement"),
    }
}

/// Test DEFERRABLE INITIALLY IMMEDIATE on column-level REFERENCES
#[test]
fn test_parse_references_deferrable_initially_immediate() {
    let result = Parser::parse_sql(
        "CREATE TABLE t(a INTEGER REFERENCES p(x) DEFERRABLE INITIALLY IMMEDIATE)",
    );
    assert!(result.is_ok(), "Should parse DEFERRABLE INITIALLY IMMEDIATE: {:?}", result.err());
    let stmt = result.unwrap();

    match stmt {
        vibesql_ast::Statement::CreateTable(create) => {
            match &create.columns[0].constraints[0].kind {
                vibesql_ast::ColumnConstraintKind::References { deferral, .. } => {
                    let deferral = deferral.expect("Should have deferral");
                    assert!(deferral.is_deferrable, "Should be deferrable");
                    assert!(!deferral.initially_deferred, "Should be INITIALLY IMMEDIATE");
                }
                _ => panic!("Expected REFERENCES constraint"),
            }
        }
        _ => panic!("Expected CREATE TABLE statement"),
    }
}

/// Test DEFERRABLE with ON DELETE/UPDATE actions
#[test]
fn test_parse_references_deferrable_with_actions() {
    let result = Parser::parse_sql(
        "CREATE TABLE t(a INTEGER REFERENCES p(x) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED)",
    );
    assert!(result.is_ok(), "Should parse with ON DELETE and DEFERRABLE: {:?}", result.err());
    let stmt = result.unwrap();

    match stmt {
        vibesql_ast::Statement::CreateTable(create) => {
            match &create.columns[0].constraints[0].kind {
                vibesql_ast::ColumnConstraintKind::References { on_delete, deferral, .. } => {
                    assert_eq!(on_delete, &Some(vibesql_ast::ReferentialAction::Cascade));
                    let deferral = deferral.expect("Should have deferral");
                    assert!(deferral.is_deferrable);
                    assert!(deferral.initially_deferred);
                }
                _ => panic!("Expected REFERENCES constraint"),
            }
        }
        _ => panic!("Expected CREATE TABLE statement"),
    }
}

/// Test error: INITIALLY without DEFERRABLE should fail
/// The INITIALLY keyword is only valid after DEFERRABLE/NOT DEFERRABLE
#[test]
fn test_parse_references_initially_without_deferrable_fails() {
    let result = Parser::parse_sql("CREATE TABLE t(a INTEGER REFERENCES p(x) INITIALLY DEFERRED)");
    assert!(result.is_err(), "Should reject INITIALLY without DEFERRABLE");
}

/// Test that REFERENCES without deferral clause has None deferral
#[test]
fn test_parse_references_no_deferral_clause() {
    let result = Parser::parse_sql("CREATE TABLE t(a INTEGER REFERENCES p(x))");
    assert!(result.is_ok(), "Should parse REFERENCES without deferral: {:?}", result.err());
    let stmt = result.unwrap();

    match stmt {
        vibesql_ast::Statement::CreateTable(create) => {
            match &create.columns[0].constraints[0].kind {
                vibesql_ast::ColumnConstraintKind::References { deferral, .. } => {
                    assert!(deferral.is_none(), "Should have no deferral when not specified");
                }
                _ => panic!("Expected REFERENCES constraint"),
            }
        }
        _ => panic!("Expected CREATE TABLE statement"),
    }
}

/// Test ON CONFLICT clause for column-level constraints (SQLite extension)
#[test]
fn test_parse_on_conflict_column_constraints() {
    // Test PRIMARY KEY with ON CONFLICT
    let result = Parser::parse_sql("CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT IGNORE);");
    assert!(result.is_ok(), "Should parse PRIMARY KEY with ON CONFLICT");
    let stmt = result.unwrap();
    match stmt {
        vibesql_ast::Statement::CreateTable(create) => {
            assert_eq!(create.columns[0].constraints.len(), 1);
            match &create.columns[0].constraints[0].kind {
                vibesql_ast::ColumnConstraintKind::PrimaryKey { on_conflict } => {
                    assert_eq!(*on_conflict, Some(vibesql_ast::ConflictClause::Ignore));
                }
                _ => panic!("Expected PrimaryKey constraint"),
            }
        }
        _ => panic!("Expected CREATE TABLE statement"),
    }

    // Test UNIQUE with ON CONFLICT REPLACE
    let result = Parser::parse_sql("CREATE TABLE t2(email TEXT UNIQUE ON CONFLICT REPLACE);");
    assert!(result.is_ok(), "Should parse UNIQUE with ON CONFLICT");
    let stmt = result.unwrap();
    match stmt {
        vibesql_ast::Statement::CreateTable(create) => {
            assert_eq!(create.columns[0].constraints.len(), 1);
            match &create.columns[0].constraints[0].kind {
                vibesql_ast::ColumnConstraintKind::Unique { on_conflict } => {
                    assert_eq!(*on_conflict, Some(vibesql_ast::ConflictClause::Replace));
                }
                _ => panic!("Expected Unique constraint"),
            }
        }
        _ => panic!("Expected CREATE TABLE statement"),
    }

    // Test UNIQUE with ON CONFLICT ABORT
    let result = Parser::parse_sql("CREATE TABLE t3(code TEXT UNIQUE ON CONFLICT ABORT);");
    assert!(result.is_ok(), "Should parse UNIQUE with ON CONFLICT ABORT");
    let stmt = result.unwrap();
    match stmt {
        vibesql_ast::Statement::CreateTable(create) => {
            match &create.columns[0].constraints[0].kind {
                vibesql_ast::ColumnConstraintKind::Unique { on_conflict } => {
                    assert_eq!(*on_conflict, Some(vibesql_ast::ConflictClause::Abort));
                }
                _ => panic!("Expected Unique constraint"),
            }
        }
        _ => panic!("Expected CREATE TABLE statement"),
    }

    // Test PRIMARY KEY with ON CONFLICT ROLLBACK
    let result = Parser::parse_sql("CREATE TABLE t4(id INTEGER PRIMARY KEY ON CONFLICT ROLLBACK);");
    assert!(result.is_ok(), "Should parse PRIMARY KEY with ON CONFLICT ROLLBACK");
    let stmt = result.unwrap();
    match stmt {
        vibesql_ast::Statement::CreateTable(create) => {
            match &create.columns[0].constraints[0].kind {
                vibesql_ast::ColumnConstraintKind::PrimaryKey { on_conflict } => {
                    assert_eq!(*on_conflict, Some(vibesql_ast::ConflictClause::Rollback));
                }
                _ => panic!("Expected PrimaryKey constraint"),
            }
        }
        _ => panic!("Expected CREATE TABLE statement"),
    }

    // Test UNIQUE with ON CONFLICT FAIL
    let result = Parser::parse_sql("CREATE TABLE t5(name TEXT UNIQUE ON CONFLICT FAIL);");
    assert!(result.is_ok(), "Should parse UNIQUE with ON CONFLICT FAIL");
    let stmt = result.unwrap();
    match stmt {
        vibesql_ast::Statement::CreateTable(create) => {
            match &create.columns[0].constraints[0].kind {
                vibesql_ast::ColumnConstraintKind::Unique { on_conflict } => {
                    assert_eq!(*on_conflict, Some(vibesql_ast::ConflictClause::Fail));
                }
                _ => panic!("Expected Unique constraint"),
            }
        }
        _ => panic!("Expected CREATE TABLE statement"),
    }
}

/// Test ON DELETE/UPDATE RESTRICT (SQLite-supported referential action)
#[test]
fn test_parse_references_restrict() {
    let result = Parser::parse_sql(
        "CREATE TABLE t(a INTEGER REFERENCES p(x) ON DELETE RESTRICT ON UPDATE RESTRICT)",
    );
    assert!(result.is_ok(), "Should parse ON DELETE/UPDATE RESTRICT: {:?}", result.err());
    let stmt = result.unwrap();

    match stmt {
        vibesql_ast::Statement::CreateTable(create) => {
            match &create.columns[0].constraints[0].kind {
                vibesql_ast::ColumnConstraintKind::References { on_delete, on_update, .. } => {
                    assert_eq!(on_delete, &Some(vibesql_ast::ReferentialAction::Restrict));
                    assert_eq!(on_update, &Some(vibesql_ast::ReferentialAction::Restrict));
                }
                _ => panic!("Expected REFERENCES constraint"),
            }
        }
        _ => panic!("Expected CREATE TABLE statement"),
    }
}

/// Test that DEFAULT can appear after column constraints (SQLite grammar).
/// Example from fkey1-8.1: `idx UNIQUE DEFAULT NULL`
#[test]
fn test_parse_default_after_constraint() {
    let result = Parser::parse_sql("CREATE TABLE t(idx UNIQUE DEFAULT NULL)");
    assert!(result.is_ok(), "Should parse DEFAULT after UNIQUE: {:?}", result.err());
    let stmt = result.unwrap();

    match stmt {
        vibesql_ast::Statement::CreateTable(create) => {
            assert_eq!(create.columns[0].constraints.len(), 1);
            match &create.columns[0].constraints[0].kind {
                vibesql_ast::ColumnConstraintKind::Unique { .. } => {}
                _ => panic!("Expected UNIQUE constraint"),
            }
            assert!(
                create.columns[0].default_value.is_some(),
                "DEFAULT after UNIQUE should be captured on ColumnDef.default_value"
            );
        }
        _ => panic!("Expected CREATE TABLE statement"),
    }
}

/// Test that DEFAULT can appear interleaved with multiple constraints.
#[test]
fn test_parse_default_interleaved_with_constraints() {
    let result = Parser::parse_sql("CREATE TABLE t(c INT NOT NULL DEFAULT 0 CHECK(c >= 0))");
    assert!(result.is_ok(), "Should parse interleaved DEFAULT: {:?}", result.err());
    let stmt = result.unwrap();

    match stmt {
        vibesql_ast::Statement::CreateTable(create) => {
            assert!(create.columns[0].default_value.is_some(), "DEFAULT 0 should be captured");
            // NOT NULL + CHECK should both appear as constraints
            assert!(create.columns[0].constraints.iter().any(
                |c| matches!(c.kind, vibesql_ast::ColumnConstraintKind::NotNull)
            ));
            assert!(create.columns[0].constraints.iter().any(
                |c| matches!(c.kind, vibesql_ast::ColumnConstraintKind::Check(_))
            ));
        }
        _ => panic!("Expected CREATE TABLE statement"),
    }
}

/// Test that providing two DEFAULT clauses for the same column is rejected.
#[test]
fn test_parse_default_double_rejected() {
    let result = Parser::parse_sql("CREATE TABLE t(c INT DEFAULT 0 UNIQUE DEFAULT 1)");
    assert!(result.is_err(), "Should reject two DEFAULT clauses on the same column");
}