mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-06-19 14:43:05 -03:00
content generator
This commit is contained in:
@ -20,16 +20,30 @@ const (
|
||||
languagesTestTmplPath = "test_files/languages.test.tmpl"
|
||||
languagesTestTmplName = "languages.test.tmpl"
|
||||
commitLangTest = "fe8b44ab8a225b1ffa75b983b916ea22fee5b6f7"
|
||||
|
||||
// Heuristics test
|
||||
heuristicsTestFile = "test_files/heuristics.test.rb"
|
||||
contentGold = "test_files/content.gold"
|
||||
contentTestTmplPath = "test_files/content.test.go.tmpl"
|
||||
contentTestTmplName = "content.test.go.tmpl"
|
||||
commitHeuristicsTest = "fe8b44ab8a225b1ffa75b983b916ea22fee5b6f7"
|
||||
)
|
||||
|
||||
func TestFromFile(t *testing.T) {
|
||||
goldLang, err := ioutil.ReadFile(formatedLangGold)
|
||||
assert.NoError(t, err)
|
||||
|
||||
goldContent, err := ioutil.ReadFile(formatedContentGold)
|
||||
assert.NoError(t, err)
|
||||
|
||||
outPathLang, err := ioutil.TempFile("/tmp", "generator-test-")
|
||||
assert.NoError(t, err)
|
||||
defer os.Remove(outPathLang.Name())
|
||||
|
||||
outPathContent, err := ioutil.TempFile("/tmp", "generator-test-")
|
||||
assert.NoError(t, err)
|
||||
defer os.Remove(outPathContent.Name())
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
fileToParse string
|
||||
@ -50,6 +64,16 @@ func TestFromFile(t *testing.T) {
|
||||
generate: Languages,
|
||||
wantOut: goldLang,
|
||||
},
|
||||
{
|
||||
name: "TestFromFile_Heuristics",
|
||||
fileToParse: heuristicsTestFile,
|
||||
outPath: outPathContent.Name(),
|
||||
tmplPath: contentTestTmplPath,
|
||||
tmplName: contentTestTmplName,
|
||||
commit: commitHeuristicsTest,
|
||||
generate: Heuristics,
|
||||
wantOut: goldContent,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
@ -96,3 +120,37 @@ func TestLanguages(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestHeuristics(t *testing.T) {
|
||||
gold, err := ioutil.ReadFile(contentGold)
|
||||
assert.NoError(t, err)
|
||||
|
||||
input, err := ioutil.ReadFile(heuristicsTestFile)
|
||||
assert.NoError(t, err)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
input []byte
|
||||
tmplPath string
|
||||
tmplName string
|
||||
commit string
|
||||
wantOut []byte
|
||||
}{
|
||||
{
|
||||
name: "TestHeuristics",
|
||||
input: input,
|
||||
tmplPath: contentTestTmplPath,
|
||||
tmplName: contentTestTmplName,
|
||||
commit: commitHeuristicsTest,
|
||||
wantOut: gold,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
out, err := Heuristics(tt.input, tt.tmplPath, tt.tmplName, tt.commit)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, tt.wantOut, out, fmt.Sprintf("Heuristics() = %v, want %v", string(out), string(tt.wantOut)))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user