Skip to content

Commit

Permalink
feat: add map for summary
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Sep 16, 2020
1 parent 4222c63 commit 8efd270
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pkg/domain/cloc/cloc_summary.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package cloc




// LanguageSummary to generate output like cloc
type LanguageSummaryCloc struct {
Name string `yaml:"name"`
Expand Down Expand Up @@ -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"`
}
25 changes: 23 additions & 2 deletions pkg/domain/cloc/cloc_summary_test.go
Original file line number Diff line number Diff line change
@@ -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/
Expand All @@ -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:
Expand Down Expand Up @@ -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))
}

0 comments on commit 8efd270

Please sign in to comment.