diff --git a/pkg/domain/cloc/cloc_summary.go b/pkg/domain/cloc/cloc_summary.go index 9bd577f8..d07f4686 100644 --- a/pkg/domain/cloc/cloc_summary.go +++ b/pkg/domain/cloc/cloc_summary.go @@ -1,5 +1,8 @@ package cloc + + + // LanguageSummary to generate output like cloc type LanguageSummaryCloc struct { Name string `yaml:"name"` @@ -37,7 +40,4 @@ type LanguageReportEnd struct { type ClocSummary struct { Header HeaderStruct Sum SummaryStruct `yaml:"SUM,omitempty"` - Java *LanguageSummaryCloc `yaml:"Java,omitempty"` - Kotlin *LanguageSummaryCloc `yaml:"Kotlin,omitempty"` - Groovy *LanguageSummaryCloc `yaml:"Groovy,omitempty"` } diff --git a/pkg/domain/cloc/cloc_summary_test.go b/pkg/domain/cloc/cloc_summary_test.go index 0b4e017c..c7ff894e 100644 --- a/pkg/domain/cloc/cloc_summary_test.go +++ b/pkg/domain/cloc/cloc_summary_test.go @@ -1,17 +1,19 @@ package cloc import ( + "encoding/json" + "fmt" . "github.com/onsi/gomega" "gopkg.in/yaml.v2" "log" "testing" + "github.com/boyter/scc/processor" ) func Test_Yaml_Parse_Model(t *testing.T) { t.Parallel() g := NewGomegaWithT(t) - var data = ` header: url: https://github.com/boyter/scc/ @@ -37,7 +39,6 @@ func Test_Cloc_Yaml_File_Parse_Model(t *testing.T) { t.Parallel() g := NewGomegaWithT(t) - var data = ` # https://github.com/boyter/scc/ header: @@ -71,3 +72,23 @@ SUM: g.Expect(header.Header.Version).To(Equal("2.13.0")) g.Expect(header.Sum.Code).To(Equal(int64(3010))) } + +func Test_parser_json_languages(t *testing.T) { + t.Parallel() + g := NewGomegaWithT(t) + + var data = `[ + {"Name":"Java","Bytes":21169200,"CodeBytes":0,"Lines":540043,"Code":381028,"Comment":93196,"Blank":65819,"Complexity":43899,"Count":4435,"WeightedComplexity":0,"Files":[]}, + {"Name":"Kotlin","Bytes":6961705,"CodeBytes":0,"Lines":168900,"Code":118448,"Comment":30743,"Blank":19709,"Complexity":7636,"Count":1315,"WeightedComplexity":0,"Files":[]} +] +` + + var f []processor.LanguageSummary + err := json.Unmarshal([]byte(data), &f) + if err != nil { + fmt.Println("Error parsing JSON: ", err) + } + fmt.Println(f) + + g.Expect(len(f)).To(Equal(2)) +}