Skip to content

Commit

Permalink
add object context ut
Browse files Browse the repository at this point in the history
  • Loading branch information
DQinYuan committed Sep 26, 2024
1 parent 92b504c commit 8e6b3f5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -496,18 +496,20 @@ public Void visitBreakContinueStatement(BreakContinueStatementContext ctx) {

@Override
public Void visitListExpr(ListExprContext ctx) {
ListItemsContext listItemsContext = ctx.listItems();
ErrorReporter listErrorReporter = newReporterWithToken(ctx.getStart());
visitListExprInner(ctx.listItems(), newReporterWithToken(ctx.getStart()));
return null;
}

private void visitListExprInner(ListItemsContext listItemsContext, ErrorReporter listErrorReporter) {
if (listItemsContext == null) {
addInstruction(new ConstInstruction(listErrorReporter, new ArrayList<>()));
return null;
return;
}
List<ExpressionContext> expressions = listItemsContext.expression();
for (ExpressionContext expression : expressions) {
expression.accept(this);
}
addInstruction(new NewListInstruction(listErrorReporter, expressions.size()));
return null;
}

@Override
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/com/alibaba/qlexpress4/Express4RunnerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,23 @@ public void addMacroTest() {
assertEquals(express4Runner.execute("[1,2,3,4]", new HashMap<>(), QLOptions.DEFAULT_OPTIONS), result);
}

public static class MyObj {
public int a;
public String b;
}

@Test
public void executeWithObjContextTest() {
MyObj myObj = new MyObj();
myObj.a = 1;
myObj.b = "test";

Express4Runner express4Runner = new Express4Runner(InitOptions.builder()
.build());
Object result = express4Runner.execute("a+b", myObj, QLOptions.DEFAULT_OPTIONS);
assertEquals("1test", result);
}

private void assertResultEquals(Express4Runner express4Runner, String script, Object expect) {
assertResultPredicate(express4Runner, script, result -> Objects.equals(expect, result));
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/alibaba/qlexpress4/TestSuiteRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void suiteTest() throws URISyntaxException, IOException {

@Test
public void featureDebug() throws URISyntaxException, IOException {
Path filePath = getTestSuiteRoot().resolve("java/implicit/incompatible_assignment_type.ql");
Path filePath = getTestSuiteRoot().resolve("independent/for/return_from_for.ql");
handleFile(filePath, filePath.toString(), true);
}

Expand Down

0 comments on commit 8e6b3f5

Please sign in to comment.