Skip to content

Commit 1966898

Browse files
committed
fix
1 parent 751ad49 commit 1966898

File tree

9 files changed

+59
-15
lines changed

9 files changed

+59
-15
lines changed

β€Žcmd/main.goβ€Ž

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@ package main
22

33
import (
44
"fmt"
5+
"os"
56

67
"cli/internal"
78
)
89

910
func main () {
10-
fmt.Print(internal.Respond())
11+
if len(os.Args) != 2 {
12+
fmt.Println("Error parsing argument: path specified incorrectly")
13+
} else {
14+
path := os.Args[1]
15+
fmt.Print(internal.Respond(path))
16+
}
1117
}

β€Žinternal/utils.goβ€Ž

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,20 @@ package internal
22

33
import (
44
"fmt"
5-
"os"
65
"strconv"
76
"strings"
87

98
core "github.com/statloc/core"
109
)
1110

12-
func Respond() string {
13-
if len(os.Args) != 2 {
14-
return "Error parsing argument: path specified incorrectly"
15-
} else {
16-
path := os.Args[1]
11+
func Respond(path string) (result string) {
1712
response, err := core.GetStatistics(path)
1813

1914
if err != nil {
2015
return fmt.Sprintf("ERROR: path \"%s\" is not found!!!\n", path)
2116
}
2217

23-
result := fmt.Sprintf(
18+
result = fmt.Sprintf(
2419
`πŸ—£οΈ Languages
2520
%s
2621
⚑ Components
@@ -35,8 +30,7 @@ Languages: %d LOC: %d Files %d
3530
response.Total.Files,
3631
)
3732

38-
return result
39-
}
33+
return
4034
}
4135

4236
func GetTable(

β€Žinternal/utils_test.goβ€Ž

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,31 @@ import (
1111
"github.com/stretchr/testify/assert"
1212
)
1313

14-
func TestGetTable(t *testing.T) {
14+
func TestRespond(t *testing.T) {
1515
file, _ := os.Open("../testdata/results.txt")
1616
defer file.Close() // nolint:errcheck
1717

18+
response := internal.Respond("../testdata")
19+
20+
// go line by line
21+
scanner := bufio.NewScanner(file)
22+
for scanner.Scan() {
23+
println(response, scanner.Text())
24+
assert.True(t, strings.Contains(response, scanner.Text()))
25+
}
26+
}
27+
28+
func TestGetTable(t *testing.T) {
29+
file, _ := os.Open("../testdata/languages.txt")
30+
defer file.Close() // nolint:errcheck
31+
1832
statistics, _ := core.GetStatistics("../testdata")
1933
table := internal.GetTable(statistics.Languages, 5, 3, 5)
2034

2135
// go line by line
2236
scanner := bufio.NewScanner(file)
2337
for scanner.Scan() {
38+
println(table, scanner.Text())
2439
assert.True(t, strings.Contains(table, scanner.Text()))
2540
}
2641
}

β€Žtestdata/languages.txtβ€Ž

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
+--------+-----+-------+
2+
| Title | LOC | Files |
3+
+--------+-----+-------+
4+
| Rust | 8 | 2 |
5+
| Go | 8 | 1 |
6+
| Python | 4 | 2 |
7+
| C++ | 8 | 2 |
8+
+--------+-----+-------+

β€Žtestdata/results.txtβ€Ž

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1+
πŸ—£οΈ Languages
12
+--------+-----+-------+
23
| Title | LOC | Files |
34
+--------+-----+-------+
4-
| Tests | 6 | 2 |
5-
| Rust | 4 | 1 |
5+
| Rust | 8 | 2 |
66
| Go | 8 | 1 |
7-
| Python | 2 | 1 |
8-
| Total | 24 | 4 |
7+
| Python | 4 | 2 |
8+
| C++ | 8 | 2 |
99
+--------+-----+-------+
10+
11+
⚑ Components
12+
+-------------+-----+-------+
13+
| Title | LOC | Files |
14+
+-------------+-----+-------+
15+
| Tests | 10 | 3 |
16+
| Controllers | 8 | 2 |
17+
+-------------+-----+-------+
18+
19+
πŸ“Š Total statistics
20+
Languages: 4 LOC: 28 Files 7
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
int main() {
2+
return 0;
3+
}

β€Žtestdata/somedir/main.pyβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("Hello world!")

β€Žtestdata/somedir/main.rsβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello World!");
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
int main() {
2+
return 0;
3+
}

0 commit comments

Comments
Β (0)