From 2b18dc78df853db92a87177b7595804f7f50842b Mon Sep 17 00:00:00 2001 From: Jack Smith Date: Fri, 6 Dec 2024 10:58:33 -0500 Subject: [PATCH] Change tests to accept jdk21 locales for date/time formatting --- .../interpret/JinjavaInterpreterTest.java | 2 +- .../lib/filter/DateTimeFormatFilterTest.java | 5 ++++- .../filter/time/FormatDatetimeFilterTest.java | 21 +++++++++++-------- .../lib/filter/time/FormatTimeFilterTest.java | 20 +++++++++--------- .../lib/fn/DateFormatFunctionsTest.java | 4 ++-- .../objects/date/StrftimeFormatterTest.java | 10 +++++---- 6 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/test/java/com/hubspot/jinjava/interpret/JinjavaInterpreterTest.java b/src/test/java/com/hubspot/jinjava/interpret/JinjavaInterpreterTest.java index f866db349..c23fd8339 100644 --- a/src/test/java/com/hubspot/jinjava/interpret/JinjavaInterpreterTest.java +++ b/src/test/java/com/hubspot/jinjava/interpret/JinjavaInterpreterTest.java @@ -380,7 +380,7 @@ public void itInterpretsFormattedDates() { ) ); - assertThat(result).isEqualTo("Oct 20, 2022, 5:09:43 PM"); + assertThat(result).isIn("Oct 20, 2022, 5:09:43 PM", "Oct 20, 2022, 5:09:43 PM"); } @Test diff --git a/src/test/java/com/hubspot/jinjava/lib/filter/DateTimeFormatFilterTest.java b/src/test/java/com/hubspot/jinjava/lib/filter/DateTimeFormatFilterTest.java index 13761e0b9..a4544bf79 100644 --- a/src/test/java/com/hubspot/jinjava/lib/filter/DateTimeFormatFilterTest.java +++ b/src/test/java/com/hubspot/jinjava/lib/filter/DateTimeFormatFilterTest.java @@ -125,7 +125,10 @@ public void itConvertsToLocaleSpecificDateTimeFormat() { "en-US" ) ) - .isEqualTo("10/11/18 1:09:45 PM - Oct 11, 2018, 1:09:45 PM"); + .isIn( + "10/11/18 1:09:45 PM - Oct 11, 2018, 1:09:45 PM", + "10/11/18 1:09:45 PM - Oct 11, 2018, 1:09:45 PM" + ); assertThat( filter.filter( 1539277785000L, diff --git a/src/test/java/com/hubspot/jinjava/lib/filter/time/FormatDatetimeFilterTest.java b/src/test/java/com/hubspot/jinjava/lib/filter/time/FormatDatetimeFilterTest.java index 03977ea2d..c6dbe0aa5 100644 --- a/src/test/java/com/hubspot/jinjava/lib/filter/time/FormatDatetimeFilterTest.java +++ b/src/test/java/com/hubspot/jinjava/lib/filter/time/FormatDatetimeFilterTest.java @@ -37,7 +37,7 @@ public void itFormatsNumbers() { assertThat( jinjava.render("{{ d | format_datetime }}", ImmutableMap.of("d", 1668120547000L)) ) - .isEqualTo("Nov 10, 2022, 10:49:07 PM"); + .isIn("Nov 10, 2022, 10:49:07 PM", "Nov 10, 2022, 10:49:07 PM"); } @Test @@ -47,7 +47,7 @@ public void itFormatsPyishDates() { assertThat( jinjava.render("{{ d | format_datetime }}", ImmutableMap.of("d", pyishDate)) ) - .isEqualTo("Nov 10, 2022, 10:49:07 PM"); + .isIn("Nov 10, 2022, 10:49:07 PM", "Nov 10, 2022, 10:49:07 PM"); } @Test @@ -55,7 +55,7 @@ public void itFormatsZonedDateTime() { assertThat( jinjava.render("{{ d | format_datetime }}", ImmutableMap.of("d", DATE_TIME)) ) - .isEqualTo("Nov 10, 2022, 10:49:07 PM"); + .isIn("Nov 10, 2022, 10:49:07 PM", "Nov 10, 2022, 10:49:07 PM"); } @Test @@ -78,7 +78,7 @@ public void itUsesShortFormat() { ImmutableMap.of("d", DATE_TIME) ) ) - .isEqualTo("11/10/22, 10:49 PM"); + .isIn("11/10/22, 10:49 PM", "11/10/22, 10:49 PM"); } @Test @@ -89,7 +89,7 @@ public void itUsesMediumFormat() { ImmutableMap.of("d", DATE_TIME) ) ) - .isEqualTo("Nov 10, 2022, 10:49:07 PM"); + .isIn("Nov 10, 2022, 10:49:07 PM", "Nov 10, 2022, 10:49:07 PM"); } @Test @@ -97,7 +97,7 @@ public void itUsesLongFormat() { assertThat( jinjava.render("{{ d | format_datetime('long') }}", ImmutableMap.of("d", DATE_TIME)) ) - .isEqualTo("November 10, 2022 at 10:49:07 PM Z"); + .isIn("November 10, 2022 at 10:49:07 PM Z", "November 10, 2022, 10:49:07 PM Z"); } @Test @@ -105,7 +105,10 @@ public void itUsesFullFormat() { assertThat( jinjava.render("{{ d | format_datetime('full') }}", ImmutableMap.of("d", DATE_TIME)) ) - .isEqualTo("Thursday, November 10, 2022 at 10:49:07 PM Z"); + .isIn( + "Thursday, November 10, 2022 at 10:49:07 PM Z", + "Thursday, November 10, 2022, 10:49:07 PM Z" + ); } @Test @@ -140,7 +143,7 @@ public void itUsesGivenTimeZone() { ImmutableMap.of("d", DATE_TIME) ) ) - .isEqualTo("November 10, 2022 at 5:49:07 PM EST"); + .isIn("November 10, 2022 at 5:49:07 PM EST", "November 10, 2022, 5:49:07 PM EST"); } @Test @@ -230,6 +233,6 @@ public void itUsesJinjavaConfigIfNullLocalePassed() { ImmutableMap.of("d", DATE_TIME) ) ) - .isEqualTo("11/10/22, 5:49 PM"); + .isIn("11/10/22, 5:49 PM", "11/10/22, 5:49 PM"); } } diff --git a/src/test/java/com/hubspot/jinjava/lib/filter/time/FormatTimeFilterTest.java b/src/test/java/com/hubspot/jinjava/lib/filter/time/FormatTimeFilterTest.java index 4f6a96f9a..300334684 100644 --- a/src/test/java/com/hubspot/jinjava/lib/filter/time/FormatTimeFilterTest.java +++ b/src/test/java/com/hubspot/jinjava/lib/filter/time/FormatTimeFilterTest.java @@ -37,7 +37,7 @@ public void itFormatsNumbers() { assertThat( jinjava.render("{{ d | format_time }}", ImmutableMap.of("d", 1668120547000L)) ) - .isEqualTo("10:49:07 PM"); + .isIn("10:49:07 PM", "10:49:07 PM"); } @Test @@ -45,13 +45,13 @@ public void itFormatsPyishDates() { PyishDate pyishDate = new PyishDate(1668120547000L); assertThat(jinjava.render("{{ d | format_time }}", ImmutableMap.of("d", pyishDate))) - .isEqualTo("10:49:07 PM"); + .isIn("10:49:07 PM", "10:49:07 PM"); } @Test public void itFormatsZonedDateTime() { assertThat(jinjava.render("{{ d | format_time }}", ImmutableMap.of("d", DATE_TIME))) - .isEqualTo("10:49:07 PM"); + .isIn("10:49:07 PM", "10:49:07 PM"); } @Test @@ -71,7 +71,7 @@ public void itUsesShortFormat() { assertThat( jinjava.render("{{ d | format_time('short') }}", ImmutableMap.of("d", DATE_TIME)) ) - .isEqualTo("10:49 PM"); + .isIn("10:49 PM", "10:49 PM"); } @Test @@ -79,7 +79,7 @@ public void itUsesMediumFormat() { assertThat( jinjava.render("{{ d | format_time('medium') }}", ImmutableMap.of("d", DATE_TIME)) ) - .isEqualTo("10:49:07 PM"); + .isIn("10:49:07 PM", "10:49:07 PM"); } @Test @@ -87,7 +87,7 @@ public void itUsesLongFormat() { assertThat( jinjava.render("{{ d | format_time('long') }}", ImmutableMap.of("d", DATE_TIME)) ) - .isEqualTo("10:49:07 PM Z"); + .isIn("10:49:07 PM Z", "10:49:07 PM Z"); } @Test @@ -95,7 +95,7 @@ public void itUsesFullFormat() { assertThat( jinjava.render("{{ d | format_time('full') }}", ImmutableMap.of("d", DATE_TIME)) ) - .isEqualTo("10:49:07 PM Z"); + .isIn("10:49:07 PM Z", "10:49:07 PM Z"); } @Test @@ -127,7 +127,7 @@ public void itUsesGivenTimeZone() { ImmutableMap.of("d", DATE_TIME) ) ) - .isEqualTo("5:49:07 PM EST"); + .isIn("5:49:07 PM EST", "5:49:07 PM EST"); } @Test @@ -195,7 +195,7 @@ public void itUsesMediumIfNullFormatPassed() { ImmutableMap.of("d", DATE_TIME) ) ) - .isEqualTo("17:49:07"); + .isIn("17:49:07", "5:49 PM"); } @Test @@ -217,6 +217,6 @@ public void itUsesJinjavaConfigIfNullLocalePassed() { ImmutableMap.of("d", DATE_TIME) ) ) - .isEqualTo("5:49 PM"); + .isIn("5:49 PM", "5:49 PM"); } } diff --git a/src/test/java/com/hubspot/jinjava/lib/fn/DateFormatFunctionsTest.java b/src/test/java/com/hubspot/jinjava/lib/fn/DateFormatFunctionsTest.java index 1dde7928c..9e28eee10 100644 --- a/src/test/java/com/hubspot/jinjava/lib/fn/DateFormatFunctionsTest.java +++ b/src/test/java/com/hubspot/jinjava/lib/fn/DateFormatFunctionsTest.java @@ -37,7 +37,7 @@ public void itFormatsTimes() { ImmutableMap.of("d", ZonedDateTime.of(2022, 11, 28, 16, 30, 4, 0, ZoneOffset.UTC)) ) ) - .isEqualTo("4:30:04 PM"); + .isIn("4:30:04 PM", "4:30:04 PM"); } @Test @@ -48,6 +48,6 @@ public void itFormatsDateTimes() { ImmutableMap.of("d", ZonedDateTime.of(2022, 11, 28, 16, 30, 4, 0, ZoneOffset.UTC)) ) ) - .isEqualTo("Nov 28, 2022, 4:30:04 PM"); + .isIn("Nov 28, 2022, 4:30:04 PM", "Nov 28, 2022, 4:30:04 PM"); } } diff --git a/src/test/java/com/hubspot/jinjava/objects/date/StrftimeFormatterTest.java b/src/test/java/com/hubspot/jinjava/objects/date/StrftimeFormatterTest.java index 3cda22f7c..c8ec80429 100644 --- a/src/test/java/com/hubspot/jinjava/objects/date/StrftimeFormatterTest.java +++ b/src/test/java/com/hubspot/jinjava/objects/date/StrftimeFormatterTest.java @@ -58,7 +58,8 @@ public void testWithNoPcts() { @Test public void testDateTime() { - assertThat(StrftimeFormatter.format(d, "%c")).isEqualTo("Nov 6, 2013, 2:22:00 PM"); + assertThat(StrftimeFormatter.format(d, "%c")) + .isIn("Nov 6, 2013, 2:22:00 PM", "Nov 6, 2013, 2:22:00 PM"); } @Test @@ -73,12 +74,13 @@ public void testDayOfWeekNumber() { @Test public void testTime() { - assertThat(StrftimeFormatter.format(d, "%X")).isEqualTo("2:22:00 PM"); + assertThat(StrftimeFormatter.format(d, "%X")).isIn("2:22:00 PM", "2:22:00 PM"); } @Test public void testMicrosecs() { - assertThat(StrftimeFormatter.format(d, "%X %f")).isEqualTo("2:22:00 PM 123000"); + assertThat(StrftimeFormatter.format(d, "%X %f")) + .isIn("2:22:00 PM 123000", "2:22:00 PM 123000"); } @Test @@ -98,7 +100,7 @@ public void testPaddedMinFmt() { @Test public void testFinnishMonths() { assertThat(StrftimeFormatter.format(d, "long", Locale.forLanguageTag("fi"))) - .startsWith("6. marraskuuta 2013 klo 14.22.00"); + .isIn("6. marraskuuta 2013 klo 14.22.00 UTC", "6. marraskuuta 2013 14.22.00 UTC"); } @Test