Skip to content

Commit be92f2e

Browse files
authored
feat: noIndent helper (#125)
1 parent 3d16399 commit be92f2e

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

tzatziki-core/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ Then resultArray is equal to:
350350
"""
351351
```
352352

353-
Other custom helpers are foreach (loop through array), split (split a String by symbol), math (compute some value) and conditional helpers (to compare values and output conditionally)
353+
Other custom helpers are foreach (loop through array), split (split a String by symbol), math (compute some value), noIndent (remove indent right before processing to improve visibility) and conditional helpers (to compare values and output conditionally)
354354

355355
## Time management
356356

tzatziki-core/src/main/java/com/decathlon/tzatziki/steps/ObjectSteps.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ public class ObjectSteps {
134134
}).toList();
135135

136136
return options.fn(collectionsToConcat.stream().flatMap(Collection::stream).collect(Collectors.toList()));
137-
});
137+
})
138+
.registerHelper("noIndent", (str, options) -> options.handlebars.compileInline(str.toString().replaceAll("(?m)(?:^\\s+|\\s+$)", "").replaceAll("\\n", "")).apply(options.context));
138139

139140
static {
140141
register(Type.class, TypeParser::parse);

tzatziki-core/src/test/resources/com/decathlon/tzatziki/steps/objects.feature

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,24 @@ Feature: to interact with objects in the context
692692
value: value2
693693
"""
694694

695+
Scenario: noIndent helper can be used to help increase readability in scenario while allowing handlebars to properly interpret the String
696+
Given that helloWorld is "Hello World"
697+
Given that chainedMethodCalls is:
698+
"""
699+
{{noIndent '{{[
700+
701+
helloWorld
702+
.replaceAll(e, 3)
703+
.replaceAll(l, 1)
704+
.replaceAll(o, 0)
705+
706+
]}}'}}
707+
"""
708+
Then chainedMethodCalls is equal to:
709+
"""
710+
H3110 W0r1d
711+
"""
712+
695713
Scenario Template: else guard allows to run a step only if the latest-evaluated condition was false
696714
Given that condition is "<ifCondition>"
697715
When if <ifCondition> == true => ran is "if"
@@ -945,7 +963,7 @@ Feature: to interact with objects in the context
945963
current_time:
946964
timestamp: '2021-08-01T10:30:00Z'
947965
"""
948-
966+
949967
Scenario: contains should work even if an expected with a map is matched against a non-map (empty string for eg.)
950968
Given that aList is a List<Map>:
951969
"""

0 commit comments

Comments
 (0)