Merge pull request #49 from mcarmonaa/fix-tests
fixed linguist's commit which is used by tests
This commit is contained in:
commit
804bf53f4a
8
commit.go
Normal file
8
commit.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package enry
|
||||||
|
|
||||||
|
// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator
|
||||||
|
// THIS FILE SHOULD NOT BE EDITED BY HAND
|
||||||
|
// Extracted from github/linguist commit: b6460f8ed6b249281ada099ca28bd8f1230b8892
|
||||||
|
|
||||||
|
// linguist's commit from which files were generated.
|
||||||
|
var linguistCommit = "b6460f8ed6b249281ada099ca28bd8f1230b8892"
|
16
common.go
16
common.go
@ -125,7 +125,7 @@ func GetLanguages(filename string, content []byte) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetLanguagesByModeline returns a slice of possible languages for the given content, filename will be ignored.
|
// GetLanguagesByModeline returns a slice of possible languages for the given content, filename will be ignored.
|
||||||
// It is comply with the signature to be a Strategy type.
|
// It complies with the signature to be a Strategy type.
|
||||||
func GetLanguagesByModeline(filename string, content []byte, candidates []string) []string {
|
func GetLanguagesByModeline(filename string, content []byte, candidates []string) []string {
|
||||||
headFoot := getHeaderAndFooter(content)
|
headFoot := getHeaderAndFooter(content)
|
||||||
var languages []string
|
var languages []string
|
||||||
@ -185,7 +185,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// GetLanguagesByEmacsModeline returns a slice of possible languages for the given content, filename and candidates
|
// GetLanguagesByEmacsModeline returns a slice of possible languages for the given content, filename and candidates
|
||||||
// will be ignored. It is comply with the signature to be a Strategy type.
|
// will be ignored. It complies with the signature to be a Strategy type.
|
||||||
func GetLanguagesByEmacsModeline(filename string, content []byte, candidates []string) []string {
|
func GetLanguagesByEmacsModeline(filename string, content []byte, candidates []string) []string {
|
||||||
matched := reEmacsModeline.FindAllSubmatch(content, -1)
|
matched := reEmacsModeline.FindAllSubmatch(content, -1)
|
||||||
if matched == nil {
|
if matched == nil {
|
||||||
@ -211,7 +211,7 @@ func GetLanguagesByEmacsModeline(filename string, content []byte, candidates []s
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetLanguagesByVimModeline returns a slice of possible languages for the given content, filename and candidates
|
// GetLanguagesByVimModeline returns a slice of possible languages for the given content, filename and candidates
|
||||||
// will be ignored. It is comply with the signature to be a Strategy type.
|
// will be ignored. It complies with the signature to be a Strategy type.
|
||||||
func GetLanguagesByVimModeline(filename string, content []byte, candidates []string) []string {
|
func GetLanguagesByVimModeline(filename string, content []byte, candidates []string) []string {
|
||||||
matched := reVimModeline.FindAllSubmatch(content, -1)
|
matched := reVimModeline.FindAllSubmatch(content, -1)
|
||||||
if matched == nil {
|
if matched == nil {
|
||||||
@ -247,13 +247,13 @@ func GetLanguagesByVimModeline(filename string, content []byte, candidates []str
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetLanguagesByFilename returns a slice of possible languages for the given filename, content and candidates
|
// GetLanguagesByFilename returns a slice of possible languages for the given filename, content and candidates
|
||||||
// will be ignored. It is comply with the signature to be a Strategy type.
|
// will be ignored. It complies with the signature to be a Strategy type.
|
||||||
func GetLanguagesByFilename(filename string, content []byte, candidates []string) []string {
|
func GetLanguagesByFilename(filename string, content []byte, candidates []string) []string {
|
||||||
return languagesByFilename[filepath.Base(filename)]
|
return languagesByFilename[filepath.Base(filename)]
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetLanguagesByShebang returns a slice of possible languages for the given content, filename and candidates
|
// GetLanguagesByShebang returns a slice of possible languages for the given content, filename and candidates
|
||||||
// will be ignored. It is comply with the signature to be a Strategy type.
|
// will be ignored. It complies with the signature to be a Strategy type.
|
||||||
func GetLanguagesByShebang(filename string, content []byte, candidates []string) (languages []string) {
|
func GetLanguagesByShebang(filename string, content []byte, candidates []string) (languages []string) {
|
||||||
interpreter := getInterpreter(content)
|
interpreter := getInterpreter(content)
|
||||||
return languagesByInterpreter[interpreter]
|
return languagesByInterpreter[interpreter]
|
||||||
@ -333,7 +333,7 @@ func lookForMultilineExec(data []byte) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetLanguagesByExtension returns a slice of possible languages for the given filename, content and candidates
|
// GetLanguagesByExtension returns a slice of possible languages for the given filename, content and candidates
|
||||||
// will be ignored. It is comply with the signature to be a Strategy type.
|
// will be ignored. It complies with the signature to be a Strategy type.
|
||||||
func GetLanguagesByExtension(filename string, content []byte, candidates []string) []string {
|
func GetLanguagesByExtension(filename string, content []byte, candidates []string) []string {
|
||||||
if !strings.Contains(filename, ".") {
|
if !strings.Contains(filename, ".") {
|
||||||
return nil
|
return nil
|
||||||
@ -364,7 +364,7 @@ func getDotIndexes(filename string) []int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetLanguagesByContent returns a slice of possible languages for the given content, filename and candidates
|
// GetLanguagesByContent returns a slice of possible languages for the given content, filename and candidates
|
||||||
// will be ignored. It is comply with the signature to be a Strategy type.
|
// will be ignored. It complies with the signature to be a Strategy type.
|
||||||
func GetLanguagesByContent(filename string, content []byte, candidates []string) []string {
|
func GetLanguagesByContent(filename string, content []byte, candidates []string) []string {
|
||||||
ext := strings.ToLower(filepath.Ext(filename))
|
ext := strings.ToLower(filepath.Ext(filename))
|
||||||
fnMatcher, ok := contentMatchers[ext]
|
fnMatcher, ok := contentMatchers[ext]
|
||||||
@ -376,7 +376,7 @@ func GetLanguagesByContent(filename string, content []byte, candidates []string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetLanguagesByClassifier uses DefaultClassifier as a Classifier and returns a sorted slice of possible languages ordered by
|
// GetLanguagesByClassifier uses DefaultClassifier as a Classifier and returns a sorted slice of possible languages ordered by
|
||||||
// decreasing language's probability. If there are not candidates it returns nil. It is comply with the signature to be a Strategy type.
|
// decreasing language's probability. If there are not candidates it returns nil. It complies with the signature to be a Strategy type.
|
||||||
func GetLanguagesByClassifier(filename string, content []byte, candidates []string) (languages []string) {
|
func GetLanguagesByClassifier(filename string, content []byte, candidates []string) (languages []string) {
|
||||||
if len(candidates) == 0 {
|
if len(candidates) == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -11,15 +12,46 @@ import (
|
|||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SimpleLinguistTestSuite struct {
|
const linguistURL = "https://github.com/github/linguist.git"
|
||||||
|
|
||||||
|
type EnryTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
repoLinguist string
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSimpleLinguistTestSuite(t *testing.T) {
|
func TestEnryTestSuite(t *testing.T) {
|
||||||
suite.Run(t, new(SimpleLinguistTestSuite))
|
suite.Run(t, new(EnryTestSuite))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SimpleLinguistTestSuite) TestGetLanguage() {
|
func (s *EnryTestSuite) SetupSuite() {
|
||||||
|
var err error
|
||||||
|
s.repoLinguist, err = ioutil.TempDir("", "linguist-")
|
||||||
|
assert.NoError(s.T(), err)
|
||||||
|
|
||||||
|
cmd := exec.Command("git", "clone", linguistURL, s.repoLinguist)
|
||||||
|
err = cmd.Run()
|
||||||
|
assert.NoError(s.T(), err)
|
||||||
|
|
||||||
|
cwd, err := os.Getwd()
|
||||||
|
assert.NoError(s.T(), err)
|
||||||
|
|
||||||
|
err = os.Chdir(s.repoLinguist)
|
||||||
|
assert.NoError(s.T(), err)
|
||||||
|
|
||||||
|
cmd = exec.Command("git", "checkout", linguistCommit)
|
||||||
|
err = cmd.Run()
|
||||||
|
assert.NoError(s.T(), err)
|
||||||
|
|
||||||
|
err = os.Chdir(cwd)
|
||||||
|
assert.NoError(s.T(), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *EnryTestSuite) TearDownSuite() {
|
||||||
|
err := os.RemoveAll(s.repoLinguist)
|
||||||
|
assert.NoError(s.T(), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *EnryTestSuite) TestGetLanguage() {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
filename string
|
filename string
|
||||||
@ -38,7 +70,7 @@ func (s *SimpleLinguistTestSuite) TestGetLanguage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SimpleLinguistTestSuite) TestGetLanguagesByModelineLinguist() {
|
func (s *EnryTestSuite) TestGetLanguagesByModelineLinguist() {
|
||||||
const (
|
const (
|
||||||
modelinesDir = ".linguist/test/fixtures/Data/Modelines"
|
modelinesDir = ".linguist/test/fixtures/Data/Modelines"
|
||||||
samplesDir = ".linguist/samples"
|
samplesDir = ".linguist/samples"
|
||||||
@ -95,7 +127,7 @@ func (s *SimpleLinguistTestSuite) TestGetLanguagesByModelineLinguist() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SimpleLinguistTestSuite) TestGetLanguagesByModeline() {
|
func (s *EnryTestSuite) TestGetLanguagesByModeline() {
|
||||||
const (
|
const (
|
||||||
wrongVim = `# vim: set syntax=ruby ft =python filetype=perl :`
|
wrongVim = `# vim: set syntax=ruby ft =python filetype=perl :`
|
||||||
rightVim = `/* vim: set syntax=python ft =python filetype=python */`
|
rightVim = `/* vim: set syntax=python ft =python filetype=python */`
|
||||||
@ -120,7 +152,7 @@ func (s *SimpleLinguistTestSuite) TestGetLanguagesByModeline() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SimpleLinguistTestSuite) TestGetLanguagesByFilename() {
|
func (s *EnryTestSuite) TestGetLanguagesByFilename() {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
filename string
|
filename string
|
||||||
@ -144,7 +176,7 @@ func (s *SimpleLinguistTestSuite) TestGetLanguagesByFilename() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SimpleLinguistTestSuite) TestGetLanguagesByShebang() {
|
func (s *EnryTestSuite) TestGetLanguagesByShebang() {
|
||||||
const (
|
const (
|
||||||
multilineExecHack = `#!/bin/sh
|
multilineExecHack = `#!/bin/sh
|
||||||
# Next line is comment in Tcl, but not in sh... \
|
# Next line is comment in Tcl, but not in sh... \
|
||||||
@ -185,7 +217,7 @@ println("The shell script says ",vm.arglist.concat(" "));`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SimpleLinguistTestSuite) TestGetLanguagesByExtension() {
|
func (s *EnryTestSuite) TestGetLanguagesByExtension() {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
filename string
|
filename string
|
||||||
@ -204,7 +236,7 @@ func (s *SimpleLinguistTestSuite) TestGetLanguagesByExtension() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SimpleLinguistTestSuite) TestGetLanguagesByClassifier() {
|
func (s *EnryTestSuite) TestGetLanguagesByClassifier() {
|
||||||
const samples = `.linguist/samples/`
|
const samples = `.linguist/samples/`
|
||||||
test := []struct {
|
test := []struct {
|
||||||
name string
|
name string
|
||||||
@ -236,7 +268,7 @@ func (s *SimpleLinguistTestSuite) TestGetLanguagesByClassifier() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SimpleLinguistTestSuite) TestGetLanguagesBySpecificClassifier() {
|
func (s *EnryTestSuite) TestGetLanguagesBySpecificClassifier() {
|
||||||
const samples = `.linguist/samples/`
|
const samples = `.linguist/samples/`
|
||||||
test := []struct {
|
test := []struct {
|
||||||
name string
|
name string
|
||||||
@ -270,7 +302,7 @@ func (s *SimpleLinguistTestSuite) TestGetLanguagesBySpecificClassifier() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SimpleLinguistTestSuite) TestGetLanguageExtensions() {
|
func (s *EnryTestSuite) TestGetLanguageExtensions() {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
language string
|
language string
|
||||||
@ -287,7 +319,7 @@ func (s *SimpleLinguistTestSuite) TestGetLanguageExtensions() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SimpleLinguistTestSuite) TestGetLanguageType() {
|
func (s *EnryTestSuite) TestGetLanguageType() {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
language string
|
language string
|
||||||
@ -310,7 +342,7 @@ func (s *SimpleLinguistTestSuite) TestGetLanguageType() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SimpleLinguistTestSuite) TestGetLanguageByAlias() {
|
func (s *EnryTestSuite) TestGetLanguageByAlias() {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
alias string
|
alias string
|
||||||
@ -336,12 +368,9 @@ func (s *SimpleLinguistTestSuite) TestGetLanguageByAlias() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SimpleLinguistTestSuite) TestLinguistCorpus() {
|
func (s *EnryTestSuite) TestLinguistCorpus() {
|
||||||
const (
|
const filenamesDir = "filenames"
|
||||||
samplesDir = ".linguist/samples"
|
var samplesDir = filepath.Join(s.repoLinguist, "samples")
|
||||||
filenamesDir = "filenames"
|
|
||||||
)
|
|
||||||
|
|
||||||
var cornerCases = map[string]bool{
|
var cornerCases = map[string]bool{
|
||||||
"hello.ms": true,
|
"hello.ms": true,
|
||||||
}
|
}
|
||||||
|
8
internal/code-generator/assets/commit.go.tmpl
Normal file
8
internal/code-generator/assets/commit.go.tmpl
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package enry
|
||||||
|
|
||||||
|
// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator
|
||||||
|
// THIS FILE SHOULD NOT BE EDITED BY HAND
|
||||||
|
// Extracted from github/linguist commit: {{ . }}
|
||||||
|
|
||||||
|
// linguist's commit from which files were generated.
|
||||||
|
var linguistCommit = "{{- . -}}"
|
@ -10,7 +10,7 @@ import (
|
|||||||
yaml "gopkg.in/yaml.v2"
|
yaml "gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Aliases reads from fileToParse and builds source file from tmplPath. It's comply with type File signature.
|
// Aliases reads from fileToParse and builds source file from tmplPath. It complies with type File signature.
|
||||||
func Aliases(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error {
|
func Aliases(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error {
|
||||||
data, err := ioutil.ReadFile(fileToParse)
|
data, err := ioutil.ReadFile(fileToParse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
yaml "gopkg.in/yaml.v2"
|
yaml "gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Documentation reads from fileToParse and builds source file from tmplPath. It's comply with type File signature.
|
// Documentation reads from fileToParse and builds source file from tmplPath. It complies with type File signature.
|
||||||
func Documentation(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error {
|
func Documentation(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error {
|
||||||
data, err := ioutil.ReadFile(fileToParse)
|
data, err := ioutil.ReadFile(fileToParse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -15,7 +15,7 @@ type extensionsInfo struct {
|
|||||||
ExtensionsByLanguage map[string][]string
|
ExtensionsByLanguage map[string][]string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extensions reads from fileToParse and builds source file from tmplPath. It's comply with type File signature.
|
// Extensions reads from fileToParse and builds source file from tmplPath. It complies with type File signature.
|
||||||
func Extensions(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error {
|
func Extensions(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error {
|
||||||
data, err := ioutil.ReadFile(fileToParse)
|
data, err := ioutil.ReadFile(fileToParse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
yaml "gopkg.in/yaml.v2"
|
yaml "gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Filenames reads from fileToParse and builds source file from tmplPath. It's comply with type File signature.
|
// Filenames reads from fileToParse and builds source file from tmplPath. It complies with type File signature.
|
||||||
func Filenames(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error {
|
func Filenames(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error {
|
||||||
data, err := ioutil.ReadFile(fileToParse)
|
data, err := ioutil.ReadFile(fileToParse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -65,6 +65,11 @@ const (
|
|||||||
frequenciesGold = "test_files/frequencies.gold"
|
frequenciesGold = "test_files/frequencies.gold"
|
||||||
frequenciesTestTmplPath = "../assets/frequencies.go.tmpl"
|
frequenciesTestTmplPath = "../assets/frequencies.go.tmpl"
|
||||||
frequenciesTestTmplName = "frequencies.go.tmpl"
|
frequenciesTestTmplName = "frequencies.go.tmpl"
|
||||||
|
|
||||||
|
// commit test
|
||||||
|
commitGold = "test_files/commit.gold"
|
||||||
|
commitTestTmplPath = "../assets/commit.go.tmpl"
|
||||||
|
commitTestTmplName = "commit.go.tmpl"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GeneratorTestSuite struct {
|
type GeneratorTestSuite struct {
|
||||||
@ -76,35 +81,35 @@ func TestGeneratorTestSuite(t *testing.T) {
|
|||||||
suite.Run(t, new(GeneratorTestSuite))
|
suite.Run(t, new(GeneratorTestSuite))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GeneratorTestSuite) SetupSuite() {
|
func (s *GeneratorTestSuite) SetupSuite() {
|
||||||
tmpLinguist, err := ioutil.TempDir("", "linguist-")
|
var err error
|
||||||
assert.NoError(g.T(), err)
|
s.tmpLinguist, err = ioutil.TempDir("", "linguist-")
|
||||||
g.tmpLinguist = tmpLinguist
|
assert.NoError(s.T(), err)
|
||||||
|
|
||||||
cmd := exec.Command("git", "clone", lingustURL, tmpLinguist)
|
cmd := exec.Command("git", "clone", lingustURL, s.tmpLinguist)
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
assert.NoError(g.T(), err)
|
assert.NoError(s.T(), err)
|
||||||
|
|
||||||
cwd, err := os.Getwd()
|
cwd, err := os.Getwd()
|
||||||
assert.NoError(g.T(), err)
|
assert.NoError(s.T(), err)
|
||||||
|
|
||||||
err = os.Chdir(tmpLinguist)
|
err = os.Chdir(s.tmpLinguist)
|
||||||
assert.NoError(g.T(), err)
|
assert.NoError(s.T(), err)
|
||||||
|
|
||||||
cmd = exec.Command("git", "checkout", commit)
|
cmd = exec.Command("git", "checkout", commit)
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
assert.NoError(g.T(), err)
|
assert.NoError(s.T(), err)
|
||||||
|
|
||||||
err = os.Chdir(cwd)
|
err = os.Chdir(cwd)
|
||||||
assert.NoError(g.T(), err)
|
assert.NoError(s.T(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GeneratorTestSuite) TearDownSuite() {
|
func (s *GeneratorTestSuite) TearDownSuite() {
|
||||||
err := os.RemoveAll(g.tmpLinguist)
|
err := os.RemoveAll(s.tmpLinguist)
|
||||||
assert.NoError(g.T(), err)
|
assert.NoError(s.T(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GeneratorTestSuite) TestGenerationFiles() {
|
func (s *GeneratorTestSuite) TestGenerationFiles() {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
fileToParse string
|
fileToParse string
|
||||||
@ -117,7 +122,7 @@ func (g *GeneratorTestSuite) TestGenerationFiles() {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Extensions()",
|
name: "Extensions()",
|
||||||
fileToParse: filepath.Join(g.tmpLinguist, languagesFile),
|
fileToParse: filepath.Join(s.tmpLinguist, languagesFile),
|
||||||
samplesDir: "",
|
samplesDir: "",
|
||||||
tmplPath: extensionTestTmplPath,
|
tmplPath: extensionTestTmplPath,
|
||||||
tmplName: extensionTestTmplName,
|
tmplName: extensionTestTmplName,
|
||||||
@ -127,7 +132,7 @@ func (g *GeneratorTestSuite) TestGenerationFiles() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Heuristics()",
|
name: "Heuristics()",
|
||||||
fileToParse: filepath.Join(g.tmpLinguist, heuristicsTestFile),
|
fileToParse: filepath.Join(s.tmpLinguist, heuristicsTestFile),
|
||||||
samplesDir: "",
|
samplesDir: "",
|
||||||
tmplPath: contentTestTmplPath,
|
tmplPath: contentTestTmplPath,
|
||||||
tmplName: contentTestTmplName,
|
tmplName: contentTestTmplName,
|
||||||
@ -137,7 +142,7 @@ func (g *GeneratorTestSuite) TestGenerationFiles() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Vendor()",
|
name: "Vendor()",
|
||||||
fileToParse: filepath.Join(g.tmpLinguist, vendorTestFile),
|
fileToParse: filepath.Join(s.tmpLinguist, vendorTestFile),
|
||||||
samplesDir: "",
|
samplesDir: "",
|
||||||
tmplPath: vendorTestTmplPath,
|
tmplPath: vendorTestTmplPath,
|
||||||
tmplName: vendorTestTmplName,
|
tmplName: vendorTestTmplName,
|
||||||
@ -147,7 +152,7 @@ func (g *GeneratorTestSuite) TestGenerationFiles() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Documentation()",
|
name: "Documentation()",
|
||||||
fileToParse: filepath.Join(g.tmpLinguist, documentationTestFile),
|
fileToParse: filepath.Join(s.tmpLinguist, documentationTestFile),
|
||||||
samplesDir: "",
|
samplesDir: "",
|
||||||
tmplPath: documentationTestTmplPath,
|
tmplPath: documentationTestTmplPath,
|
||||||
tmplName: documentationTestTmplName,
|
tmplName: documentationTestTmplName,
|
||||||
@ -157,7 +162,7 @@ func (g *GeneratorTestSuite) TestGenerationFiles() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Types()",
|
name: "Types()",
|
||||||
fileToParse: filepath.Join(g.tmpLinguist, languagesFile),
|
fileToParse: filepath.Join(s.tmpLinguist, languagesFile),
|
||||||
samplesDir: "",
|
samplesDir: "",
|
||||||
tmplPath: typeTestTmplPath,
|
tmplPath: typeTestTmplPath,
|
||||||
tmplName: typeTestTmplName,
|
tmplName: typeTestTmplName,
|
||||||
@ -167,7 +172,7 @@ func (g *GeneratorTestSuite) TestGenerationFiles() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Interpreters()",
|
name: "Interpreters()",
|
||||||
fileToParse: filepath.Join(g.tmpLinguist, languagesFile),
|
fileToParse: filepath.Join(s.tmpLinguist, languagesFile),
|
||||||
samplesDir: "",
|
samplesDir: "",
|
||||||
tmplPath: interpreterTestTmplPath,
|
tmplPath: interpreterTestTmplPath,
|
||||||
tmplName: interpreterTestTmplName,
|
tmplName: interpreterTestTmplName,
|
||||||
@ -177,8 +182,8 @@ func (g *GeneratorTestSuite) TestGenerationFiles() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Filenames()",
|
name: "Filenames()",
|
||||||
fileToParse: filepath.Join(g.tmpLinguist, languagesFile),
|
fileToParse: filepath.Join(s.tmpLinguist, languagesFile),
|
||||||
samplesDir: filepath.Join(g.tmpLinguist, samplesDir),
|
samplesDir: filepath.Join(s.tmpLinguist, samplesDir),
|
||||||
tmplPath: filenameTestTmplPath,
|
tmplPath: filenameTestTmplPath,
|
||||||
tmplName: filenameTestTmplName,
|
tmplName: filenameTestTmplName,
|
||||||
commit: commit,
|
commit: commit,
|
||||||
@ -187,7 +192,7 @@ func (g *GeneratorTestSuite) TestGenerationFiles() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Aliases()",
|
name: "Aliases()",
|
||||||
fileToParse: filepath.Join(g.tmpLinguist, languagesFile),
|
fileToParse: filepath.Join(s.tmpLinguist, languagesFile),
|
||||||
samplesDir: "",
|
samplesDir: "",
|
||||||
tmplPath: aliasTestTmplPath,
|
tmplPath: aliasTestTmplPath,
|
||||||
tmplName: aliasTestTmplName,
|
tmplName: aliasTestTmplName,
|
||||||
@ -197,27 +202,36 @@ func (g *GeneratorTestSuite) TestGenerationFiles() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Frequencies()",
|
name: "Frequencies()",
|
||||||
samplesDir: filepath.Join(g.tmpLinguist, samplesDir),
|
samplesDir: filepath.Join(s.tmpLinguist, samplesDir),
|
||||||
tmplPath: frequenciesTestTmplPath,
|
tmplPath: frequenciesTestTmplPath,
|
||||||
tmplName: frequenciesTestTmplName,
|
tmplName: frequenciesTestTmplName,
|
||||||
commit: commit,
|
commit: commit,
|
||||||
generate: Frequencies,
|
generate: Frequencies,
|
||||||
wantOut: frequenciesGold,
|
wantOut: frequenciesGold,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Commit()",
|
||||||
|
samplesDir: "",
|
||||||
|
tmplPath: commitTestTmplPath,
|
||||||
|
tmplName: commitTestTmplName,
|
||||||
|
commit: commit,
|
||||||
|
generate: Commit,
|
||||||
|
wantOut: commitGold,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
gold, err := ioutil.ReadFile(test.wantOut)
|
gold, err := ioutil.ReadFile(test.wantOut)
|
||||||
assert.NoError(g.T(), err)
|
assert.NoError(s.T(), err)
|
||||||
|
|
||||||
outPath, err := ioutil.TempFile("/tmp", "generator-test-")
|
outPath, err := ioutil.TempFile("/tmp", "generator-test-")
|
||||||
assert.NoError(g.T(), err)
|
assert.NoError(s.T(), err)
|
||||||
defer os.Remove(outPath.Name())
|
defer os.Remove(outPath.Name())
|
||||||
|
|
||||||
err = test.generate(test.fileToParse, test.samplesDir, outPath.Name(), test.tmplPath, test.tmplName, test.commit)
|
err = test.generate(test.fileToParse, test.samplesDir, outPath.Name(), test.tmplPath, test.tmplName, test.commit)
|
||||||
assert.NoError(g.T(), err)
|
assert.NoError(s.T(), err)
|
||||||
out, err := ioutil.ReadFile(outPath.Name())
|
out, err := ioutil.ReadFile(outPath.Name())
|
||||||
assert.NoError(g.T(), err)
|
assert.NoError(s.T(), err)
|
||||||
assert.EqualValues(g.T(), gold, out, fmt.Sprintf("%v: %v, expected: %v", test.name, string(out), string(gold)))
|
assert.EqualValues(s.T(), gold, out, fmt.Sprintf("%v: %v, expected: %v", test.name, string(out), string(gold)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
"text/template"
|
"text/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Heuristics reads from fileToParse and builds source file from tmplPath. It's comply with type File signature.
|
// Heuristics reads from fileToParse and builds source file from tmplPath. It complies with type File signature.
|
||||||
func Heuristics(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error {
|
func Heuristics(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error {
|
||||||
data, err := ioutil.ReadFile(fileToParse)
|
data, err := ioutil.ReadFile(fileToParse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Interpreters reads from fileToParse and builds source file from tmplPath. It's comply with type File signature.
|
// Interpreters reads from fileToParse and builds source file from tmplPath. It complies with type File signature.
|
||||||
func Interpreters(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error {
|
func Interpreters(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error {
|
||||||
data, err := ioutil.ReadFile(fileToParse)
|
data, err := ioutil.ReadFile(fileToParse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
17
internal/code-generator/generator/linguist-commit.go
Normal file
17
internal/code-generator/generator/linguist-commit.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package generator
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"text/template"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Commit takes a commit and builds the source file from tmplPath. It complies with type File signature.
|
||||||
|
func Commit(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error {
|
||||||
|
buf := &bytes.Buffer{}
|
||||||
|
t := template.Must(template.New(tmplName).ParseFiles(tmplPath))
|
||||||
|
if err := t.Execute(buf, commit); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return formatedWrite(outPath, buf.Bytes())
|
||||||
|
}
|
@ -25,7 +25,7 @@ type samplesFrequencies struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Frequencies reads directories in samplesDir, retrieves information about frequencies of languages and tokens, and write
|
// Frequencies reads directories in samplesDir, retrieves information about frequencies of languages and tokens, and write
|
||||||
// the file outPath using tmplName as a template.
|
// the file outPath using tmplName as a template. It complies with type File signature.
|
||||||
func Frequencies(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error {
|
func Frequencies(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error {
|
||||||
freqs, err := getFrequencies(samplesDir)
|
freqs, err := getFrequencies(samplesDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
8
internal/code-generator/generator/test_files/commit.gold
Normal file
8
internal/code-generator/generator/test_files/commit.gold
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package enry
|
||||||
|
|
||||||
|
// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator
|
||||||
|
// THIS FILE SHOULD NOT BE EDITED BY HAND
|
||||||
|
// Extracted from github/linguist commit: b6460f8ed6b249281ada099ca28bd8f1230b8892
|
||||||
|
|
||||||
|
// linguist's commit from which files were generated.
|
||||||
|
var linguistCommit = "b6460f8ed6b249281ada099ca28bd8f1230b8892"
|
@ -16,7 +16,7 @@ var typeToTypeConst = map[string]string{
|
|||||||
"prose": "Prose",
|
"prose": "Prose",
|
||||||
}
|
}
|
||||||
|
|
||||||
// Types reads from fileToParse and builds source file from tmplPath. It's comply with type File signature.
|
// Types reads from fileToParse and builds source file from tmplPath. It complies with type File signature.
|
||||||
func Types(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error {
|
func Types(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error {
|
||||||
data, err := ioutil.ReadFile(fileToParse)
|
data, err := ioutil.ReadFile(fileToParse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
yaml "gopkg.in/yaml.v2"
|
yaml "gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Vendor reads from fileToParse and builds source file from tmplPath. It's comply with type File signature.
|
// Vendor reads from fileToParse and builds source file from tmplPath. It complies with type File signature.
|
||||||
func Vendor(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error {
|
func Vendor(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error {
|
||||||
data, err := ioutil.ReadFile(fileToParse)
|
data, err := ioutil.ReadFile(fileToParse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -62,6 +62,11 @@ const (
|
|||||||
frequenciesTmplPath = "internal/code-generator/assets/frequencies.go.tmpl"
|
frequenciesTmplPath = "internal/code-generator/assets/frequencies.go.tmpl"
|
||||||
frequenciesTmpl = "frequencies.go.tmpl"
|
frequenciesTmpl = "frequencies.go.tmpl"
|
||||||
|
|
||||||
|
// commit.go generation
|
||||||
|
commitFile = "commit.go"
|
||||||
|
commitTmplPath = "internal/code-generator/assets/commit.go.tmpl"
|
||||||
|
commitTmpl = "commit.go.tmpl"
|
||||||
|
|
||||||
commitPath = ".linguist/.git/HEAD"
|
commitPath = ".linguist/.git/HEAD"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -91,6 +96,7 @@ func main() {
|
|||||||
&generatorFiles{generator.Filenames, languagesYAML, samplesDir, filenamesFile, filenamesTmplPath, filenamesTmpl, commit},
|
&generatorFiles{generator.Filenames, languagesYAML, samplesDir, filenamesFile, filenamesTmplPath, filenamesTmpl, commit},
|
||||||
&generatorFiles{generator.Aliases, languagesYAML, "", aliasesFile, aliasesTmplPath, aliasesTmpl, commit},
|
&generatorFiles{generator.Aliases, languagesYAML, "", aliasesFile, aliasesTmplPath, aliasesTmpl, commit},
|
||||||
&generatorFiles{generator.Frequencies, "", samplesDir, frequenciesFile, frequenciesTmplPath, frequenciesTmpl, commit},
|
&generatorFiles{generator.Frequencies, "", samplesDir, frequenciesFile, frequenciesTmplPath, frequenciesTmpl, commit},
|
||||||
|
&generatorFiles{generator.Commit, "", "", commitFile, commitTmplPath, commitTmpl, commit},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, file := range fileList {
|
for _, file := range fileList {
|
||||||
@ -108,13 +114,11 @@ func getCommit(path string) (string, error) {
|
|||||||
|
|
||||||
if string(commit) == "ref: refs/heads/master\n" {
|
if string(commit) == "ref: refs/heads/master\n" {
|
||||||
path = ".linguist/.git/" + string(commit[5:len(commit)-1])
|
path = ".linguist/.git/" + string(commit[5:len(commit)-1])
|
||||||
commit, err := ioutil.ReadFile(path)
|
commit, err = ioutil.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return string(commit), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return string(commit), nil
|
return string(commit[:len(commit)-1]), nil
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *SimpleLinguistTestSuite) TestIsVendor() {
|
func (s *EnryTestSuite) TestIsVendor() {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
path string
|
path string
|
||||||
@ -31,7 +31,7 @@ func (s *SimpleLinguistTestSuite) TestIsVendor() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SimpleLinguistTestSuite) TestIsDocumentation() {
|
func (s *EnryTestSuite) TestIsDocumentation() {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
path string
|
path string
|
||||||
@ -47,7 +47,7 @@ func (s *SimpleLinguistTestSuite) TestIsDocumentation() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SimpleLinguistTestSuite) TestIsConfiguration() {
|
func (s *EnryTestSuite) TestIsConfiguration() {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
path string
|
path string
|
||||||
@ -64,7 +64,7 @@ func (s *SimpleLinguistTestSuite) TestIsConfiguration() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SimpleLinguistTestSuite) TestIsBinary() {
|
func (s *EnryTestSuite) TestIsBinary() {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
data []byte
|
data []byte
|
||||||
|
Loading…
Reference in New Issue
Block a user