diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..a757998 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "mustache"] + path = mustache + url = git://github.com/mustache/spec.git diff --git a/mustache b/mustache new file mode 160000 index 0000000..83b0721 --- /dev/null +++ b/mustache @@ -0,0 +1 @@ +Subproject commit 83b0721610a4e11832e83df19c73ace3289972b9 diff --git a/mustache_test.go b/mustache_test.go new file mode 100644 index 0000000..f2010f7 --- /dev/null +++ b/mustache_test.go @@ -0,0 +1,79 @@ +package raymond + +import ( + "io/ioutil" + "path" + "testing" + + "gopkg.in/yaml.v2" +) + +// @todo Replace that by adding yaml tags in raymondTest struct +type mustacheTest struct { + Name string + Desc string + Data interface{} + Template string + Expected string + Partials map[string]string +} + +type mustacheTestFile struct { + Overview string + Tests []mustacheTest +} + +func testsFromMustacheFile(fileName string) []raymondTest { + result := []raymondTest{} + + fileData, err := ioutil.ReadFile(path.Join("mustache", "specs", fileName)) + if err != nil { + panic(err) + } + + var testFile mustacheTestFile + if err := yaml.Unmarshal(fileData, &testFile); err != nil { + panic(err) + } + + for _, mustacheTest := range testFile.Tests { + test := raymondTest{ + name: mustacheTest.Name, + input: mustacheTest.Template, + data: mustacheTest.Data, + output: mustacheTest.Expected, + } + + result = append(result, test) + } + + return result +} + +func TestMustacheComments(t *testing.T) { + launchRaymondTests(t, testsFromMustacheFile("comments.yml")) +} + +func TestMustacheDelimiters(t *testing.T) { + launchRaymondTests(t, testsFromMustacheFile("delimiters.yml")) +} + +func TestMustacheInterpolation(t *testing.T) { + launchRaymondTests(t, testsFromMustacheFile("interpolation.yml")) +} + +func TestMustacheInverted(t *testing.T) { + launchRaymondTests(t, testsFromMustacheFile("inverted.yml")) +} + +// func TestMustachePartials(t *testing.T) { +// launchRaymondTests(t, testsFromMustacheFile("partials.yml")) +// } + +func TestMustacheSections(t *testing.T) { + launchRaymondTests(t, testsFromMustacheFile("sections.yml")) +} + +// func TestMustacheLambdas(t *testing.T) { +// launchRaymondTests(t, testsFromMustacheFile("~lambdas.yml")) +// }