Skip to content

Commit

Permalink
Adds mustache tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aymerick committed May 21, 2015
1 parent 1a9eb74 commit 2ec4824
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "mustache"]
path = mustache
url = git://github.com/mustache/spec.git
1 change: 1 addition & 0 deletions mustache
Submodule mustache added at 83b072
79 changes: 79 additions & 0 deletions mustache_test.go
Original file line number Diff line number Diff line change
@@ -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"))
// }

0 comments on commit 2ec4824

Please sign in to comment.