Skip to content

Expand parser/token edge-case test coverage for error recovery, whitespace filtering, and null-state branches - #32

Merged
fupacat merged 4 commits into
masterfrom
copilot/add-unit-test-coverage-tsql180parser
Oct 12, 2026
Merged

fupacat merged 4 commits into
masterfrom
copilot/add-unit-test-coverage-tsql180parser

Conversation

Copilot AI commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Coverage gaps existed in core parsing/token utilities around parser error recovery, quoted-identifier initialization paths, whitespace/comment filtering boundaries, and null/error-state branches in lightweight value objects. This PR adds focused unit tests to exercise those branches without changing production behavior.

  • Parser recovery + constructor-path coverage (TSql180ParserTest)

    • Adds coverage for parse(null, errors) returning null without mutating error state.
    • Adds a malformed SQL case to validate syntax errors are surfaced through parse-error collection.
    • Exercises both TSql180Parser(true) and TSql180Parser(false) constructor paths to cover quoted-identifier initialization toggles.
  • Whitespace/comment filter edge cases (TSqlWhitespaceTokenFilterTest)

    • Adds stream-backed and list-backed tests for:
      • adjacent multiline comments,
      • mixed comment/whitespace skipping,
      • EOF emission and last-token state.
    • Verifies AsciiStringOrQuotedIdentifier conversion behavior under quoted-identifier on/off modes.
  • Token + parse-result null/error branches

    • TSqlParserTokenTest: adds null token-type constructor case to validate fallback to TSqlTokenType.None and underlying ANTLR type 0.
    • ParseResultTest (new): adds null-errors/immutable-empty-list and non-empty-errors branches, including isSuccess()/hasErrors()/toString() behavior.
// New branch coverage example: null token type fallback
TSqlParserToken token = new TSqlParserToken(null, 7, "?", 3, 4);
assertThat(token._getTokenType()).isEqualTo(TSqlTokenType.None);
assertThat(token.getType()).isZero();

Co-authored-by: fupacat <595487+fupacat@users.noreply.github.com>
Copilot AI changed the title [WIP] Add unit test coverage for TSql180Parser and related classes Expand parser/token edge-case test coverage for error recovery, whitespace filtering, and null-state branches Oct 12, 2026
Copilot AI requested a review from fupacat October 12, 2026 19:17
@fupacat
fupacat marked this pull request as ready for review October 12, 2026 20:08
Copilot AI balanced review requested due to automatic review settings October 12, 2026 20:08
@fupacat
fupacat enabled auto-merge (squash) October 12, 2026 20:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is additive, test-only with no production behavior change, and each new assertion was verified to match the existing production code.

0 open findings

What changed in this PR

This PR adds focused unit tests to close SonarCloud coverage gaps in the tsql-scriptdom-core parser/token utilities (issue #29). No production code is modified; the tests exercise previously uncovered branches in parser error recovery, quoted-identifier initialization, whitespace/comment filtering boundaries, and null/error-state handling in lightweight value objects. I verified each new assertion against the corresponding production code (TSqlWhitespaceTokenFilter, TSqlParserToken, TSql180Parser, ParseResult) and found them consistent with actual behavior; imports are present, and every TRACEABILITY_MAPPING references a requirement that exists in context/SRS.md.

Changes:

  • Adds TSql180ParserTest cases for parse(null, errors), malformed-SQL error collection, and both quoted-identifier constructor paths.
  • Extends TSqlWhitespaceTokenFilterTest with adjacent-comment/EOF-boundary, inner-stream skip-to-EOF, and AsciiStringOrQuotedIdentifier conversion-flag tests.
  • Adds a null-token-type fallback test (TSqlParserTokenTest) and a new ParseResultTest covering null/non-empty error branches and immutability.
File Description
tsql-scriptdom-core/​src/​test/​java/​io/​github/​fupacat/​TSql180ParserTest.java Adds null-reader, syntax-error, and quoted-identifier constructor coverage.
tsql-scriptdom-core/​src/​test/​java/​io/​github/​fupacat/​TSqlWhitespaceTokenFilterTest.java Adds list-backed and inner-stream filter edge cases plus conversion-flag checks.
tsql-scriptdom-core/​src/​test/​java/​io/​github/​fupacat/​TSqlParserTokenTest.java Adds null token-type fallback to None/ANTLR type 0.
tsql-scriptdom-core/​src/​test/​java/​io/​github/​fupacat/​ParseResultTest.java New test for null/non-empty error branches, immutability, and toString.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI balanced review requested due to automatic review settings October 12, 2026 20:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

testParseSyntaxErrorIsCollected asserts a non-null fragment for malformed SQL, but the defaultErrorHandler=false grammar causes _parse to return null, so the test will fail.

1 open finding

🧠 Review effort: Balanced


TSqlFragment fragment = parser.parse(new StringReader("SELECT FROM WHERE;"), errors);

assertThat(fragment).isNotNull();
Copilot AI balanced review requested due to automatic review settings October 12, 2026 20:25
@fupacat
fupacat merged commit 46e9018 into master Oct 12, 2026
6 checks passed
@fupacat
fupacat deleted the copilot/add-unit-test-coverage-tsql180parser branch October 12, 2026 20:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approved

Test-only additions whose assertions I verified line-by-line against the production code, with valid symbol references and correct REQ traceability mappings.

1 open finding

🧠 Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit test coverage for TSql180Parser error recovery, tokens, and filter edge cases

3 participants