Skip to content

Commit

Permalink
preprocessor: fixed temporary variable values not supporting closing …
Browse files Browse the repository at this point in the history
…parentheses as values
  • Loading branch information
BlvckBytes committed Oct 30, 2024
1 parent b4123ae commit 3236c60
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Tuple<String, Boolean> preProcess(String input, PreProcessorInput substit
var temporaryVariables = Map.<String, String>of();

if (openingParenthesisIndex >= 0) {
var closingParenthesisIndex = substitutionContent.indexOf(')');
var closingParenthesisIndex = substitutionContent.lastIndexOf(')');

if (closingParenthesisIndex > openingParenthesisIndex) {
var temporaryVariablesContent = substitutionContent.substring(openingParenthesisIndex + 1, closingParenthesisIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,16 @@ public void shouldRenderInterpolations() throws Exception {
public void shouldParseTemporaryVariables() throws Exception {
var preProcessor = new PreProcessor();
var temporaryVariables = preProcessor.parseTemporaryVariables(
"a=lut[\"PREFIX\"];B = test ; c =if x then y else z",
"a=lut[\"PREFIX\"];B = test ; c =if x then y else z; d=key(y); e=value(y)",
0
);

assertEquals(3, temporaryVariables.size());
assertEquals(5, temporaryVariables.size());
assertEquals("lut[\"PREFIX\"]", temporaryVariables.get("a"));
assertEquals("test", temporaryVariables.get("b"));
assertEquals("if x then y else z", temporaryVariables.get("c"));
assertEquals("key(y)", temporaryVariables.get("d"));
assertEquals("value(y)", temporaryVariables.get("e"));
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/preprocessor/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ multilineList:
- |
hello world
test
@{KEY-C}
@{KEY-C(y=key(a); z=value(a))}
another line
2 changes: 1 addition & 1 deletion src/test/resources/preprocessor/result.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ multilineList$:
- |
hello world
test
"before " & x & " after"
"before " & x & " after " & (key(a)) & " and " & (value(a))
another line
2 changes: 1 addition & 1 deletion src/test/resources/preprocessor/substitution_input.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
KEY-A value a
KEY-B value b
KEY-C before {x} after
KEY-C before {x} after {y} and {z}

0 comments on commit 3236c60

Please sign in to comment.