diff --git a/CHANGES.md b/CHANGES.md index 20263c1..51171a2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,7 @@ ## Unreleased - Export `Statement` in both Python and Javascript target +- Add tests for #67 ## 2024/09/18 v0.0.7 - Improve error matching on single statement diff --git a/cratedb_sqlparse_js/tests/exceptions.test.js b/cratedb_sqlparse_js/tests/exceptions.test.js index d2ba4d5..0e5f3f7 100644 --- a/cratedb_sqlparse_js/tests/exceptions.test.js +++ b/cratedb_sqlparse_js/tests/exceptions.test.js @@ -70,4 +70,19 @@ test('Exception message is correct', () => { expect(stmts[0].exception.errorMessage).toBe(expectedMessage) expect(stmts[0].exception.getOriginalQueryWithErrorMarked()).toBe(expectedMessageVerbose) +}) + + +test('Whitetest or special characters should not avoid exception catching', () => { + // https://github.com/crate/cratedb-sqlparse/issues/67 + const stmts = [ + `SELECT 1\n limit `, + `SELECT 1\r limit `, + `SELECT 1\t limit `, + `SELECT 1 limit ` + ] + for (const stmt in stmts) { + let r = sqlparse(stmt) + expect(r[0].exception).toBeDefined(); + } }) \ No newline at end of file diff --git a/cratedb_sqlparse_py/tests/test_exceptions.py b/cratedb_sqlparse_py/tests/test_exceptions.py index aa8079d..e095369 100644 --- a/cratedb_sqlparse_py/tests/test_exceptions.py +++ b/cratedb_sqlparse_py/tests/test_exceptions.py @@ -83,3 +83,18 @@ def test_sqlparse_collects_exceptions_3(): assert r[0].exception is None assert r[1].exception is None assert r[2].exception is None + + +def test_sqlparse_catches_exception(): + from cratedb_sqlparse import sqlparse + + # Special characters shouldn't avoid exception catching. + # https://github.com/crate/cratedb-sqlparse/issues/67 + stmts = """ + SELECT 1\n limit, + SELECT 1\r limit, + SELECT 1\t limit, + SELECT 1 limit + """ + for stmt in stmts: + assert sqlparse(stmt)[0].exception