From 63d4d9bf2420fcacee79028214a445bbd39523b6 Mon Sep 17 00:00:00 2001 From: Manuel Carmona Date: Thu, 20 Apr 2017 08:12:56 +0200 Subject: [PATCH] removed templates from test_files directory to use templates from assets directory in tests --- .../code-generator/generator/documentation.go | 2 +- .../generator/generator_test.go | 28 +++++----- .../generator/test_files/content.test.go.tmpl | 51 ------------------- .../test_files/documentation.test.go.tmpl | 13 ----- .../test_files/extensions.test.go.tmpl | 11 ---- .../test_files/filenames.test.go.tmpl | 11 ---- .../test_files/interpreters.test.go.tmpl | 11 ---- .../generator/test_files/vendor.test.go.tmpl | 13 ----- 8 files changed, 15 insertions(+), 125 deletions(-) delete mode 100644 internal/code-generator/generator/test_files/content.test.go.tmpl delete mode 100644 internal/code-generator/generator/test_files/documentation.test.go.tmpl delete mode 100644 internal/code-generator/generator/test_files/extensions.test.go.tmpl delete mode 100644 internal/code-generator/generator/test_files/filenames.test.go.tmpl delete mode 100644 internal/code-generator/generator/test_files/interpreters.test.go.tmpl delete mode 100644 internal/code-generator/generator/test_files/vendor.test.go.tmpl diff --git a/internal/code-generator/generator/documentation.go b/internal/code-generator/generator/documentation.go index b5a4bd9..9d87ac2 100644 --- a/internal/code-generator/generator/documentation.go +++ b/internal/code-generator/generator/documentation.go @@ -16,7 +16,7 @@ func Documentation(data []byte, documentationTmplPath, documentationTmplName, co } buf := &bytes.Buffer{} - if err := executeVendorTemplate(buf, regexpList, documentationTmplPath, documentationTmplName, commit); err != nil { + if err := executeDocumentationTemplate(buf, regexpList, documentationTmplPath, documentationTmplName, commit); err != nil { return nil, err } diff --git a/internal/code-generator/generator/generator_test.go b/internal/code-generator/generator/generator_test.go index 0487cca..93af6e1 100644 --- a/internal/code-generator/generator/generator_test.go +++ b/internal/code-generator/generator/generator_test.go @@ -15,44 +15,44 @@ const ( // Languages test extensionsTestFile = "test_files/extensions.test.yml" extensionsGold = "test_files/extensions.gold" - extensionsTestTmplPath = "test_files/extensions.test.go.tmpl" - extensionsTestTmplName = "extensions.test.go.tmpl" + extensionsTestTmplPath = "../assets/extensions.go.tmpl" + extensionsTestTmplName = "extensions.go.tmpl" // 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" + contentTestTmplPath = "../assets/content.go.tmpl" + contentTestTmplName = "content.go.tmpl" // Vendor test vendorTestFile = "test_files/vendor.test.yml" vendorGold = "test_files/vendor.gold" - vendorTestTmplPath = "test_files/vendor.test.go.tmpl" - vendorTestTmplName = "vendor.test.go.tmpl" + vendorTestTmplPath = "../assets/vendor.go.tmpl" + vendorTestTmplName = "vendor.go.tmpl" // Documentation test documentationTestFile = "test_files/documentation.test.yml" documentationGold = "test_files/documentation.gold" - documentationTestTmplPath = "test_files/documentation.test.go.tmpl" - documentationTestTmplName = "documentation.test.go.tmpl" + documentationTestTmplPath = "../assets/documentation.go.tmpl" + documentationTestTmplName = "documentation.go.tmpl" // Types test typesTestFile = "test_files/type.test.yml" typesGold = "test_files/type.gold" - typesTestTmplPath = "test_files/type.test.go.tmpl" - typesTestTmplName = "type.test.go.tmpl" + typesTestTmplPath = "../assets/type.go.tmpl" + typesTestTmplName = "type.go.tmpl" // Interpreters test interpretersTestFile = "test_files/interpreters.test.yml" interpretersGold = "test_files/interpreters.gold" - interpretersTestTmplPath = "test_files/interpreters.test.go.tmpl" - interpretersTestTmplName = "interpreters.test.go.tmpl" + interpretersTestTmplPath = "../assets/interpreters.go.tmpl" + interpretersTestTmplName = "interpreters.go.tmpl" // Filenames test filenamesTestFile = "test_files/filenames.test.yml" filenamesGold = "test_files/filenames.gold" - filenamesTestTmplPath = "test_files/filenames.test.go.tmpl" - filenamesTestTmplName = "filenames.test.go.tmpl" + filenamesTestTmplPath = "../assets/filenames.go.tmpl" + filenamesTestTmplName = "filenames.go.tmpl" ) func TestFromFile(t *testing.T) { diff --git a/internal/code-generator/generator/test_files/content.test.go.tmpl b/internal/code-generator/generator/test_files/content.test.go.tmpl deleted file mode 100644 index 332b3e7..0000000 --- a/internal/code-generator/generator/test_files/content.test.go.tmpl +++ /dev/null @@ -1,51 +0,0 @@ -package slinguist - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/simple-linguist.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND -// Extracted from github/linguist commit: {{ getCommit }} - -import ( - "path/filepath" - "regexp" - "strings" -) - -func GetLanguageByContent(filename string, content []byte) (lang string, safe bool) { - ext := strings.ToLower(filepath.Ext(filename)) - if fnMatcher, ok := matchers[ext]; ok { - lang, safe = fnMatcher(content) - return - } - - return GetLanguageByExtension(filename) -} - -type languageMatcher func ([]byte) (string, bool) - -var matchers = map[string]languageMatcher{ - {{ range $index, $disambiguator := . -}} - {{ printf "%q" $disambiguator.Extension }}: func(i []byte) (string, bool) { - {{ range $i, $language := $disambiguator.Languages -}} - - {{- if not (avoidLanguage $language) }} - {{- if gt (len $language.Heuristics) 0 }} - {{- if gt $i 0 }} else {{ end -}} - if {{- range $j, $heuristic := $language.Heuristics }} {{ $heuristic.Name }}.Match(i) - {{- if lt $j (len $language.LogicRelations) }} {{index $language.LogicRelations $j}} {{- end -}} {{ end }} { - return {{ printf "%q" $language.Language }}, true - } - - {{- end -}} - {{- end -}} - {{- end}} - - return {{ returnLanguage $disambiguator.Languages }}, {{ safeLanguage $disambiguator.Languages }} - }, - {{ end -}} -} - -var ( - {{ range $index, $heuristic := getAllHeuristics . -}} - {{ $heuristic.Name }} = regexp.MustCompile(`{{ $heuristic.Regexp }}`) - {{ end -}} -) \ No newline at end of file diff --git a/internal/code-generator/generator/test_files/documentation.test.go.tmpl b/internal/code-generator/generator/test_files/documentation.test.go.tmpl deleted file mode 100644 index ef346f2..0000000 --- a/internal/code-generator/generator/test_files/documentation.test.go.tmpl +++ /dev/null @@ -1,13 +0,0 @@ -package slinguist - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/simple-linguist.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND -// Extracted from github/linguist commit: {{ getCommit }} - -import "gopkg.in/toqueteos/substring.v1" - -var documentationMatchers = substring.Or( - {{range $regexp := . -}} - substring.Regexp(`{{ $regexp }}`), - {{end -}} -) diff --git a/internal/code-generator/generator/test_files/extensions.test.go.tmpl b/internal/code-generator/generator/test_files/extensions.test.go.tmpl deleted file mode 100644 index 70a9641..0000000 --- a/internal/code-generator/generator/test_files/extensions.test.go.tmpl +++ /dev/null @@ -1,11 +0,0 @@ -package slinguist - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/simple-linguist.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND -// Extracted from github/linguist commit: {{ getCommit }} - -var languagesByExtension = map[string][]string{ - {{range $extension, $languages := . -}} - "{{ $extension }}": { {{- $languages | formatStringSlice -}} }, - {{end -}} -} diff --git a/internal/code-generator/generator/test_files/filenames.test.go.tmpl b/internal/code-generator/generator/test_files/filenames.test.go.tmpl deleted file mode 100644 index f0a7952..0000000 --- a/internal/code-generator/generator/test_files/filenames.test.go.tmpl +++ /dev/null @@ -1,11 +0,0 @@ -package slinguist - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/simple-linguist.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND -// Extracted from github/linguist commit: {{ getCommit }} - -var languagesByFilename = map[string]string{ - {{range $filename, $language := . -}} - "{{ $filename }}": {{- printf "%q" $language -}}, - {{end -}} -} diff --git a/internal/code-generator/generator/test_files/interpreters.test.go.tmpl b/internal/code-generator/generator/test_files/interpreters.test.go.tmpl deleted file mode 100644 index 0ecb444..0000000 --- a/internal/code-generator/generator/test_files/interpreters.test.go.tmpl +++ /dev/null @@ -1,11 +0,0 @@ -package slinguist - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/simple-linguist.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND -// Extracted from github/linguist commit: {{ getCommit }} - -var languagesByInterpreter = map[string][]string{ - {{range $interpreter, $languages := . -}} - "{{ $interpreter }}": { {{- $languages | formatStringSlice -}} }, - {{end -}} -} diff --git a/internal/code-generator/generator/test_files/vendor.test.go.tmpl b/internal/code-generator/generator/test_files/vendor.test.go.tmpl deleted file mode 100644 index 89a65be..0000000 --- a/internal/code-generator/generator/test_files/vendor.test.go.tmpl +++ /dev/null @@ -1,13 +0,0 @@ -package slinguist - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/simple-linguist.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND -// Extracted from github/linguist commit: {{ getCommit }} - -import "gopkg.in/toqueteos/substring.v1" - -var vendorMatchers = substring.Or( - {{range $regexp := . -}} - substring.Regexp(`{{ $regexp }}`), - {{end -}} -)