Skip to content

Commit

Permalink
feat: add basic xml parser
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Sep 16, 2020
1 parent 3acfea3 commit 6a309cd
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ require (
github.com/yudai/pp v2.0.1+incompatible // indirect
golang.org/x/exp v0.0.0-20191224044220-1fea468a75e9 // indirect
gonum.org/v1/gonum v0.6.2
gopkg.in/yaml.v2 v2.3.0
)
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,5 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
39 changes: 39 additions & 0 deletions pkg/domain/cloc/cloc_summary.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package cloc

// LanguageSummary to generate output like cloc
type LanguageSummaryCloc struct {
Name string `yaml:"name"`
Code int64 `yaml:"code"`
Comment int64 `yaml:"comment"`
Blank int64 `yaml:"blank"`
Count int64 `yaml:"nFiles"`
}

type SummaryStruct struct {
Code int64 `yaml:"code"`
Comment int64 `yaml:"comment"`
Blank int64 `yaml:"blank"`
Count int64 `yaml:"nFiles"`
}

type HeaderStruct struct {
Url string `yaml:"url"`
Version string `yaml:"version"`
ElapsedSeconds float64 `yaml:"elapsed_seconds"`
NFiles int64 `yaml:"n_files"`
NLines int64 `yaml:"n_lines"`
FilesPerSecond float64 `yaml:"files_per_second"`
LinesPerSecond float64 `yaml:"lines_per_second"`
}

type LanguageReportStart struct {
Header HeaderStruct
}

type LanguageReportEnd struct {
Sum SummaryStruct `yaml:"SUM"`
}

type ClocSummary struct {
Header HeaderStruct
}
36 changes: 36 additions & 0 deletions pkg/domain/cloc/cloc_summary_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cloc


import (
"fmt"
. "github.com/onsi/gomega"
"gopkg.in/yaml.v2"
"log"
"testing"
)

func Test_Yaml_Parse_Model(t *testing.T) {
t.Parallel()
g := NewGomegaWithT(t)


var data = `
header:
url: https://github.com/boyter/scc/
version: 2.13.0
elapsed_seconds: 0.006
n_files: 25
n_lines: 4045
files_per_second: 4166.666666666667
lines_per_second: 674166.6666666666
`

var header = LanguageReportStart{}
err := yaml.Unmarshal([]byte(data), &header)
if err != nil {
log.Fatalf("error: %v", header)
}

g.Expect(header.Header.Version).To(Equal("2.13.0"))
}

0 comments on commit 6a309cd

Please sign in to comment.