forked from cleveragents/cleveragents-core
102 lines
5.4 KiB
Gherkin
102 lines
5.4 KiB
Gherkin
Feature: SQL String-Aware scanning utilities coverage
|
|
Exercise uncovered code paths in _sql_string_aware.py including
|
|
dollar-quoted strings, escaped single quotes, and nested block
|
|
comments for both strip_sql_comments and find_unquoted_semicolon.
|
|
|
|
Background:
|
|
Given the sql_string_aware module is imported
|
|
|
|
# -----------------------------------------------------------------------
|
|
# strip_sql_comments — escaped single quotes (line 40)
|
|
# -----------------------------------------------------------------------
|
|
Scenario: strip_sql_comments preserves escaped single quotes inside strings
|
|
Given SQL content "SELECT 'it''s a test'"
|
|
When I strip SQL comments
|
|
Then the stripped result should be "SELECT 'it''s a test'"
|
|
|
|
Scenario: strip_sql_comments preserves multiple escaped quotes in one literal
|
|
Given SQL content "SELECT 'he said ''hello'' to her'"
|
|
When I strip SQL comments
|
|
Then the stripped result should be "SELECT 'he said ''hello'' to her'"
|
|
|
|
# -----------------------------------------------------------------------
|
|
# strip_sql_comments — dollar-quoted strings, terminated (lines 52-58)
|
|
# -----------------------------------------------------------------------
|
|
Scenario: strip_sql_comments preserves a terminated dollar-quoted string with anonymous tag
|
|
Given SQL content with a terminated anonymous dollar-quoted string
|
|
When I strip SQL comments
|
|
Then the dollar-quoted body should be preserved intact
|
|
|
|
Scenario: strip_sql_comments preserves a terminated dollar-quoted string with named tag
|
|
Given SQL content with a terminated named dollar-quoted string
|
|
When I strip SQL comments
|
|
Then the named dollar-quoted body should be preserved intact
|
|
|
|
# -----------------------------------------------------------------------
|
|
# strip_sql_comments — dollar-quoted strings, unterminated (lines 60-62)
|
|
# -----------------------------------------------------------------------
|
|
Scenario: strip_sql_comments handles an unterminated dollar-quoted string
|
|
Given SQL content with an unterminated dollar-quoted string
|
|
When I strip SQL comments
|
|
Then the rest of the content should be preserved as-is
|
|
|
|
# -----------------------------------------------------------------------
|
|
# strip_sql_comments — nested block comments (lines 70-71)
|
|
# -----------------------------------------------------------------------
|
|
Scenario: strip_sql_comments removes nested block comments
|
|
Given SQL content "SELECT 1 /* outer /* inner */ still comment */ + 2"
|
|
When I strip SQL comments
|
|
Then the stripped result should be "SELECT 1 + 2"
|
|
|
|
Scenario: strip_sql_comments removes deeply nested block comments
|
|
Given SQL content "A /* a /* b /* c */ b */ a */ B"
|
|
When I strip SQL comments
|
|
Then the stripped result should be "A B"
|
|
|
|
# -----------------------------------------------------------------------
|
|
# find_unquoted_semicolon — escaped single quotes (line 115)
|
|
# -----------------------------------------------------------------------
|
|
Scenario: find_unquoted_semicolon skips semicolons inside escaped single-quoted strings
|
|
Given SQL content "SELECT 'it''s;here'; DROP TABLE"
|
|
When I search for the first unquoted semicolon
|
|
Then the semicolon index should point to the one after the closing quote
|
|
|
|
Scenario: find_unquoted_semicolon with multiple escaped quotes before semicolon
|
|
Given SQL content "'a''b''c';X"
|
|
When I search for the first unquoted semicolon
|
|
Then the semicolon index should be 9
|
|
|
|
# -----------------------------------------------------------------------
|
|
# find_unquoted_semicolon — dollar-quoted strings, terminated (lines 125-129)
|
|
# -----------------------------------------------------------------------
|
|
Scenario: find_unquoted_semicolon skips semicolons inside dollar-quoted strings
|
|
Given SQL content with dollar-quoted string containing a semicolon then real semicolon
|
|
When I search for the first unquoted semicolon
|
|
Then the semicolon should be found after the dollar-quoted string
|
|
|
|
Scenario: find_unquoted_semicolon skips named dollar-quoted strings
|
|
Given SQL content with named dollar-quoted string containing a semicolon then real semicolon
|
|
When I search for the first unquoted semicolon
|
|
Then the semicolon should be found after the named dollar-quoted string
|
|
|
|
# -----------------------------------------------------------------------
|
|
# find_unquoted_semicolon — dollar-quoted strings, unterminated (line 129 else)
|
|
# -----------------------------------------------------------------------
|
|
Scenario: find_unquoted_semicolon returns -1 for unterminated dollar-quoted string
|
|
Given SQL content with an unterminated dollar-quoted string containing a semicolon
|
|
When I search for the first unquoted semicolon
|
|
Then ssacov the result should be -1 indicating no unquoted semicolon
|
|
|
|
# -----------------------------------------------------------------------
|
|
# Combined / integration-style
|
|
# -----------------------------------------------------------------------
|
|
Scenario: strip_sql_comments handles mix of dollar-quoted strings and comments
|
|
Given SQL content mixing dollar-quoted strings and comments
|
|
When I strip SQL comments
|
|
Then only the comments should be removed and dollar strings preserved
|
|
|
|
Scenario: find_unquoted_semicolon with start offset skipping initial semicolons
|
|
Given SQL content ";$$body;$$;end"
|
|
When I search for unquoted semicolon starting at offset 1
|
|
Then the semicolon should be found at index 10
|