Skip to content

Commit

Permalink
feat: add test for summary
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Sep 17, 2020
1 parent ede6701 commit 31a925d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions _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":[]}]
1 change: 0 additions & 1 deletion pkg/domain/cloc/cloc_summary.go
Expand Up @@ -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 {
Expand Down
21 changes: 20 additions & 1 deletion pkg/domain/cloc/cloc_summary_test.go
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/boyter/scc/processor"
. "github.com/onsi/gomega"
"path/filepath"
"testing"
)

Expand Down Expand Up @@ -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{}

Expand All @@ -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)))
}

0 comments on commit 31a925d

Please sign in to comment.