Skip to content

Commit

Permalink
feat: add sort cloc support
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Sep 17, 2020
1 parent decb12a commit 4b63a21
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
18 changes: 17 additions & 1 deletion cmd/cloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"log"
"os"
"path/filepath"
"sort"
"strings"
)

Expand Down Expand Up @@ -64,7 +65,22 @@ func processTopFile(dir string) {

runProcessor()

//content := cmd_util.ReadCocaFile("top_cloc.json")
var languageSummaries []processor.LanguageSummary
content := cmd_util.ReadCocaFile("top_cloc.json")
err := json.Unmarshal(content, &languageSummaries)
checkError("no a valid language languageSummaries", err)

for _, langSummary := range languageSummaries {
files := langSummary.Files
sort.Slice(files, func(i, j int) bool {
return files[i].Code > files[j].Code
})

langSummary.Files = files
}

sortContent, _ := json.Marshal(languageSummaries)
cmd_util.WriteToCocaFile("sort_cloc.json", string(sortContent))
}

func processByDirectory(firstDir string) {
Expand Down
18 changes: 18 additions & 0 deletions cmd/cloc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,22 @@ func TestShouldReturnNullWhenIgnoreDir(t *testing.T) {
Golden: "testdata/cloc_ignore.txt",
}}
RunTestCmd(t, tests)
}

func TestShouldByFileSize(t *testing.T) {
abs := "../_fixtures"

analysis := []testcase.CmdTestCase{{
Name: "analysis",
Cmd: "analysis -p " + abs,
Golden: "",
}}
RunTestCmd(t, analysis)

tests := []testcase.CmdTestCase{{
Name: "cloc",
Cmd: "cloc " + abs + " --top-file",
Golden: "",
}}
RunTestCmd(t, tests)
}

0 comments on commit 4b63a21

Please sign in to comment.