Skip to content

Commit

Permalink
Merge pull request #22900 from mkouba/qute-relax-infix-notation
Browse files Browse the repository at this point in the history
Qute - relax infix notation syntax
  • Loading branch information
gsmet authored Jan 18, 2022
2 parents 50233fc + b234db3 commit 063a825
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,20 @@ public static List<String> splitParts(String value, SplitConfig splitConfig) {
}
// Non-separator char
if (!literal) {
// Not inside a string/type literal
if (brackets == 0 && c == ' ' && splitConfig.isInfixNotationSupported()) {
// Not inside a virtual method
if (infix == 1) {
// The second space after the infix method
// Infix supported, blank space and not inside a virtual method
if (separator == 0
&& (buffer.length() == 0 || buffer.charAt(buffer.length() - 1) == '(')) {
// Skip redundant blank space:
// 1. before the infix method
// foo or bar
// ----^
// 2. before an infix method parameter
// foo or bar
// -------^
} else if (infix == 1) {
// The space after the infix method
// foo or bar
// ------^
buffer.append(LEFT_BRACKET);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ public void testExpressions() throws InterruptedException, ExecutionException {
virtualMethod("or", ExpressionImpl.literalFrom(-1, "null")));
}

@Test
public void testInfixNotationRedundantSpace() throws InterruptedException, ExecutionException {
verify("name or 'John'", null, null, name("name"), virtualMethod("or", ExpressionImpl.from("'John'")));
verify("name or 'John'", null, null, name("name"), virtualMethod("or", ExpressionImpl.from("'John'")));
verify("name or 'John'", null, null, name("name"), virtualMethod("or", ExpressionImpl.from("'John'")));
verify("name or 'John' or 1", null, null, name("name"), virtualMethod("or", ExpressionImpl.from("'John'")),
virtualMethod("or", ExpressionImpl.literalFrom(-1, "1")));
verify("name or 'John' or 1", null, null, name("name"), virtualMethod("or", ExpressionImpl.from("'John'")),
virtualMethod("or", ExpressionImpl.literalFrom(-1, "1")));
}

@Test
public void testNestedVirtualMethods() {
assertNestedVirtualMethod(ExpressionImpl.from("movie.findServices(movie.name,movie.toNumber(movie.getName))"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public void testOrElseResolver() {
data.put("nameOptional", Optional.of("BUG"));
assertEquals("John Bug", engine.parse("{name.or('John')} {surname.or('John')}").render(data));
assertEquals("John Bug", engine.parse("{name ?: 'John'} {surname or 'John'}").render(data));
assertEquals("John Bug", engine.parse("{name ?: 'John'} {surname or 'John'}").render(data));
assertEquals("John Bug", engine.parse("{name ?: \"John Bug\"}").render(data));
assertEquals("Is null", engine.parse("{foo ?: 'Is null'}").render(data));
assertEquals("10", engine.parse("{foo.age.limit ?: 10}").render(data));
Expand Down

0 comments on commit 063a825

Please sign in to comment.