Skip to content

Commit d042f98

Browse files
committed
Add support for Java 21
1 parent 1da0b1c commit d042f98

3 files changed

Lines changed: 55 additions & 4 deletions

File tree

handlebars/src/test/java/com/github/jknack/handlebars/AbstractTest.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ public void shouldCompileTo(final String template, final String data, final Stri
3434
shouldCompileTo(template, data, expected, "");
3535
}
3636

37+
/**
38+
* Normalizes spaces in the result and compares it with the expected value.
39+
*
40+
* @param template The template to compile.
41+
* @param data The context to apply.
42+
* @param expected The expected result.
43+
* @throws IOException If an I/O error occurs.
44+
*/
45+
public void shouldCompileToNormalized(final String template, final Object data, final String expected)
46+
throws IOException {
47+
shouldCompileToNormalized(template, data, new Hash(), new Hash(), expected, "");
48+
}
49+
3750
public void shouldCompileTo(final String template, final Object data, final String expected)
3851
throws IOException {
3952
shouldCompileTo(template, data, expected, "");
@@ -120,6 +133,41 @@ public void shouldCompileTo(
120133
assertEquals(expected, result, "'" + expected + "' should === '" + result + "': " + message);
121134
}
122135

136+
/*
137+
* Normalizes spaces in the result and compares it with the expected value.
138+
*
139+
* @param template The template to compile.
140+
* @param context The context to apply.
141+
* @param helpers The helpers to use.
142+
* @param partials The partials to use.
143+
* @param expected The expected result.
144+
* @param message The message to display on failure.
145+
* @throws IOException If an I/O error occurs.
146+
*/
147+
public void shouldCompileToNormalized(
148+
final String template,
149+
final Object context,
150+
final Hash helpers,
151+
final Hash partials,
152+
final String expected,
153+
final String message)
154+
throws IOException {
155+
Template t = compile(template, helpers, partials);
156+
String result = t.apply(configureContext(context));
157+
assertEquals(expected, normalizeSpaces(result), "'" + expected + "' should === '" + result + "': " + message);
158+
}
159+
160+
/**
161+
* Helper to normalize narrow no-break space (U+202F) and regular non-breaking space (U+00A0)
162+
* characters to regular space (U+0020).
163+
*/
164+
public String normalizeSpaces(String input) {
165+
return input.replace('\u202F', ' ')
166+
.replace('\u00A0', ' ')
167+
.replaceAll("\\s+", " ") // optional: also collapses multiple spaces
168+
.trim();
169+
}
170+
123171
protected Object configureContext(final Object context) {
124172
return context;
125173
}

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,9 @@
502502
<maven.build.timestamp.format>yyyy-MM-dd HH:mm:ssa</maven.build.timestamp.format>
503503
<maven-antrun-plugin.version>3.1.0</maven-antrun-plugin.version>
504504
<timestamp>${maven.build.timestamp}</timestamp>
505-
<maven.compiler.source>17</maven.compiler.source>
506-
<maven.compiler.target>17</maven.compiler.target>
507-
<maven.compiler.release>17</maven.compiler.release>
505+
<maven.compiler.source>21</maven.compiler.source>
506+
<maven.compiler.target>21</maven.compiler.target>
507+
<maven.compiler.release>21</maven.compiler.release>
508508
<maven.javadoc.failOnError>false</maven.javadoc.failOnError>
509509
<pre-commit-hook>src${file.separator}etc${file.separator}formatter.sh</pre-commit-hook>
510510
<mustache-specs>handlebars${file.separator}src${file.separator}test${file.separator}resources${file.separator}mustache</mustache-specs>

tests/src/test/java/com/github/jknack/handlebars/helper/ext/JodaHelperTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ public void testStyle() throws IOException {
6060
version -> version <= 8,
6161
() -> shouldCompileTo("{{jodaStyleHelper this \"SS\"}}", dateTime, "7/4/95 2:32 PM"));
6262
withJava(
63-
version -> version >= 9,
63+
version -> version >= 9 && version <= 20,
6464
() -> shouldCompileTo("{{jodaStyleHelper this \"SS\"}}", dateTime, "7/4/95, 2:32 PM"));
65+
withJava(
66+
version -> version >= 21,
67+
() -> shouldCompileToNormalized("{{jodaStyleHelper this \"SS\"}}", dateTime, "7/4/95, 2:32 PM"));
6568
}
6669

6770
@Test

0 commit comments

Comments
 (0)