test: add regression tests for #439 (logical NOT immediately after AND/OR/EQ) - #446
Open
chenjunwenhao wants to merge 1 commit into
Open
Conversation
…tely after AND) Issue alibaba#439 reported that expressions like `if(oldObj!=null&&!oldObj.getLong("status"))` failed to compile in v4 due to the ANTLR4 lexer greedily merging `&&!` into a single OPID token instead of separate `&&` + `!` tokens. The bug has been fixed by replacing ANTLR4 with a hand-written lexer, but no regression tests existed for this edge case. This PR adds 11 tests covering: Lexer-level (3 tests): - `&&!` → OPID(`&&`) + BANG(`!`) - `||!` → OPID(`||`) + BANG(`!`) - `==!` → OPID(`==`) + BANG(`!`) Parser/Execution-level (8 tests): - `a && !b` with spaces (baseline) - `a&&!b` without spaces (core regression) - `if(x!=null&&!y)` mixed operators - `a&&!b&&!c` chained - `oldObj!=null&&!oldObj.equals("test")` complex - Short-circuit when null - `a||!b` OR variant - Full original issue pattern All 215 existing tests + 11 new tests pass. Fixes alibaba#439
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Issue #439 reported that
&&!(logical NOT immediately after logical AND, without spaces) failed to compile in QLExpress v4. The root cause was the ANTLR4 lexer's greedy longest-match rule merging&&!into a singleOPIDtoken instead ofOPID("&&")+BANG("!").The bug has been fixed in the current
mainbranch (ANTLR4 was replaced with a hand-written lexer that explicitly handles&&,||,==,!=as 2-character tokens). However, no regression tests existed for this edge case.This PR adds 11 regression tests to prevent future regressions.
Changes
New file:
src/test/java/com/alibaba/qlexpress4/test/issue/Issue439RegressionTest.javaLexer-level tests (3)
lexerShouldSplitAndBangIntoOpidAndBang&&!&&) + BANG(!)lexerShouldSplitOrBangIntoOpidAndBang||!||) + BANG(!)lexerShouldSplitEqBangIntoOpidAndBang==!==) + BANG(!)Parser / Execution tests (8)
executeLogicalAndNotWithSpacesa && !bexecuteLogicalAndNotWithoutSpacesa&&!bexecuteIfNotNullAndNotWithNoSpacesif(x!=null&&!y)executeNestedAndNotWithoutSpacesa&&!b&&!cexecuteComplexNotNullAndNotEqualsWithoutSpacesoldObj!=null&&!oldObj.equals("test")executeComplexNotNullShortCircuitWhenNulloldObjexecuteLogicalOrNotWithoutSpacesa||!bexecuteOriginalIssuePatternTest Results
Fixes #439