Visitar URL original
Complete traversal of structured DDL children by minleejae · Pull Request #2738 · JSQLParser/JSqlParser · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: cover VALUES child traversal with context
Signed-off-by: minleejae <mmj9808@gmail.com>
  • Loading branch information
minleejae committed Oct 1, 2026
commit 7f8bb7fb24401a4940ff89d36aefa8e224603c08
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.sf.jsqlparser.util.deparser.StatementDeParser;
import net.sf.jsqlparser.util.validation.Validation;
import net.sf.jsqlparser.util.validation.feature.FeaturesAllowed;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
Expand Down Expand Up @@ -62,6 +63,25 @@ static Stream<Arguments> definitions() {
List.of("7", "9", "before"), List.of("t", "log")));
}

@Test
void valuesChildrenIncludingWithAndTailKeepTheVisitorContext() throws Exception {
Object context = new Object();
List<Long> values = new ArrayList<>();
ExpressionVisitorAdapter<Void> expressions = new ExpressionVisitorAdapter<Void>() {
@Override
public <S> Void visit(LongValue value, S actualContext) {
assertSame(context, actualContext);
values.add(value.getValue());
return null;
}
};
Statement statement = CCJSqlParserUtil.parse(
"WITH c AS (SELECT 11) VALUES (22) ORDER BY (33 + 0) LIMIT 44 OFFSET 55");
statement.accept(new StatementVisitorAdapter<>(new SelectVisitorAdapter<>(expressions)),
context);
assertEquals(List.of(11L, 22L, 33L, 0L, 44L, 55L), values);
}

@ParameterizedTest
@MethodSource("definitions")
void visitsAndMutatesChildrenWithContext(String sql, List<String> expectedValues,
Expand Down Expand Up @@ -97,7 +117,7 @@ public <S> Void visit(Table table, S actualContext) {
}
};
SelectVisitorAdapter<Void> selects =
new SelectVisitorAdapter<>(expressions, null, null, fromItems);
new SelectVisitorAdapter<>(expressions, fromItems);
statement.accept(new StatementVisitorAdapter<>(selects), context);
assertEquals(expectedValues, values);
assertEquals(expectedTables, tables);
Expand Down
Loading