Skip to content

Commit

Permalink
Add tests to check that special characters '\r, \n, \t' don't block e…
Browse files Browse the repository at this point in the history
…xception collecting
  • Loading branch information
surister committed Oct 6, 2024
1 parent 9d7490e commit e093a5b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions cratedb_sqlparse_js/tests/exceptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
})
15 changes: 15 additions & 0 deletions cratedb_sqlparse_py/tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e093a5b

Please sign in to comment.