Skip to content

Commit

Permalink
build: attempt to fix windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
jknack committed Sep 27, 2021
1 parent 6a4ab57 commit 3651d7f
Show file tree
Hide file tree
Showing 18 changed files with 290 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
*/
package com.github.jknack.handlebars;

import static org.junit.Assert.assertEquals;
import static com.github.jknack.handlebars.IgnoreWindowsLineMatcher.equalsToStringIgnoringWindowsNewLine;
import static org.hamcrest.MatcherAssert.assertThat;

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

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

CharSequence result = template.apply(new Blog("First Post", "..."));

assertEquals("{\"title\":\"First Post\",\"body\":\"...\",\"comments\":[]}",
result);
assertThat(template.apply(new Blog("First Post", "...")), equalsToStringIgnoringWindowsNewLine(
"{\"title\":\"First Post\",\"body\":\"...\",\"comments\":[]}"));
}

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

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

CharSequence result = template.apply(new Blog("First Post", "..."));

assertEquals("{\n" +
" \"title\" : \"First Post\",\n" +
" \"body\" : \"...\",\n" +
" \"comments\" : [ ]\n" +
"}",
result);
assertThat(template.apply(new Blog("First Post", "...")),
equalsToStringIgnoringWindowsNewLine("{\n" +
" \"title\" : \"First Post\",\n" +
" \"body\" : \"...\",\n" +
" \"comments\" : [ ]\n" +
"}"));
}

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

Template template =
handlebars
.compileInline("{{@json this view=\"com.github.jknack.handlebars.Blog$Views$Public\"}}");

CharSequence result = template.apply(new Blog("First Post", "..."));
.compileInline(
"{{@json this view=\"com.github.jknack.handlebars.Blog$Views$Public\"}}");

assertEquals("{\"title\":\"First Post\",\"body\":\"...\",\"comments\":[]}",
result);
assertThat(template.apply(new Blog("First Post", "...")),
equalsToStringIgnoringWindowsNewLine(
"{\"title\":\"First Post\",\"body\":\"...\",\"comments\":[]}"));
}

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

Template template =
handlebars
.compileInline("{{@json this view=\"com.github.jknack.handlebars.Blog$Views$Public\"}}");
.compileInline(
"{{@json this view=\"com.github.jknack.handlebars.Blog$Views$Public\"}}");

CharSequence result = template.apply(new Blog("First Post", "..."));

assertEquals("{\"title\":\"First Post\"}", result);
assertThat(template.apply(new Blog("First Post", "...")),
equalsToStringIgnoringWindowsNewLine("{\"title\":\"First Post\"}"));
}

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

CharSequence result = template.apply(new Blog("First Post", "..."));

assertEquals("{\"title\":\"First Post\"}", result);
assertThat(template.apply(new Blog("First Post", "...")),
equalsToStringIgnoringWindowsNewLine("{\"title\":\"First Post\"}"));
}

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

CharSequence result = template.apply(new Blog("First Post", "..."));

assertEquals("{\"title\":\"First Post\"}", result);
assertThat(template.apply(new Blog("First Post", "...")),
equalsToStringIgnoringWindowsNewLine("{\"title\":\"First Post\"}"));
}

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

assertEquals("{\"script\":\"<script text=\\\"text/javascript\\\"></script>\"}", handlebars
.compileInline("{{@json this}}").apply(model));
assertThat(handlebars
.compileInline("{{@json this}}").apply(model), equalsToStringIgnoringWindowsNewLine(
"{\"script\":\"<script text=\\\"text/javascript\\\"></script>\"}"));

assertEquals(
"{\"script\":\"\\u003Cscript text=\\\"text/javascript\\\"\\u003E\\u003C/script\\u003E\"}",
handlebars.compileInline("{{@json this escapeHTML=true}}").apply(model));
assertThat(handlebars.compileInline("{{@json this escapeHTML=true}}").apply(model),
equalsToStringIgnoringWindowsNewLine(
"{\"script\":\"\\u003Cscript text=\\\"text/javascript\\\"\\u003E\\u003C/script\\u003E\"}"));
}
}
54 changes: 54 additions & 0 deletions handlebars-maven-plugin/a.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
... () {
// Source: src[/test/resources/partials/level1/level1.html

var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
var helper, lookupProperty = container.lookupProperty || function(parent, propertyName) {
if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
return parent[propertyName];
}
return undefined
};

return "<h1>I'm "
+ 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)))
+ "</h1>";
},"useData":true});
var templates = Handlebars.templates = Handlebars.templates || {};
templates['level1/level1'] = template;
var partials = Handlebars.partials = Handlebars.partials || {};
partials['level1/level1'] = template;


// Source: src/test/resources/partials/partial/base.html

var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
var stack1, lookupProperty = container.lookupProperty || function(parent, propertyName) {
if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
return parent[propertyName];
}
return undefined
};

return "I'm the base partial\n"
+ ((stack1 = container.invokePartial(lookupProperty(partials,"partial/partial"),depth0,{"name":"partial/partial","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "");
},"usePartial":true,"useData":true});
var templates = Handlebars.templates = Handlebars.templates || {};
templates['partial/base'] = template;
var partials = Handlebars.partials = Handlebars.partials || {};
partials['partial/base'] = template;


// Source: src/test/resources/partials/partial/partial.html

var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
return "I'm the child partial";
},"useData":true});
var templates = Handlebars.templates = Handlebars.templates || {};
templates['partial/partial'] = template;
var partials = Handlebars.partials = Handlebars.partials || {};
partials['partial/partial'] = template;


// Source: src/test/resources/partials/r]oot.html

var temp...
54 changes: 54 additions & 0 deletions handlebars-maven-plugin/b.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
... () {
// Source: src[\testesources\partials\level1\level1.html

var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
var helper, lookupProperty = container.lookupProperty || function(parent, propertyName) {
if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
return parent[propertyName];
}
return undefined
};

return "<h1>I'm "
+ 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)))
+ "</h1>";
},"useData":true});
var templates = Handlebars.templates = Handlebars.templates || {};
templates['level1/level1'] = template;
var partials = Handlebars.partials = Handlebars.partials || {};
partials['level1/level1'] = template;


// Source: src\testesources\partials\partial\base.html

var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
var stack1, lookupProperty = container.lookupProperty || function(parent, propertyName) {
if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
return parent[propertyName];
}
return undefined
};

return "I'm the base partial\n"
+ ((stack1 = container.invokePartial(lookupProperty(partials,"partial/partial"),depth0,{"name":"partial/partial","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "");
},"usePartial":true,"useData":true});
var templates = Handlebars.templates = Handlebars.templates || {};
templates['partial/base'] = template;
var partials = Handlebars.partials = Handlebars.partials || {};
partials['partial/base'] = template;


// Source: src\testesources\partials\partial\partial.html

var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
return "I'm the child partial";
},"useData":true});
var templates = Handlebars.templates = Handlebars.templates || {};
templates['partial/partial'] = template;
var partials = Handlebars.partials = Handlebars.partials || {};
partials['partial/partial'] = template;


// Source: src\testesources\partials]oot.html

var temp...
8 changes: 8 additions & 0 deletions handlebars-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@
<artifactId>easymock</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.github.jknack</groupId>
<artifactId>handlebars</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<classifier>tests</classifier>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ protected void doExecute() throws Exception {
.setHash(hash)
.build();

writer.append("// Source: ").append(file.getPath()).append("\n");
writer.append(PrecompileHelper.INSTANCE.apply(templateName, opts).toString())
.append("\n\n");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public void i18nJsNoMergeDeepPath() throws Exception {

plugin.execute();

assertEquals(FileUtils.fileRead("src/test/resources/deep.expected.js"),
FileUtils.fileRead("target/deep.js"));
equalsToIgnoreBlanks("src/test/resources/deep.expected.js", "target/deep.js");
}

@Test
Expand Down Expand Up @@ -106,7 +105,21 @@ private MavenProject newProject(final String... classpath)
* Matches on tokens and avoid errors between Java 6.x and Java 7.x.
*/
private Set<String> tokens(final String filename) throws IOException {
String content = FileUtils.fileRead(filename);
String content = FileUtils.fileRead(filename)
.replace("\r", "")
.replace("\t", " ");
return Sets.newLinkedHashSet(Splitter.on(Pattern.compile("\\s|,")).split(content));
}

private void equalsToIgnoreBlanks(String expected, String found) throws IOException {
assertEquals(replaceWhiteCharsWithSpace(FileUtils.fileRead(expected)),
replaceWhiteCharsWithSpace(FileUtils.fileRead(found)));
}

private String replaceWhiteCharsWithSpace(String content) {
return content
.replace("\r", "")
.replace("\t", " ")
.trim();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import static org.easymock.EasyMock.replay;
import static org.junit.Assert.assertEquals;

import java.io.IOException;

import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.FileUtils;
Expand All @@ -27,9 +29,9 @@ public void issue230() throws Exception {
" /* English (United States) */\n" +
" I18n.translations = I18n.translations || {};\n" +
" I18n.translations['en_US'] = {\n" +
" \"pagination_top_of_page\": \"Inicio de la página\"\n" +
" \"pagination_top_of_page\": \"Inicio de la pagina\"\n" +
" };\n" +
"})();\n", FileUtils.fileRead("target/i230.js"));
"})();", replaceWhiteCharsWithSpace(FileUtils.fileRead("target/i230.js")));
}

private MavenProject newProject(final String... classpath)
Expand All @@ -39,4 +41,11 @@ private MavenProject newProject(final String... classpath)
replay(project);
return project;
}

private String replaceWhiteCharsWithSpace(String content) {
return content
.replace("\r", "")
.replace("\t", " ")
.trim();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import static org.easymock.EasyMock.replay;
import static org.junit.Assert.assertEquals;

import java.io.IOException;

import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.FileUtils;
Expand All @@ -28,8 +30,18 @@ public void withAmdOutput() throws Exception {

plugin.execute();

assertEquals(FileUtils.fileRead("target/issue234.js"), FileUtils.fileRead("src/test/resources/issue234.expected").trim(),
FileUtils.fileRead("target/issue234.js").trim());
equalsToIgnoreBlanks("src/test/resources/issue234.expected", "target/issue234.js");
}

private void equalsToIgnoreBlanks(String expected, String found) throws IOException {
assertEquals(replaceWhiteCharsWithSpace(FileUtils.fileRead(expected)),
replaceWhiteCharsWithSpace(FileUtils.fileRead(found)));
}

private String replaceWhiteCharsWithSpace(String content) {
return content.trim()
.replace("\r", "")
.replace("\t", " ");
}

private MavenProject newProject(final String... classpath)
Expand Down
Loading

0 comments on commit 3651d7f

Please sign in to comment.