Skip to content

Commit

Permalink
add a git submodule with mustache specs jknack#112
Browse files Browse the repository at this point in the history
  • Loading branch information
jknack committed Jan 4, 2013
1 parent ff97916 commit a968e34
Show file tree
Hide file tree
Showing 28 changed files with 62 additions and 1,257 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "handlebars/src/test/resources/mustache"]
path = handlebars/src/test/resources/mustache
url = https://github.com/mustache/spec.git
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@
import java.util.Map;
import java.util.Map.Entry;

import org.junit.runners.Parameterized.Parameters;
import mustache.specs.Spec;
import mustache.specs.SpecTest;

import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.Helper;
import com.github.jknack.handlebars.Options;
import org.junit.runners.Parameterized.Parameters;

import specs.Spec;
import specs.SpecTest;

public class HelpersTest extends SpecTest {

Expand Down Expand Up @@ -108,7 +105,7 @@ public CharSequence apply(final String text,
}

@Parameters
public static Collection<Object[]> data() {
public static Collection<Object[]> data() throws IOException {
return data(HelpersTest.class, "helpers.yml");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
*/
package com.github.jknack.handlebars.custom;

import java.io.IOException;
import java.util.Collection;

import mustache.specs.Spec;
import mustache.specs.SpecTest;

import org.junit.runners.Parameterized.Parameters;

import specs.Spec;
import specs.SpecTest;

public class CustomObjectTest extends SpecTest {

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

@Parameters
public static Collection<Object[]> data() {
public static Collection<Object[]> data() throws IOException {
return data(CustomObjectTest.class, "customObjects.yml");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.junit.Test;

import com.github.jknack.handlebars.TemplateLoader;
import com.github.jknack.handlebars.io.ClassTemplateLoader;

/**
* Unit test for {@link ClassTemplateLoader}.
Expand All @@ -48,15 +47,15 @@ public void locate() throws IOException {
public void subFolder() throws IOException {
TemplateLoader locator = new ClassTemplateLoader();
locator.setSuffix(".yml");
Reader reader = locator.load(URI.create("specs/comments"));
Reader reader = locator.load(URI.create("mustache/specs/comments"));
assertNotNull(reader);
}

@Test
public void subFolderwithDashAtBeginning() throws IOException {
TemplateLoader locator = new ClassTemplateLoader();
locator.setSuffix(".yml");
Reader reader = locator.load(URI.create("/specs/comments"));
Reader reader = locator.load(URI.create("/mustache/specs/comments"));
assertNotNull(reader);
}

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

@Test
public void setBasePath() throws IOException {
TemplateLoader locator = new ClassTemplateLoader("/specs", ".yml");
TemplateLoader locator = new ClassTemplateLoader("/mustache/specs", ".yml");
Reader reader = locator.load(URI.create("comments"));
assertNotNull(reader);
}

@Test
public void setBasePathWithDashDash() throws IOException {
TemplateLoader locator = new ClassTemplateLoader("/specs/", ".yml");
TemplateLoader locator = new ClassTemplateLoader("/mustache/specs/", ".yml");
Reader reader = locator.load(URI.create("comments"));
assertNotNull(reader);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import org.junit.Test;

import com.github.jknack.handlebars.TemplateLoader;
import com.github.jknack.handlebars.io.ClassTemplateLoader;
import com.github.jknack.handlebars.io.FileTemplateLoader;

/**
* Unit test for {@link ClassTemplateLoader}.
Expand All @@ -51,15 +49,15 @@ public void locate() throws IOException {
public void subFolder() throws IOException {
TemplateLoader locator =
new FileTemplateLoader(new File("src/test/resources"), ".yml");
Reader reader = locator.load(URI.create("specs/comments"));
Reader reader = locator.load(URI.create("mustache/specs/comments"));
assertNotNull(reader);
}

@Test
public void subFolderwithDashAtBeginning() throws IOException {
TemplateLoader locator =
new FileTemplateLoader(new File("src/test/resources"), ".yml");
Reader reader = locator.load(URI.create("/specs/comments"));
Reader reader = locator.load(URI.create("mustache/specs/comments"));
assertNotNull(reader);
}

Expand All @@ -73,15 +71,15 @@ public void failLocate() throws IOException {
@Test
public void setBasePath() throws IOException {
TemplateLoader locator =
new FileTemplateLoader(new File("src/test/resources/specs"), ".yml");
new FileTemplateLoader(new File("src/test/resources/mustache/specs"), ".yml");
Reader reader = locator.load(URI.create("comments"));
assertNotNull(reader);
}

@Test
public void setBasePathWithDash() throws IOException {
TemplateLoader locator =
new FileTemplateLoader(new File("src/test/resources/specs/"), ".yml");
new FileTemplateLoader(new File("src/test/resources/mustache/specs/"), ".yml");
Reader reader = locator.load(URI.create("comments"));
assertNotNull(reader);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* Handlebars.js Spec Tests
* See https://github.com/wycats/handlebars.js/blob/master/spec/qunit_spec.js
*/
*/
package hbs.js;
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package specs;
package mustache.specs;

import java.io.IOException;
import java.util.Collection;

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

@Parameters
public static Collection<Object[]> data() {
public static Collection<Object[]> data() throws IOException {
return data("comments.yml");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package specs;
package mustache.specs;

import java.io.IOException;
import java.util.Collection;

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

@Parameters
public static Collection<Object[]> data() {
public static Collection<Object[]> data() throws IOException {
return data("delimiters.yml");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package specs;
package mustache.specs;

import java.io.IOException;
import java.util.Collection;

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

@Parameters
public static Collection<Object[]> data() {
public static Collection<Object[]> data() throws IOException {
return data("interpolation.yml");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package specs;
package mustache.specs;

import java.io.IOException;
import java.util.Collection;

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

@Parameters
public static Collection<Object[]> data() {
public static Collection<Object[]> data() throws IOException {
return data("inverted.yml");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package specs;
package mustache.specs;

import java.io.IOException;
import java.util.Collection;
Expand Down Expand Up @@ -144,7 +144,7 @@ public Object apply(final Object scope, final Template template)
}

@Parameters
public static Collection<Object[]> data() {
return data("lambdas.yml");
public static Collection<Object[]> data() throws IOException {
return data("~lambdas.yml");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package specs;
package mustache.specs;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -61,7 +62,7 @@ protected Handlebars configure(final Handlebars handlebars) {
}

@Parameters
public static Collection<Object[]> data() {
public static Collection<Object[]> data() throws IOException {
return data("partials.yml");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package specs;
package mustache.specs;

import java.io.IOException;
import java.util.Collection;

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

@Parameters
public static Collection<Object[]> data() {
public static Collection<Object[]> data() throws IOException {
return data("sections.yml");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package specs;
package mustache.specs;

import org.junit.internal.AssumptionViolatedException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package specs;
package mustache.specs;

import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package specs;
package mustache.specs;

import java.io.IOException;
import java.io.Reader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package specs;
package mustache.specs;

import java.lang.reflect.Method;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package specs;
package mustache.specs;

import static org.junit.Assert.assertEquals;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.ComparisonFailure;
import org.junit.Test;
Expand Down Expand Up @@ -82,7 +84,7 @@ public void run() throws HandlebarsException, IOException {
}
}

public static Collection<Object[]> data(final String filename) {
public static Collection<Object[]> data(final String filename) throws IOException {
return data(SpecTest.class, filename);
}

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

@SuppressWarnings("unchecked")
public static Collection<Object[]> data(final Class<?> loader,
final String filename) {
final String filename) throws IOException {
Constructor constructor = new Constructor();
constructor.addTypeDescription(new TypeDescription(Blog.class, "!blog"));
constructor.addTypeDescription(new TypeDescription(Comment.class,
"!comment"));
constructor.addTypeDescription(new TypeDescription(Map.class,
"!code"));

Yaml yaml = new Yaml(constructor);

String location = path(loader) + filename;
Map<String, Object> data =
(Map<String, Object>) yaml.load(
SpecTest.class.getResourceAsStream(location));
String input = FileUtils.readFileToString(new File("src/test/resources", location));
Map<String, Object> data = (Map<String, Object>) yaml.load(input);
List<Map<String, Object>> tests =
(List<Map<String, Object>>) data.get("tests");
int number = 0;
Collection<Object[]> dataset = new ArrayList<Object[]>();
for (Map<String, Object> test : tests) {
test.put("number", number++);
dataset.add(new Object[] {new Spec(test) });
dataset.add(new Object[]{new Spec(test) });
}
return dataset;
}
Expand Down Expand Up @@ -153,7 +156,7 @@ private void run(final Spec spec) throws IOException {
assertEquals(expected, output);
report.append("OUTPUT:");
report.append(output);
} catch(HandlebarsException ex) {
} catch (HandlebarsException ex) {
Handlebars.error(ex.getMessage());
} catch (ComparisonFailure ex) {
report.append("FOUND:");
Expand Down
Loading

0 comments on commit a968e34

Please sign in to comment.