From be92f2e470c90a25a056039100975bb9e8204dc5 Mon Sep 17 00:00:00 2001 From: brian-mulier <69139631+brian-mulier@users.noreply.github.com> Date: Thu, 22 Dec 2022 12:41:44 +0100 Subject: [PATCH] feat: noIndent helper (#125) --- tzatziki-core/README.md | 2 +- .../decathlon/tzatziki/steps/ObjectSteps.java | 3 ++- .../decathlon/tzatziki/steps/objects.feature | 20 ++++++++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/tzatziki-core/README.md b/tzatziki-core/README.md index 63b4eb83..84262eee 100644 --- a/tzatziki-core/README.md +++ b/tzatziki-core/README.md @@ -350,7 +350,7 @@ Then resultArray is equal to: """ ``` -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) +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) ## Time management diff --git a/tzatziki-core/src/main/java/com/decathlon/tzatziki/steps/ObjectSteps.java b/tzatziki-core/src/main/java/com/decathlon/tzatziki/steps/ObjectSteps.java index 3a6b7867..7559fe57 100644 --- a/tzatziki-core/src/main/java/com/decathlon/tzatziki/steps/ObjectSteps.java +++ b/tzatziki-core/src/main/java/com/decathlon/tzatziki/steps/ObjectSteps.java @@ -134,7 +134,8 @@ public class ObjectSteps { }).toList(); return options.fn(collectionsToConcat.stream().flatMap(Collection::stream).collect(Collectors.toList())); - }); + }) + .registerHelper("noIndent", (str, options) -> options.handlebars.compileInline(str.toString().replaceAll("(?m)(?:^\\s+|\\s+$)", "").replaceAll("\\n", "")).apply(options.context)); static { register(Type.class, TypeParser::parse); diff --git a/tzatziki-core/src/test/resources/com/decathlon/tzatziki/steps/objects.feature b/tzatziki-core/src/test/resources/com/decathlon/tzatziki/steps/objects.feature index a6220dde..e98c40c9 100644 --- a/tzatziki-core/src/test/resources/com/decathlon/tzatziki/steps/objects.feature +++ b/tzatziki-core/src/test/resources/com/decathlon/tzatziki/steps/objects.feature @@ -692,6 +692,24 @@ Feature: to interact with objects in the context value: value2 """ + Scenario: noIndent helper can be used to help increase readability in scenario while allowing handlebars to properly interpret the String + Given that helloWorld is "Hello World" + Given that chainedMethodCalls is: + """ + {{noIndent '{{[ + + helloWorld + .replaceAll(e, 3) + .replaceAll(l, 1) + .replaceAll(o, 0) + + ]}}'}} + """ + Then chainedMethodCalls is equal to: + """ + H3110 W0r1d + """ + Scenario Template: else guard allows to run a step only if the latest-evaluated condition was false Given that condition is "" When if == true => ran is "if" @@ -945,7 +963,7 @@ Feature: to interact with objects in the context current_time: timestamp: '2021-08-01T10:30:00Z' """ - + Scenario: contains should work even if an expected with a map is matched against a non-map (empty string for eg.) Given that aList is a List: """