Skip to content

Commit 07eedf2

Browse files
authored
feat: we can now concat multiple arrays using concat helper (#40)
1 parent 6f97c22 commit 07eedf2

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
managed-logger.repository=autodetect
2+
managed-logger.repository.enabled=false
3+
banner.hide=true

tzatziki-core/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,34 @@ And userName is equal to "bob"
294294

295295
*notice that you need to surround your expression with `{{{[ expression ]}}}` to have Handlebars deal with the whitespaces*
296296

297+
You can also use some built-in-handlebars helpers, or use some custom helpers for Tzatziki. One is used for example to concatenate multiple arrays :
298+
```gherkin
299+
Given that myFirstArray is:
300+
"""
301+
- firstItem
302+
- secondItem
303+
"""
304+
And that mySecondArray is:
305+
"""
306+
- thirdItem
307+
- fourthItem
308+
"""
309+
310+
When resultArray is:
311+
"""
312+
{{#concat myFirstArray mySecondArray}}
313+
{{this}}
314+
{{/concat}}
315+
"""
316+
317+
Then resultArray is equal to:
318+
"""
319+
[firstItem, secondItem, thirdItem, fourthItem]
320+
"""
321+
```
322+
323+
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)
324+
297325
## Time management
298326

299327
This library uses [Natty](http://natty.joestelmach.com/try.jsp) to express time human friendly way.

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.regex.Matcher;
4444
import java.util.regex.Pattern;
4545
import java.util.stream.Collectors;
46+
import java.util.stream.Stream;
4647

4748
import static com.decathlon.tzatziki.steps.DynamicTransformers.register;
4849
import static com.decathlon.tzatziki.utils.Comparison.IS_COMPARED_TO;
@@ -91,6 +92,22 @@ public class ObjectSteps {
9192
return ((Collection<?>) context).stream()
9293
.map(value -> unchecked(() -> options.fn(value)))
9394
.collect(Collectors.joining());
95+
})
96+
.registerHelper("concat", (firstArray, options) -> {
97+
if(options.params.length <= 0){
98+
return null;
99+
}
100+
101+
List<Collection<?>> collectionsToConcat = Stream.concat(Stream.of(firstArray), Arrays.stream(options.params))
102+
.map(arrayToConcat -> {
103+
if (arrayToConcat instanceof Collection<?> array) {
104+
return array;
105+
} else {
106+
return Mapper.<List<?>>read(arrayToConcat.toString(), List.class);
107+
}
108+
}).toList();
109+
110+
return collectionsToConcat.stream().flatMap(Collection::stream).collect(Collectors.toList());
94111
});
95112

96113
static {

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,11 +609,40 @@ Feature: to interact with objects in the context
609609
And it is not true that it is not true that it is not true that it is not true that test is equal to "true"
610610
And it is not true that within 100ms it is not true that during 100ms it is not true that test is equal to "true"
611611

612-
Scenario Template:
612+
Scenario Template: some additional conditional chain guards
613613
Given that if <shouldDoTask> == true => after 100ms taskDone is "true"
614614
Then if <shouldDoTask> == true => within 110ms taskDone is equal to "true"
615615

616616
Examples:
617617
| shouldDoTask |
618618
| true |
619619
| false |
620+
621+
Scenario: concatenate multiple arrays using handlebars helper
622+
Given that myFirstArray is:
623+
"""
624+
- firstItem
625+
- secondItem
626+
"""
627+
And that mySecondArray is:
628+
"""
629+
- thirdItem
630+
- fourthItem
631+
"""
632+
And that myThirdArray is:
633+
"""
634+
- fifthItem
635+
- sixthItem
636+
"""
637+
638+
When resultArray is:
639+
"""
640+
{{#concat myFirstArray mySecondArray myThirdArray}}
641+
{{this}}
642+
{{/concat}}
643+
"""
644+
645+
Then resultArray is equal to:
646+
"""
647+
[firstItem, secondItem, thirdItem, fourthItem, fifthItem, sixthItem]
648+
"""

0 commit comments

Comments
 (0)