Skip to content

Commit badfea3

Browse files
Place regression tests beside related syntax cases
1 parent 069df96 commit badfea3

1 file changed

Lines changed: 98 additions & 98 deletions

File tree

‎tests/sqlparser_sqlite.rs‎

Lines changed: 98 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,104 @@ fn test_dollar_identifier_as_placeholder() {
596596
}
597597
}
598598

599+
#[test]
600+
fn parse_sqlite_variable_tokens() {
601+
for sql in [
602+
"SELECT #a",
603+
"SELECT @a",
604+
"SELECT :a",
605+
"SELECT $a",
606+
"SELECT @2t",
607+
"SELECT :9c",
608+
"SELECT @a$",
609+
"SELECT :a$",
610+
"SELECT :a()",
611+
"SELECT :a(x)",
612+
"SELECT @a()",
613+
"SELECT :::6",
614+
"SELECT :a::b",
615+
"SELECT $a::b",
616+
"SELECT @::b",
617+
"SELECT #::b",
618+
"SELECT ($$::)",
619+
"SELECT @\u{00e9}",
620+
"SELECT :\u{00e9}",
621+
"SELECT #\u{00e9}",
622+
"SELECT :::\u{00e9}",
623+
] {
624+
sqlite().verified_stmt(sql);
625+
}
626+
sqlite().one_statement_parses_to("SELECT @2t i", "SELECT @2t AS i");
627+
628+
let generic = TestedDialects::new(vec![Box::new(GenericDialect {})]);
629+
for (sql, err) in [
630+
(
631+
"SELECT :::6",
632+
ParserError::ParserError("Expected: an expression, found: ::".to_string()),
633+
),
634+
(
635+
"SELECT ($$::)",
636+
ParserError::TokenizerError(
637+
"Unterminated dollar-quoted string at Line: 1, Column: 14".to_string(),
638+
),
639+
),
640+
] {
641+
assert_eq!(generic.parse_sql_statements(sql), Err(err), "{sql}");
642+
}
643+
// SQLite ends a subscript at whitespace and rejects the token
644+
assert_eq!(
645+
sqlite().parse_sql_statements("SELECT $a(x y)"),
646+
Err(ParserError::TokenizerError(
647+
"Unterminated SQLite variable subscript at Line: 1, Column: 8".to_string()
648+
))
649+
);
650+
// A vertical tab also ends a subscript in SQLite's tokenizer
651+
assert_eq!(
652+
sqlite().parse_sql_statements("SELECT :a(x\u{000b}y)"),
653+
Err(ParserError::TokenizerError(
654+
"Unterminated SQLite variable subscript at Line: 1, Column: 8".to_string()
655+
))
656+
);
657+
}
658+
659+
#[test]
660+
fn parse_colon_is_not_an_operator() {
661+
for (sql, err) in [
662+
(
663+
"SELECT b : c",
664+
ParserError::ParserError("Expected: end of statement, found: :".to_string()),
665+
),
666+
(
667+
"SELECT a / b : c",
668+
ParserError::ParserError("Expected: end of statement, found: :".to_string()),
669+
),
670+
(
671+
"SELECT b : c.d",
672+
ParserError::ParserError("Expected: end of statement, found: :".to_string()),
673+
),
674+
(
675+
"SELECT b : \"c\"",
676+
ParserError::ParserError("Expected: end of statement, found: :".to_string()),
677+
),
678+
(
679+
"SELECT b :c",
680+
ParserError::ParserError("Expected: end of statement, found: :c".to_string()),
681+
),
682+
] {
683+
assert_eq!(sqlite().parse_sql_statements(sql), Err(err), "{sql}");
684+
}
685+
sqlite().verified_stmt("SELECT a FROM t WHERE b = :c");
686+
}
687+
688+
#[test]
689+
fn tokenize_hash_digit_is_not_a_variable() {
690+
let tokens = Tokenizer::new(&SQLiteDialect {}, "#123")
691+
.tokenize()
692+
.unwrap();
693+
let expected = vec![Token::Sharp, Token::Number("123".to_string(), false)];
694+
assert_eq!(tokens, expected);
695+
}
696+
599697
#[test]
600698
fn test_match_operator() {
601699
assert_eq!(
@@ -1464,101 +1562,3 @@ fn parse_bitwise_and_or_share_precedence() {
14641562
assert_eq!(sqlite().verified_expr(sql), expected, "{sql}");
14651563
}
14661564
}
1467-
1468-
#[test]
1469-
fn parse_sqlite_variable_tokens() {
1470-
for sql in [
1471-
"SELECT #a",
1472-
"SELECT @a",
1473-
"SELECT :a",
1474-
"SELECT $a",
1475-
"SELECT @2t",
1476-
"SELECT :9c",
1477-
"SELECT @a$",
1478-
"SELECT :a$",
1479-
"SELECT :a()",
1480-
"SELECT :a(x)",
1481-
"SELECT @a()",
1482-
"SELECT :::6",
1483-
"SELECT :a::b",
1484-
"SELECT $a::b",
1485-
"SELECT @::b",
1486-
"SELECT #::b",
1487-
"SELECT ($$::)",
1488-
"SELECT @\u{00e9}",
1489-
"SELECT :\u{00e9}",
1490-
"SELECT #\u{00e9}",
1491-
"SELECT :::\u{00e9}",
1492-
] {
1493-
sqlite().verified_stmt(sql);
1494-
}
1495-
sqlite().one_statement_parses_to("SELECT @2t i", "SELECT @2t AS i");
1496-
1497-
let generic = TestedDialects::new(vec![Box::new(GenericDialect {})]);
1498-
for (sql, err) in [
1499-
(
1500-
"SELECT :::6",
1501-
ParserError::ParserError("Expected: an expression, found: ::".to_string()),
1502-
),
1503-
(
1504-
"SELECT ($$::)",
1505-
ParserError::TokenizerError(
1506-
"Unterminated dollar-quoted string at Line: 1, Column: 14".to_string(),
1507-
),
1508-
),
1509-
] {
1510-
assert_eq!(generic.parse_sql_statements(sql), Err(err), "{sql}");
1511-
}
1512-
// SQLite ends a subscript at whitespace and rejects the token
1513-
assert_eq!(
1514-
sqlite().parse_sql_statements("SELECT $a(x y)"),
1515-
Err(ParserError::TokenizerError(
1516-
"Unterminated SQLite variable subscript at Line: 1, Column: 8".to_string()
1517-
))
1518-
);
1519-
// A vertical tab also ends a subscript in SQLite's tokenizer
1520-
assert_eq!(
1521-
sqlite().parse_sql_statements("SELECT :a(x\u{000b}y)"),
1522-
Err(ParserError::TokenizerError(
1523-
"Unterminated SQLite variable subscript at Line: 1, Column: 8".to_string()
1524-
))
1525-
);
1526-
}
1527-
1528-
#[test]
1529-
fn parse_colon_is_not_an_operator() {
1530-
for (sql, err) in [
1531-
(
1532-
"SELECT b : c",
1533-
ParserError::ParserError("Expected: end of statement, found: :".to_string()),
1534-
),
1535-
(
1536-
"SELECT a / b : c",
1537-
ParserError::ParserError("Expected: end of statement, found: :".to_string()),
1538-
),
1539-
(
1540-
"SELECT b : c.d",
1541-
ParserError::ParserError("Expected: end of statement, found: :".to_string()),
1542-
),
1543-
(
1544-
"SELECT b : \"c\"",
1545-
ParserError::ParserError("Expected: end of statement, found: :".to_string()),
1546-
),
1547-
(
1548-
"SELECT b :c",
1549-
ParserError::ParserError("Expected: end of statement, found: :c".to_string()),
1550-
),
1551-
] {
1552-
assert_eq!(sqlite().parse_sql_statements(sql), Err(err), "{sql}");
1553-
}
1554-
sqlite().verified_stmt("SELECT a FROM t WHERE b = :c");
1555-
}
1556-
1557-
#[test]
1558-
fn tokenize_hash_digit_is_not_a_variable() {
1559-
let tokens = Tokenizer::new(&SQLiteDialect {}, "#123")
1560-
.tokenize()
1561-
.unwrap();
1562-
let expected = vec![Token::Sharp, Token::Number("123".to_string(), false)];
1563-
assert_eq!(tokens, expected);
1564-
}

0 commit comments

Comments
 (0)