Skip to content

Commit a968e34

Browse files
committed
add a git submodule with mustache specs #112
1 parent ff97916 commit a968e34

28 files changed

+62
-1257
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "handlebars/src/test/resources/mustache"]
2+
path = handlebars/src/test/resources/mustache
3+
url = https://github.com/mustache/spec.git

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

+4-7
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@
2323
import java.util.Map;
2424
import java.util.Map.Entry;
2525

26-
import org.junit.runners.Parameterized.Parameters;
26+
import mustache.specs.Spec;
27+
import mustache.specs.SpecTest;
2728

28-
import com.github.jknack.handlebars.Handlebars;
29-
import com.github.jknack.handlebars.Helper;
30-
import com.github.jknack.handlebars.Options;
29+
import org.junit.runners.Parameterized.Parameters;
3130

32-
import specs.Spec;
33-
import specs.SpecTest;
3431

3532
public class HelpersTest extends SpecTest {
3633

@@ -108,7 +105,7 @@ public CharSequence apply(final String text,
108105
}
109106

110107
@Parameters
111-
public static Collection<Object[]> data() {
108+
public static Collection<Object[]> data() throws IOException {
112109
return data(HelpersTest.class, "helpers.yml");
113110
}
114111
}

handlebars/src/test/java/com/github/jknack/handlebars/custom/CustomObjectTest.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
*/
1818
package com.github.jknack.handlebars.custom;
1919

20+
import java.io.IOException;
2021
import java.util.Collection;
2122

23+
import mustache.specs.Spec;
24+
import mustache.specs.SpecTest;
25+
2226
import org.junit.runners.Parameterized.Parameters;
2327

24-
import specs.Spec;
25-
import specs.SpecTest;
2628

2729
public class CustomObjectTest extends SpecTest {
2830

@@ -31,7 +33,7 @@ public CustomObjectTest(final Spec spec) {
3133
}
3234

3335
@Parameters
34-
public static Collection<Object[]> data() {
36+
public static Collection<Object[]> data() throws IOException {
3537
return data(CustomObjectTest.class, "customObjects.yml");
3638
}
3739

handlebars/src/test/java/com/github/jknack/handlebars/io/ClasspathLocatorTest.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.junit.Test;
2828

2929
import com.github.jknack.handlebars.TemplateLoader;
30-
import com.github.jknack.handlebars.io.ClassTemplateLoader;
3130

3231
/**
3332
* Unit test for {@link ClassTemplateLoader}.
@@ -48,15 +47,15 @@ public void locate() throws IOException {
4847
public void subFolder() throws IOException {
4948
TemplateLoader locator = new ClassTemplateLoader();
5049
locator.setSuffix(".yml");
51-
Reader reader = locator.load(URI.create("specs/comments"));
50+
Reader reader = locator.load(URI.create("mustache/specs/comments"));
5251
assertNotNull(reader);
5352
}
5453

5554
@Test
5655
public void subFolderwithDashAtBeginning() throws IOException {
5756
TemplateLoader locator = new ClassTemplateLoader();
5857
locator.setSuffix(".yml");
59-
Reader reader = locator.load(URI.create("/specs/comments"));
58+
Reader reader = locator.load(URI.create("/mustache/specs/comments"));
6059
assertNotNull(reader);
6160
}
6261

@@ -68,14 +67,14 @@ public void failLocate() throws IOException {
6867

6968
@Test
7069
public void setBasePath() throws IOException {
71-
TemplateLoader locator = new ClassTemplateLoader("/specs", ".yml");
70+
TemplateLoader locator = new ClassTemplateLoader("/mustache/specs", ".yml");
7271
Reader reader = locator.load(URI.create("comments"));
7372
assertNotNull(reader);
7473
}
7574

7675
@Test
7776
public void setBasePathWithDashDash() throws IOException {
78-
TemplateLoader locator = new ClassTemplateLoader("/specs/", ".yml");
77+
TemplateLoader locator = new ClassTemplateLoader("/mustache/specs/", ".yml");
7978
Reader reader = locator.load(URI.create("comments"));
8079
assertNotNull(reader);
8180
}

handlebars/src/test/java/com/github/jknack/handlebars/io/FileLocatorTest.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
import org.junit.Test;
2929

3030
import com.github.jknack.handlebars.TemplateLoader;
31-
import com.github.jknack.handlebars.io.ClassTemplateLoader;
32-
import com.github.jknack.handlebars.io.FileTemplateLoader;
3331

3432
/**
3533
* Unit test for {@link ClassTemplateLoader}.
@@ -51,15 +49,15 @@ public void locate() throws IOException {
5149
public void subFolder() throws IOException {
5250
TemplateLoader locator =
5351
new FileTemplateLoader(new File("src/test/resources"), ".yml");
54-
Reader reader = locator.load(URI.create("specs/comments"));
52+
Reader reader = locator.load(URI.create("mustache/specs/comments"));
5553
assertNotNull(reader);
5654
}
5755

5856
@Test
5957
public void subFolderwithDashAtBeginning() throws IOException {
6058
TemplateLoader locator =
6159
new FileTemplateLoader(new File("src/test/resources"), ".yml");
62-
Reader reader = locator.load(URI.create("/specs/comments"));
60+
Reader reader = locator.load(URI.create("mustache/specs/comments"));
6361
assertNotNull(reader);
6462
}
6563

@@ -73,15 +71,15 @@ public void failLocate() throws IOException {
7371
@Test
7472
public void setBasePath() throws IOException {
7573
TemplateLoader locator =
76-
new FileTemplateLoader(new File("src/test/resources/specs"), ".yml");
74+
new FileTemplateLoader(new File("src/test/resources/mustache/specs"), ".yml");
7775
Reader reader = locator.load(URI.create("comments"));
7876
assertNotNull(reader);
7977
}
8078

8179
@Test
8280
public void setBasePathWithDash() throws IOException {
8381
TemplateLoader locator =
84-
new FileTemplateLoader(new File("src/test/resources/specs/"), ".yml");
82+
new FileTemplateLoader(new File("src/test/resources/mustache/specs/"), ".yml");
8583
Reader reader = locator.load(URI.create("comments"));
8684
assertNotNull(reader);
8785
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/**
22
* Handlebars.js Spec Tests
33
* See https://github.com/wycats/handlebars.js/blob/master/spec/qunit_spec.js
4-
*/
4+
*/
5+
package hbs.js;

handlebars/src/test/java/specs/CommentsTest.java handlebars/src/test/java/mustache/specs/CommentsTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
package specs;
18+
package mustache.specs;
1919

20+
import java.io.IOException;
2021
import java.util.Collection;
2122

2223
import org.junit.runners.Parameterized.Parameters;
@@ -28,7 +29,7 @@ public CommentsTest(final Spec spec) {
2829
}
2930

3031
@Parameters
31-
public static Collection<Object[]> data() {
32+
public static Collection<Object[]> data() throws IOException {
3233
return data("comments.yml");
3334
}
3435
}

handlebars/src/test/java/specs/DelimitersTest.java handlebars/src/test/java/mustache/specs/DelimitersTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
package specs;
18+
package mustache.specs;
1919

20+
import java.io.IOException;
2021
import java.util.Collection;
2122

2223
import org.junit.runners.Parameterized.Parameters;
@@ -28,7 +29,7 @@ public DelimitersTest(final Spec spec) {
2829
}
2930

3031
@Parameters
31-
public static Collection<Object[]> data() {
32+
public static Collection<Object[]> data() throws IOException {
3233
return data("delimiters.yml");
3334
}
3435

handlebars/src/test/java/specs/InterpolationTest.java handlebars/src/test/java/mustache/specs/InterpolationTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
package specs;
18+
package mustache.specs;
1919

20+
import java.io.IOException;
2021
import java.util.Collection;
2122

2223
import org.junit.runners.Parameterized.Parameters;
@@ -28,7 +29,7 @@ public InterpolationTest(final Spec spec) {
2829
}
2930

3031
@Parameters
31-
public static Collection<Object[]> data() {
32+
public static Collection<Object[]> data() throws IOException {
3233
return data("interpolation.yml");
3334
}
3435
}

handlebars/src/test/java/specs/InvertedTest.java handlebars/src/test/java/mustache/specs/InvertedTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
package specs;
18+
package mustache.specs;
1919

20+
import java.io.IOException;
2021
import java.util.Collection;
2122

2223
import org.junit.runners.Parameterized.Parameters;
@@ -28,7 +29,7 @@ public InvertedTest(final Spec spec) {
2829
}
2930

3031
@Parameters
31-
public static Collection<Object[]> data() {
32+
public static Collection<Object[]> data() throws IOException {
3233
return data("inverted.yml");
3334
}
3435
}

handlebars/src/test/java/specs/LambdasTest.java handlebars/src/test/java/mustache/specs/LambdasTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
package specs;
18+
package mustache.specs;
1919

2020
import java.io.IOException;
2121
import java.util.Collection;
@@ -144,7 +144,7 @@ public Object apply(final Object scope, final Template template)
144144
}
145145

146146
@Parameters
147-
public static Collection<Object[]> data() {
148-
return data("lambdas.yml");
147+
public static Collection<Object[]> data() throws IOException {
148+
return data("~lambdas.yml");
149149
}
150150
}

handlebars/src/test/java/specs/PartialsTest.java handlebars/src/test/java/mustache/specs/PartialsTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
package specs;
18+
package mustache.specs;
1919

20+
import java.io.IOException;
2021
import java.util.Arrays;
2122
import java.util.Collection;
2223
import java.util.List;
@@ -61,7 +62,7 @@ protected Handlebars configure(final Handlebars handlebars) {
6162
}
6263

6364
@Parameters
64-
public static Collection<Object[]> data() {
65+
public static Collection<Object[]> data() throws IOException {
6566
return data("partials.yml");
6667
}
6768
}

handlebars/src/test/java/specs/SectionsTest.java handlebars/src/test/java/mustache/specs/SectionsTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
package specs;
18+
package mustache.specs;
1919

20+
import java.io.IOException;
2021
import java.util.Collection;
2122

2223
import org.junit.runners.Parameterized.Parameters;
@@ -28,7 +29,7 @@ public SectionsTest(final Spec spec) {
2829
}
2930

3031
@Parameters
31-
public static Collection<Object[]> data() {
32+
public static Collection<Object[]> data() throws IOException {
3233
return data("sections.yml");
3334
}
3435
}

handlebars/src/test/java/specs/SkipTestException.java handlebars/src/test/java/mustache/specs/SkipTestException.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
package specs;
18+
package mustache.specs;
1919

2020
import org.junit.internal.AssumptionViolatedException;
2121

handlebars/src/test/java/specs/Spec.java handlebars/src/test/java/mustache/specs/Spec.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
package specs;
18+
package mustache.specs;
1919

2020
import java.util.Map;
2121

handlebars/src/test/java/specs/SpecResourceLocator.java handlebars/src/test/java/mustache/specs/SpecResourceLocator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
package specs;
18+
package mustache.specs;
1919

2020
import java.io.IOException;
2121
import java.io.Reader;

handlebars/src/test/java/specs/SpecRunner.java handlebars/src/test/java/mustache/specs/SpecRunner.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
package specs;
18+
package mustache.specs;
1919

2020
import java.lang.reflect.Method;
2121
import java.util.ArrayList;

handlebars/src/test/java/specs/SpecTest.java handlebars/src/test/java/mustache/specs/SpecTest.java

+11-8
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
package specs;
18+
package mustache.specs;
1919

2020
import static org.junit.Assert.assertEquals;
2121

22+
import java.io.File;
2223
import java.io.IOException;
2324
import java.net.URI;
2425
import java.util.ArrayList;
2526
import java.util.Collection;
2627
import java.util.List;
2728
import java.util.Map;
2829

30+
import org.apache.commons.io.FileUtils;
2931
import org.junit.Before;
3032
import org.junit.ComparisonFailure;
3133
import org.junit.Test;
@@ -82,7 +84,7 @@ public void run() throws HandlebarsException, IOException {
8284
}
8385
}
8486

85-
public static Collection<Object[]> data(final String filename) {
87+
public static Collection<Object[]> data(final String filename) throws IOException {
8688
return data(SpecTest.class, filename);
8789
}
8890

@@ -92,25 +94,26 @@ public static String path(final Class<?> loader) {
9294

9395
@SuppressWarnings("unchecked")
9496
public static Collection<Object[]> data(final Class<?> loader,
95-
final String filename) {
97+
final String filename) throws IOException {
9698
Constructor constructor = new Constructor();
9799
constructor.addTypeDescription(new TypeDescription(Blog.class, "!blog"));
98100
constructor.addTypeDescription(new TypeDescription(Comment.class,
99101
"!comment"));
102+
constructor.addTypeDescription(new TypeDescription(Map.class,
103+
"!code"));
100104

101105
Yaml yaml = new Yaml(constructor);
102106

103107
String location = path(loader) + filename;
104-
Map<String, Object> data =
105-
(Map<String, Object>) yaml.load(
106-
SpecTest.class.getResourceAsStream(location));
108+
String input = FileUtils.readFileToString(new File("src/test/resources", location));
109+
Map<String, Object> data = (Map<String, Object>) yaml.load(input);
107110
List<Map<String, Object>> tests =
108111
(List<Map<String, Object>>) data.get("tests");
109112
int number = 0;
110113
Collection<Object[]> dataset = new ArrayList<Object[]>();
111114
for (Map<String, Object> test : tests) {
112115
test.put("number", number++);
113-
dataset.add(new Object[] {new Spec(test) });
116+
dataset.add(new Object[]{new Spec(test) });
114117
}
115118
return dataset;
116119
}
@@ -153,7 +156,7 @@ private void run(final Spec spec) throws IOException {
153156
assertEquals(expected, output);
154157
report.append("OUTPUT:");
155158
report.append(output);
156-
} catch(HandlebarsException ex) {
159+
} catch (HandlebarsException ex) {
157160
Handlebars.error(ex.getMessage());
158161
} catch (ComparisonFailure ex) {
159162
report.append("FOUND:");

0 commit comments

Comments
 (0)