Skip to content

Commit 3651d7f

Browse files
committed
build: attempt to fix windows build
1 parent 6a4ab57 commit 3651d7f

File tree

18 files changed

+290
-109
lines changed

18 files changed

+290
-109
lines changed

handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Jackson2HelperTest.java

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
*/
1414
package com.github.jknack.handlebars;
1515

16-
import static org.junit.Assert.assertEquals;
16+
import static com.github.jknack.handlebars.IgnoreWindowsLineMatcher.equalsToStringIgnoringWindowsNewLine;
17+
import static org.hamcrest.MatcherAssert.assertThat;
1718

1819
import java.io.IOException;
1920
import java.util.HashMap;
@@ -40,10 +41,8 @@ public void toJSON() throws IOException {
4041

4142
Template template = handlebars.compileInline("{{@json this}}");
4243

43-
CharSequence result = template.apply(new Blog("First Post", "..."));
44-
45-
assertEquals("{\"title\":\"First Post\",\"body\":\"...\",\"comments\":[]}",
46-
result);
44+
assertThat(template.apply(new Blog("First Post", "...")), equalsToStringIgnoringWindowsNewLine(
45+
"{\"title\":\"First Post\",\"body\":\"...\",\"comments\":[]}"));
4746
}
4847

4948
@Test
@@ -53,14 +52,12 @@ public void toPrettyJSON() throws IOException {
5352

5453
Template template = handlebars.compileInline("{{@json this pretty=true}}");
5554

56-
CharSequence result = template.apply(new Blog("First Post", "..."));
57-
58-
assertEquals("{\n" +
59-
" \"title\" : \"First Post\",\n" +
60-
" \"body\" : \"...\",\n" +
61-
" \"comments\" : [ ]\n" +
62-
"}",
63-
result);
55+
assertThat(template.apply(new Blog("First Post", "...")),
56+
equalsToStringIgnoringWindowsNewLine("{\n" +
57+
" \"title\" : \"First Post\",\n" +
58+
" \"body\" : \"...\",\n" +
59+
" \"comments\" : [ ]\n" +
60+
"}"));
6461
}
6562

6663
@Test
@@ -71,12 +68,12 @@ public void toJSONViewInclusive() throws IOException {
7168

7269
Template template =
7370
handlebars
74-
.compileInline("{{@json this view=\"com.github.jknack.handlebars.Blog$Views$Public\"}}");
75-
76-
CharSequence result = template.apply(new Blog("First Post", "..."));
71+
.compileInline(
72+
"{{@json this view=\"com.github.jknack.handlebars.Blog$Views$Public\"}}");
7773

78-
assertEquals("{\"title\":\"First Post\",\"body\":\"...\",\"comments\":[]}",
79-
result);
74+
assertThat(template.apply(new Blog("First Post", "...")),
75+
equalsToStringIgnoringWindowsNewLine(
76+
"{\"title\":\"First Post\",\"body\":\"...\",\"comments\":[]}"));
8077
}
8178

8279
@Test
@@ -90,11 +87,11 @@ public void toJSONViewExclusive() throws IOException {
9087

9188
Template template =
9289
handlebars
93-
.compileInline("{{@json this view=\"com.github.jknack.handlebars.Blog$Views$Public\"}}");
90+
.compileInline(
91+
"{{@json this view=\"com.github.jknack.handlebars.Blog$Views$Public\"}}");
9492

95-
CharSequence result = template.apply(new Blog("First Post", "..."));
96-
97-
assertEquals("{\"title\":\"First Post\"}", result);
93+
assertThat(template.apply(new Blog("First Post", "...")),
94+
equalsToStringIgnoringWindowsNewLine("{\"title\":\"First Post\"}"));
9895
}
9996

10097
@Test
@@ -111,9 +108,8 @@ public void toJSONAliasViewExclusive() throws IOException {
111108
handlebars
112109
.compileInline("{{@json this view=\"myView\"}}");
113110

114-
CharSequence result = template.apply(new Blog("First Post", "..."));
115-
116-
assertEquals("{\"title\":\"First Post\"}", result);
111+
assertThat(template.apply(new Blog("First Post", "...")),
112+
equalsToStringIgnoringWindowsNewLine("{\"title\":\"First Post\"}"));
117113
}
118114

119115
@Test(expected = HandlebarsException.class)
@@ -129,9 +125,8 @@ public void jsonViewNotFound() throws IOException {
129125
handlebars
130126
.compileInline("{{@json this view=\"missing.ViewClass\"}}");
131127

132-
CharSequence result = template.apply(new Blog("First Post", "..."));
133-
134-
assertEquals("{\"title\":\"First Post\"}", result);
128+
assertThat(template.apply(new Blog("First Post", "...")),
129+
equalsToStringIgnoringWindowsNewLine("{\"title\":\"First Post\"}"));
135130
}
136131

137132
@Test
@@ -142,11 +137,12 @@ public void escapeHtml() throws IOException {
142137
Map<String, String> model = new HashMap<String, String>();
143138
model.put("script", "<script text=\"text/javascript\"></script>");
144139

145-
assertEquals("{\"script\":\"<script text=\\\"text/javascript\\\"></script>\"}", handlebars
146-
.compileInline("{{@json this}}").apply(model));
140+
assertThat(handlebars
141+
.compileInline("{{@json this}}").apply(model), equalsToStringIgnoringWindowsNewLine(
142+
"{\"script\":\"<script text=\\\"text/javascript\\\"></script>\"}"));
147143

148-
assertEquals(
149-
"{\"script\":\"\\u003Cscript text=\\\"text/javascript\\\"\\u003E\\u003C/script\\u003E\"}",
150-
handlebars.compileInline("{{@json this escapeHTML=true}}").apply(model));
144+
assertThat(handlebars.compileInline("{{@json this escapeHTML=true}}").apply(model),
145+
equalsToStringIgnoringWindowsNewLine(
146+
"{\"script\":\"\\u003Cscript text=\\\"text/javascript\\\"\\u003E\\u003C/script\\u003E\"}"));
151147
}
152148
}

handlebars-maven-plugin/a.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
... () {
2+
// Source: src[/test/resources/partials/level1/level1.html
3+
4+
var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
5+
var helper, lookupProperty = container.lookupProperty || function(parent, propertyName) {
6+
if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
7+
return parent[propertyName];
8+
}
9+
return undefined
10+
};
11+
12+
return "<h1>I'm "
13+
+ container.escapeExpression(((helper = (helper = lookupProperty(helpers,"level1") || (depth0 != null ? lookupProperty(depth0,"level1") : depth0)) != null ? helper : container.hooks.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"level1","hash":{},"data":data,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":18}}}) : helper)))
14+
+ "</h1>";
15+
},"useData":true});
16+
var templates = Handlebars.templates = Handlebars.templates || {};
17+
templates['level1/level1'] = template;
18+
var partials = Handlebars.partials = Handlebars.partials || {};
19+
partials['level1/level1'] = template;
20+
21+
22+
// Source: src/test/resources/partials/partial/base.html
23+
24+
var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
25+
var stack1, lookupProperty = container.lookupProperty || function(parent, propertyName) {
26+
if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
27+
return parent[propertyName];
28+
}
29+
return undefined
30+
};
31+
32+
return "I'm the base partial\n"
33+
+ ((stack1 = container.invokePartial(lookupProperty(partials,"partial/partial"),depth0,{"name":"partial/partial","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "");
34+
},"usePartial":true,"useData":true});
35+
var templates = Handlebars.templates = Handlebars.templates || {};
36+
templates['partial/base'] = template;
37+
var partials = Handlebars.partials = Handlebars.partials || {};
38+
partials['partial/base'] = template;
39+
40+
41+
// Source: src/test/resources/partials/partial/partial.html
42+
43+
var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
44+
return "I'm the child partial";
45+
},"useData":true});
46+
var templates = Handlebars.templates = Handlebars.templates || {};
47+
templates['partial/partial'] = template;
48+
var partials = Handlebars.partials = Handlebars.partials || {};
49+
partials['partial/partial'] = template;
50+
51+
52+
// Source: src/test/resources/partials/r]oot.html
53+
54+
var temp...

handlebars-maven-plugin/b.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
... () {
2+
// Source: src[\testesources\partials\level1\level1.html
3+
4+
var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
5+
var helper, lookupProperty = container.lookupProperty || function(parent, propertyName) {
6+
if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
7+
return parent[propertyName];
8+
}
9+
return undefined
10+
};
11+
12+
return "<h1>I'm "
13+
+ container.escapeExpression(((helper = (helper = lookupProperty(helpers,"level1") || (depth0 != null ? lookupProperty(depth0,"level1") : depth0)) != null ? helper : container.hooks.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"level1","hash":{},"data":data,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":18}}}) : helper)))
14+
+ "</h1>";
15+
},"useData":true});
16+
var templates = Handlebars.templates = Handlebars.templates || {};
17+
templates['level1/level1'] = template;
18+
var partials = Handlebars.partials = Handlebars.partials || {};
19+
partials['level1/level1'] = template;
20+
21+
22+
// Source: src\testesources\partials\partial\base.html
23+
24+
var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
25+
var stack1, lookupProperty = container.lookupProperty || function(parent, propertyName) {
26+
if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
27+
return parent[propertyName];
28+
}
29+
return undefined
30+
};
31+
32+
return "I'm the base partial\n"
33+
+ ((stack1 = container.invokePartial(lookupProperty(partials,"partial/partial"),depth0,{"name":"partial/partial","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "");
34+
},"usePartial":true,"useData":true});
35+
var templates = Handlebars.templates = Handlebars.templates || {};
36+
templates['partial/base'] = template;
37+
var partials = Handlebars.partials = Handlebars.partials || {};
38+
partials['partial/base'] = template;
39+
40+
41+
// Source: src\testesources\partials\partial\partial.html
42+
43+
var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
44+
return "I'm the child partial";
45+
},"useData":true});
46+
var templates = Handlebars.templates = Handlebars.templates || {};
47+
templates['partial/partial'] = template;
48+
var partials = Handlebars.partials = Handlebars.partials || {};
49+
partials['partial/partial'] = template;
50+
51+
52+
// Source: src\testesources\partials]oot.html
53+
54+
var temp...

handlebars-maven-plugin/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@
9090
<artifactId>easymock</artifactId>
9191
<scope>test</scope>
9292
</dependency>
93+
94+
<dependency>
95+
<groupId>com.github.jknack</groupId>
96+
<artifactId>handlebars</artifactId>
97+
<version>${project.version}</version>
98+
<scope>test</scope>
99+
<classifier>tests</classifier>
100+
</dependency>
93101
</dependencies>
94102

95103
<build>

handlebars-maven-plugin/src/main/java/com/github/jknack/handlebars/maven/PrecompilePlugin.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ protected void doExecute() throws Exception {
230230
.setHash(hash)
231231
.build();
232232

233-
writer.append("// Source: ").append(file.getPath()).append("\n");
234233
writer.append(PrecompileHelper.INSTANCE.apply(templateName, opts).toString())
235234
.append("\n\n");
236235
}

handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/I18nJsPluginTest.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ public void i18nJsNoMergeDeepPath() throws Exception {
4747

4848
plugin.execute();
4949

50-
assertEquals(FileUtils.fileRead("src/test/resources/deep.expected.js"),
51-
FileUtils.fileRead("target/deep.js"));
50+
equalsToIgnoreBlanks("src/test/resources/deep.expected.js", "target/deep.js");
5251
}
5352

5453
@Test
@@ -106,7 +105,21 @@ private MavenProject newProject(final String... classpath)
106105
* Matches on tokens and avoid errors between Java 6.x and Java 7.x.
107106
*/
108107
private Set<String> tokens(final String filename) throws IOException {
109-
String content = FileUtils.fileRead(filename);
108+
String content = FileUtils.fileRead(filename)
109+
.replace("\r", "")
110+
.replace("\t", " ");
110111
return Sets.newLinkedHashSet(Splitter.on(Pattern.compile("\\s|,")).split(content));
111112
}
113+
114+
private void equalsToIgnoreBlanks(String expected, String found) throws IOException {
115+
assertEquals(replaceWhiteCharsWithSpace(FileUtils.fileRead(expected)),
116+
replaceWhiteCharsWithSpace(FileUtils.fileRead(found)));
117+
}
118+
119+
private String replaceWhiteCharsWithSpace(String content) {
120+
return content
121+
.replace("\r", "")
122+
.replace("\t", " ")
123+
.trim();
124+
}
112125
}

handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue230.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import static org.easymock.EasyMock.replay;
66
import static org.junit.Assert.assertEquals;
77

8+
import java.io.IOException;
9+
810
import org.apache.maven.artifact.DependencyResolutionRequiredException;
911
import org.apache.maven.project.MavenProject;
1012
import org.codehaus.plexus.util.FileUtils;
@@ -27,9 +29,9 @@ public void issue230() throws Exception {
2729
" /* English (United States) */\n" +
2830
" I18n.translations = I18n.translations || {};\n" +
2931
" I18n.translations['en_US'] = {\n" +
30-
" \"pagination_top_of_page\": \"Inicio de la página\"\n" +
32+
" \"pagination_top_of_page\": \"Inicio de la pagina\"\n" +
3133
" };\n" +
32-
"})();\n", FileUtils.fileRead("target/i230.js"));
34+
"})();", replaceWhiteCharsWithSpace(FileUtils.fileRead("target/i230.js")));
3335
}
3436

3537
private MavenProject newProject(final String... classpath)
@@ -39,4 +41,11 @@ private MavenProject newProject(final String... classpath)
3941
replay(project);
4042
return project;
4143
}
44+
45+
private String replaceWhiteCharsWithSpace(String content) {
46+
return content
47+
.replace("\r", "")
48+
.replace("\t", " ")
49+
.trim();
50+
}
4251
}

handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue234.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import static org.easymock.EasyMock.replay;
66
import static org.junit.Assert.assertEquals;
77

8+
import java.io.IOException;
9+
810
import org.apache.maven.artifact.DependencyResolutionRequiredException;
911
import org.apache.maven.project.MavenProject;
1012
import org.codehaus.plexus.util.FileUtils;
@@ -28,8 +30,18 @@ public void withAmdOutput() throws Exception {
2830

2931
plugin.execute();
3032

31-
assertEquals(FileUtils.fileRead("target/issue234.js"), FileUtils.fileRead("src/test/resources/issue234.expected").trim(),
32-
FileUtils.fileRead("target/issue234.js").trim());
33+
equalsToIgnoreBlanks("src/test/resources/issue234.expected", "target/issue234.js");
34+
}
35+
36+
private void equalsToIgnoreBlanks(String expected, String found) throws IOException {
37+
assertEquals(replaceWhiteCharsWithSpace(FileUtils.fileRead(expected)),
38+
replaceWhiteCharsWithSpace(FileUtils.fileRead(found)));
39+
}
40+
41+
private String replaceWhiteCharsWithSpace(String content) {
42+
return content.trim()
43+
.replace("\r", "")
44+
.replace("\t", " ");
3345
}
3446

3547
private MavenProject newProject(final String... classpath)

0 commit comments

Comments
 (0)