Skip to content

Commit 8f2e4a8

Browse files
authored
Ft/better dot notation (#113)
* fix: timestamp issue with dot notation
1 parent b7173ef commit 8f2e4a8

File tree

3 files changed

+20
-5
lines changed
  • tzatziki-common/src/main/java/com/decathlon/tzatziki/utils
  • tzatziki-core/src/test/resources/com/decathlon/tzatziki/steps
  • tzatziki-mapper/src/main/java/com/decathlon/tzatziki/utils

3 files changed

+20
-5
lines changed

tzatziki-common/src/main/java/com/decathlon/tzatziki/utils/Asserts.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,15 @@ private static void equals(String actual, String expected) {
112112
case "is" -> Mapper.read(actual, TypeParser.parse(stripped(expected)));
113113
case "ignore" -> {} // ignore the value
114114
default -> {
115-
if (actual.matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.?|\\.\\d*)Z?$")) {
116-
if (actual.endsWith("Z")) assertEquals(Instant.parse(expected), Instant.parse(actual));
117-
else assertEquals(Instant.parse(expected + "Z"), Instant.parse(actual + "Z"));
118-
} else {assertEquals(expected, actual);}
115+
Matcher instantMatcher = Pattern.compile("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d*)?(\\+\\d+:\\d+|Z)?$").matcher(actual);
116+
117+
if (instantMatcher.matches()) {
118+
if (instantMatcher.group(1) == null){
119+
expected += "Z";
120+
actual += "Z";
121+
}
122+
assertEquals(Instant.parse(expected), Instant.parse(actual));
123+
} else assertEquals(expected, actual);
119124
}
120125
}
121126
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,16 @@ Feature: to interact with objects in the context
931931
message: another message
932932
"""
933933

934+
Scenario: dot notation should not take dot from timestamp into account
935+
Given that object is:
936+
"""
937+
timestamp: '2021-08-01T12:30:00.000+02:00'
938+
"""
939+
Then object is equal to:
940+
"""
941+
timestamp: '2021-08-01T10:30:00Z'
942+
"""
943+
934944
Scenario: contains should work even if an expected with a map is matched against a non-map (empty string for eg.)
935945
Given that aList is a List<Map>:
936946
"""

tzatziki-mapper/src/main/java/com/decathlon/tzatziki/utils/Mapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private static String dotNotationToYamlObject(String content) {
6868
for (int idx = 0; idx < lines.size(); idx++) {
6969
String line;
7070
String matchOnlyIfNonRegexFlag = "(?![ \"']*\\?e)";
71-
String captureDotNotation = "^(?>([ \\-]*))" + matchOnlyIfNonRegexFlag + "([^.]+)\\.([\\S ]+:" + matchOnlyIfNonRegexFlag + "[^\\n]*)\\n?";
71+
String captureDotNotation = "^(?>([ \\-]*))" + matchOnlyIfNonRegexFlag + "([^.:]+)\\.([\\S ]+:" + matchOnlyIfNonRegexFlag + "[^\\n]*)\\n?";
7272
while ((line = lines.get(idx)).matches(captureDotNotation)) {
7373
String rootObjectIndent = line.replaceAll(captureDotNotation, "$1").replace("-", " ");
7474
String subObjectIndent = " " + rootObjectIndent;

0 commit comments

Comments
 (0)