Skip to content

Commit 631265e

Browse files
committed
Add parser unit tests (81 tests) and fix IF NOT EXISTS parsing
- Created tests/parser_tests.cpp with comprehensive coverage of: - SELECT with all clauses (WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, OFFSET, JOINs) - CREATE TABLE/INDEX, INSERT, UPDATE, DELETE, DROP - Transaction statements (BEGIN, COMMIT, ROLLBACK) - Expression parsing (binary, unary, IN, IS NULL, functions) - Error handling and edge cases - Fixed parse_create_table() to handle IF NOT EXISTS in correct order (was checking for NOT before IF, now correctly checks IF before NOT) - Note: PRIMARY KEY not supported by lexer (missing PRIMARY/KEY keywords)
1 parent 36b2833 commit 631265e

3 files changed

Lines changed: 845 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ if(BUILD_TESTS)
137137
add_cloudsql_test(columnar_table_tests tests/columnar_table_tests.cpp)
138138
add_cloudsql_test(heap_table_tests tests/heap_table_tests.cpp)
139139
add_cloudsql_test(lexer_tests tests/lexer_tests.cpp)
140+
add_cloudsql_test(parser_tests tests/parser_tests.cpp)
140141
add_cloudsql_test(storage_manager_tests tests/storage_manager_tests.cpp)
141142
add_cloudsql_test(rpc_server_tests tests/rpc_server_tests.cpp)
142143
add_cloudsql_test(operator_tests tests/operator_tests.cpp)

src/parser/parser.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,10 @@ std::unique_ptr<Statement> Parser::parse_create_table() {
287287
}
288288

289289
/* IF NOT EXISTS */
290-
if (consume(TokenType::Not)) {
290+
if (consume(TokenType::If)) {
291+
if (!consume(TokenType::Not)) {
292+
return nullptr;
293+
}
291294
if (!consume(TokenType::Exists)) {
292295
return nullptr;
293296
}

0 commit comments

Comments
 (0)