@@ -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 }
0 commit comments