From 6ddbb79af0f574446bcad9d00eb855cee8431acd Mon Sep 17 00:00:00 2001 From: Manuel Carmona Date: Mon, 17 Apr 2017 08:14:46 +0200 Subject: [PATCH] changed generator_test.go to use only TestFromFile modified *.test.yml to contain only necessary information fixed white spaces remove duplicated file languages.test.tmpl --- .../generator/generator_test.go | 193 +----------------- .../generator/test_files/content.gold | 38 ++-- .../generator/test_files/documentation.gold | 2 +- .../test_files/formated_content.gold | 81 -------- .../test_files/formated_documentation.gold | 25 --- .../test_files/formated_languages.gold | 12 -- .../generator/test_files/formated_type.gold | 27 --- .../generator/test_files/formated_vendor.gold | 24 --- .../generator/test_files/languages.gold | 10 +- .../generator/test_files/languages.test.yml | 13 -- .../generator/test_files/type.gold | 6 +- .../generator/test_files/type.test.yml | 37 +--- .../generator/test_files/vendor.gold | 2 +- internal/code-generator/main.go | 5 + 14 files changed, 43 insertions(+), 432 deletions(-) delete mode 100644 internal/code-generator/generator/test_files/formated_content.gold delete mode 100644 internal/code-generator/generator/test_files/formated_documentation.gold delete mode 100644 internal/code-generator/generator/test_files/formated_languages.gold delete mode 100644 internal/code-generator/generator/test_files/formated_type.gold delete mode 100644 internal/code-generator/generator/test_files/formated_vendor.gold diff --git a/internal/code-generator/generator/generator_test.go b/internal/code-generator/generator/generator_test.go index 9584b1d..524d805 100644 --- a/internal/code-generator/generator/generator_test.go +++ b/internal/code-generator/generator/generator_test.go @@ -12,18 +12,11 @@ import ( const ( commitTest = "fe8b44ab8a225b1ffa75b983b916ea22fee5b6f7" - // FromFile test - formatedLangGold = "test_files/formated_languages.gold" - formatedContentGold = "test_files/formated_content.gold" - formatedVendorGold = "test_files/formated_vendor.gold" - formatedDocumentationGold = "test_files/formated_documentation.gold" - formatedTypesGold = "test_files/formated_type.gold" - // Languages test ymlTestFile = "test_files/languages.test.yml" langGold = "test_files/languages.gold" - languagesTestTmplPath = "test_files/languages.test.tmpl" - languagesTestTmplName = "languages.test.tmpl" + languagesTestTmplPath = "test_files/languages.test.go.tmpl" + languagesTestTmplName = "languages.test.go.tmpl" // Heuristics test heuristicsTestFile = "test_files/heuristics.test.rb" @@ -51,19 +44,19 @@ const ( ) func TestFromFile(t *testing.T) { - goldLang, err := ioutil.ReadFile(formatedLangGold) + goldLang, err := ioutil.ReadFile(langGold) assert.NoError(t, err) - goldContent, err := ioutil.ReadFile(formatedContentGold) + goldContent, err := ioutil.ReadFile(contentGold) assert.NoError(t, err) - goldVendor, err := ioutil.ReadFile(formatedVendorGold) + goldVendor, err := ioutil.ReadFile(vendorGold) assert.NoError(t, err) - goldDocumentation, err := ioutil.ReadFile(formatedDocumentationGold) + goldDocumentation, err := ioutil.ReadFile(documentationGold) assert.NoError(t, err) - goldTypes, err := ioutil.ReadFile(formatedTypesGold) + goldTypes, err := ioutil.ReadFile(typesGold) assert.NoError(t, err) outPathLang, err := ioutil.TempFile("/tmp", "generator-test-") @@ -137,7 +130,7 @@ func TestFromFile(t *testing.T) { wantOut: goldDocumentation, }, { - name: "tyTestFromFile_Types", + name: "TestFromFile_Types", fileToParse: typesTestFile, outPath: outPathTypes.Name(), tmplPath: typesTestTmplPath, @@ -158,173 +151,3 @@ func TestFromFile(t *testing.T) { }) } } - -func TestLanguages(t *testing.T) { - gold, err := ioutil.ReadFile(langGold) - assert.NoError(t, err) - - input, err := ioutil.ReadFile(ymlTestFile) - assert.NoError(t, err) - - tests := []struct { - name string - input []byte - tmplPath string - tmplName string - commit string - wantOut []byte - }{ - { - name: "TestLanguages", - input: input, - tmplPath: languagesTestTmplPath, - tmplName: languagesTestTmplName, - commit: commitTest, - wantOut: gold, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - out, err := Languages(tt.input, tt.tmplPath, tt.tmplName, tt.commit) - assert.NoError(t, err) - assert.EqualValues(t, tt.wantOut, out, fmt.Sprintf("Languages() = %v, want %v", string(out), string(tt.wantOut))) - }) - } -} - -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: commitTest, - 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))) - }) - } -} - -func TestVendor(t *testing.T) { - gold, err := ioutil.ReadFile(vendorGold) - assert.NoError(t, err) - - input, err := ioutil.ReadFile(vendorTestFile) - assert.NoError(t, err) - - tests := []struct { - name string - input []byte - tmplPath string - tmplName string - commit string - wantOut []byte - }{ - { - name: "TestVendor", - input: input, - tmplPath: vendorTestTmplPath, - tmplName: vendorTestTmplName, - commit: commitTest, - wantOut: gold, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - out, err := Vendor(tt.input, tt.tmplPath, tt.tmplName, tt.commit) - assert.NoError(t, err) - assert.EqualValues(t, tt.wantOut, out, fmt.Sprintf("Vendor() = %v, want %v", string(out), string(tt.wantOut))) - }) - } -} - -func TestDocumentation(t *testing.T) { - gold, err := ioutil.ReadFile(documentationGold) - assert.NoError(t, err) - - input, err := ioutil.ReadFile(documentationTestFile) - assert.NoError(t, err) - - tests := []struct { - name string - input []byte - tmplPath string - tmplName string - commit string - wantOut []byte - }{ - { - name: "TestDocumentation", - input: input, - tmplPath: documentationTestTmplPath, - tmplName: documentationTestTmplName, - commit: commitTest, - wantOut: gold, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - out, err := Documentation(tt.input, tt.tmplPath, tt.tmplName, tt.commit) - assert.NoError(t, err) - assert.EqualValues(t, tt.wantOut, out, fmt.Sprintf("Documentation() = %v, want %v", string(out), string(tt.wantOut))) - }) - } -} - -func TestTypes(t *testing.T) { - gold, err := ioutil.ReadFile(typesGold) - assert.NoError(t, err) - - input, err := ioutil.ReadFile(typesTestFile) - assert.NoError(t, err) - - tests := []struct { - name string - input []byte - tmplPath string - tmplName string - commit string - wantOut []byte - }{ - { - name: "TestTypes", - input: input, - tmplPath: typesTestTmplPath, - tmplName: typesTestTmplName, - commit: commitTest, - wantOut: gold, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - out, err := Types(tt.input, tt.tmplPath, tt.tmplName, tt.commit) - assert.NoError(t, err) - assert.EqualValues(t, tt.wantOut, out, fmt.Sprintf("Types() = %v, want %v", string(out), string(tt.wantOut))) - }) - } -} diff --git a/internal/code-generator/generator/test_files/content.gold b/internal/code-generator/generator/test_files/content.gold index 73e745e..1e39940 100644 --- a/internal/code-generator/generator/test_files/content.gold +++ b/internal/code-generator/generator/test_files/content.gold @@ -20,7 +20,7 @@ func GetLanguageByContent(filename string, content []byte) (lang string, safe bo return GetLanguageByExtension(filename) } -type languageMatcher func ([]byte) (string, bool) +type languageMatcher func([]byte) (string, bool) var matchers = map[string]languageMatcher{ ".asc": func(i []byte) (string, bool) { @@ -31,14 +31,14 @@ var matchers = map[string]languageMatcher{ } else if asc_AGSScript_Matcher_0.Match(i) { return "AGS Script", true } - + return OtherLanguage, false }, ".ms": func(i []byte) (string, bool) { if ms_Groff_Matcher_0.Match(i) { return "Groff", true } - + return "MAXScript", true }, ".mod": func(i []byte) (string, bool) { @@ -47,7 +47,7 @@ var matchers = map[string]languageMatcher{ } else if mod_ModulaDash2_Matcher_0.Match(i) || mod_ModulaDash2_Matcher_1.Match(i) { return "Modula-2", true } - + return "Linux Kernel Module", false }, ".pro": func(i []byte) (string, bool) { @@ -60,22 +60,22 @@ var matchers = map[string]languageMatcher{ } else if pro_IDL_Matcher_0.Match(i) { return "IDL", true } - + return OtherLanguage, false }, - } +} var ( - asc_PublicKey_Matcher_0 = regexp.MustCompile(`(?m)^(----[- ]BEGIN|ssh-(rsa|dss)) `) - asc_AsciiDoc_Matcher_0 = regexp.MustCompile(`(?m)^[=-]+(\s|\n)|{{[A-Za-z]`) - asc_AGSScript_Matcher_0 = regexp.MustCompile(`(?m)^(\/\/.+|((import|export)\s+)?(function|int|float|char)\s+((room|repeatedly|on|game)_)?([A-Za-z]+[A-Za-z_0-9]+)\s*[;\(])`) - ms_Groff_Matcher_0 = regexp.MustCompile(`(?mi)^[.'][a-z][a-z](\s|$)`) - mod_XML_Matcher_0 = regexp.MustCompile(`(?m)