From 31a925db3f46f81b2064a85ab397318f89bfbab1 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Thu, 17 Sep 2020 12:57:17 +0800 Subject: [PATCH] feat: add test for summary --- _fixtures/cloc/summary/android.json | 1 + pkg/domain/cloc/cloc_summary.go | 1 - pkg/domain/cloc/cloc_summary_test.go | 21 ++++++++++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 _fixtures/cloc/summary/android.json diff --git a/_fixtures/cloc/summary/android.json b/_fixtures/cloc/summary/android.json new file mode 100644 index 00000000..aebfe97e --- /dev/null +++ b/_fixtures/cloc/summary/android.json @@ -0,0 +1 @@ +[{"Name":"XML","Bytes":12763494,"CodeBytes":0,"Lines":223838,"Code":206000,"Comment":11368,"Blank":6470,"Complexity":0,"Count":9269,"WeightedComplexity":0,"Files":[]},{"Name":"Java","Bytes":21201489,"CodeBytes":0,"Lines":541088,"Code":381639,"Comment":93529,"Blank":65920,"Complexity":43975,"Count":4440,"WeightedComplexity":0,"Files":[]},{"Name":"Kotlin","Bytes":7141418,"CodeBytes":0,"Lines":175415,"Code":123963,"Comment":31591,"Blank":19861,"Complexity":7686,"Count":2142,"WeightedComplexity":0,"Files":[]},{"Name":"Gradle","Bytes":415024,"CodeBytes":0,"Lines":17101,"Code":15273,"Comment":432,"Blank":1396,"Complexity":0,"Count":1508,"WeightedComplexity":0,"Files":[]},{"Name":"Plain Text","Bytes":5185137,"CodeBytes":0,"Lines":94703,"Code":94544,"Comment":0,"Blank":159,"Complexity":0,"Count":150,"WeightedComplexity":0,"Files":[]},{"Name":"gitignore","Bytes":7084,"CodeBytes":0,"Lines":533,"Code":533,"Comment":0,"Blank":0,"Complexity":0,"Count":97,"WeightedComplexity":0,"Files":[]},{"Name":"Properties File","Bytes":637870,"CodeBytes":0,"Lines":2085,"Code":1659,"Comment":372,"Blank":54,"Complexity":0,"Count":80,"WeightedComplexity":0,"Files":[]},{"Name":"Prolog","Bytes":32671,"CodeBytes":0,"Lines":863,"Code":753,"Comment":0,"Blank":110,"Complexity":0,"Count":51,"WeightedComplexity":0,"Files":[]},{"Name":"HTML","Bytes":1386728,"CodeBytes":0,"Lines":39973,"Code":29951,"Comment":261,"Blank":9761,"Complexity":0,"Count":44,"WeightedComplexity":0,"Files":[]},{"Name":"JSON","Bytes":5835319,"CodeBytes":0,"Lines":166718,"Code":166714,"Comment":0,"Blank":4,"Complexity":0,"Count":26,"WeightedComplexity":0,"Files":[]},{"Name":"Forth","Bytes":4272,"CodeBytes":0,"Lines":142,"Code":120,"Comment":0,"Blank":22,"Complexity":25,"Count":18,"WeightedComplexity":0,"Files":[]},{"Name":"Markdown","Bytes":92997,"CodeBytes":0,"Lines":1302,"Code":951,"Comment":0,"Blank":351,"Complexity":0,"Count":13,"WeightedComplexity":0,"Files":[]},{"Name":"Batch","Bytes":18632,"CodeBytes":0,"Lines":702,"Code":513,"Comment":0,"Blank":189,"Complexity":170,"Count":10,"WeightedComplexity":0,"Files":[]},{"Name":"BASH","Bytes":25182,"CodeBytes":0,"Lines":812,"Code":606,"Comment":108,"Blank":98,"Complexity":96,"Count":5,"WeightedComplexity":0,"Files":[]},{"Name":"CMake","Bytes":5004,"CodeBytes":0,"Lines":141,"Code":39,"Comment":64,"Blank":38,"Complexity":0,"Count":4,"WeightedComplexity":0,"Files":[]},{"Name":"C++","Bytes":842,"CodeBytes":0,"Lines":30,"Code":27,"Comment":0,"Blank":3,"Complexity":0,"Count":3,"WeightedComplexity":0,"Files":[]},{"Name":"SVG","Bytes":10949,"CodeBytes":0,"Lines":183,"Code":162,"Comment":16,"Blank":5,"Complexity":0,"Count":3,"WeightedComplexity":0,"Files":[]},{"Name":"Shell","Bytes":15888,"CodeBytes":0,"Lines":516,"Code":399,"Comment":63,"Blank":54,"Complexity":57,"Count":3,"WeightedComplexity":0,"Files":[]},{"Name":"Android Interface Definition Language","Bytes":2650,"CodeBytes":0,"Lines":62,"Code":62,"Comment":0,"Blank":0,"Complexity":0,"Count":2,"WeightedComplexity":0,"Files":[]},{"Name":"C","Bytes":1874,"CodeBytes":0,"Lines":63,"Code":39,"Comment":22,"Blank":2,"Complexity":0,"Count":2,"WeightedComplexity":0,"Files":[]},{"Name":"XML Schema","Bytes":474,"CodeBytes":0,"Lines":15,"Code":13,"Comment":0,"Blank":2,"Complexity":0,"Count":2,"WeightedComplexity":0,"Files":[]},{"Name":"Protocol Buffers","Bytes":4929,"CodeBytes":0,"Lines":143,"Code":55,"Comment":63,"Blank":25,"Complexity":0,"Count":1,"WeightedComplexity":0,"Files":[]},{"Name":"Rust","Bytes":0,"CodeBytes":0,"Lines":0,"Code":0,"Comment":0,"Blank":0,"Complexity":0,"Count":1,"WeightedComplexity":0,"Files":[]}] \ No newline at end of file diff --git a/pkg/domain/cloc/cloc_summary.go b/pkg/domain/cloc/cloc_summary.go index 5674e407..64a5e27f 100644 --- a/pkg/domain/cloc/cloc_summary.go +++ b/pkg/domain/cloc/cloc_summary.go @@ -44,7 +44,6 @@ func BuildLanguageMap(languageMap map[string]map[string]processor.LanguageSummar } dirName := strings.TrimSuffix(filepath.Base(filePath), filepath.Ext(filePath)) - languageMap[dirName] = make(map[string]processor.LanguageSummary) for _, key := range keys { diff --git a/pkg/domain/cloc/cloc_summary_test.go b/pkg/domain/cloc/cloc_summary_test.go index 51b2a367..7e2ab89f 100644 --- a/pkg/domain/cloc/cloc_summary_test.go +++ b/pkg/domain/cloc/cloc_summary_test.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/boyter/scc/processor" . "github.com/onsi/gomega" + "path/filepath" "testing" ) @@ -33,7 +34,7 @@ func TestGenerateCsv(t *testing.T) { g := NewGomegaWithT(t) var languageMap = make(map[string]map[string]processor.LanguageSummary) - var keys = []string{"Java", "Kotlin"}; + var keys = []string{"Java", "Kotlin"} languageMap["home"] = make(map[string]processor.LanguageSummary) languageMap["home"]["Java"] = processor.LanguageSummary{} @@ -42,3 +43,21 @@ func TestGenerateCsv(t *testing.T) { g.Expect(data[0]).To(Equal([]string{"package", "summary", "Java", "Kotlin"})) g.Expect(data[1]).To(Equal([]string{"home", "0", "0", "0"})) } + +func TestShouldBuildLanguageMap(t *testing.T) { + t.Parallel() + g := NewGomegaWithT(t) + + codePath := "../../../_fixtures/cloc/summary/android.json" + codePath = filepath.FromSlash(codePath) + + var keys = []string{"Java", "Kotlin", "Phodal"} + languageMap := make(map[string]map[string]processor.LanguageSummary) + + BuildLanguageMap(languageMap, keys, codePath) + + g.Expect(len(languageMap["android"])).To(Equal(3)) + g.Expect(languageMap["android"]["Java"].Code).To(Equal(int64(381639))) + g.Expect(languageMap["android"]["Kotlin"].Code).To(Equal(int64(123963))) + g.Expect(languageMap["android"]["Phodal"].Code).To(Equal(int64(0))) +}