Skip to content

Commit 180536e

Browse files
committed
updated unit tests
1 parent 0c4813f commit 180536e

File tree

1 file changed

+231
-0
lines changed

1 file changed

+231
-0
lines changed

tests/stto_test.go

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
package tests
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"testing"
7+
8+
"github.com/mainak55512/stto/utils"
9+
"gopkg.in/yaml.v3"
10+
)
11+
12+
func dummyData() []utils.OutputStructure {
13+
test_list := []utils.OutputStructure{
14+
{
15+
Ext: "py",
16+
File_count: 10,
17+
Code: 365,
18+
Gap: 40,
19+
Comments: 23,
20+
Line_count: 428,
21+
Code_percent: 57.67,
22+
},
23+
{
24+
Ext: "go",
25+
File_count: 10,
26+
Code: 365,
27+
Gap: 40,
28+
Comments: 23,
29+
Line_count: 428,
30+
Code_percent: 57.67,
31+
},
32+
{
33+
Ext: "c",
34+
File_count: 10,
35+
Code: 365,
36+
Gap: 40,
37+
Comments: 23,
38+
Line_count: 428,
39+
Code_percent: 57.67,
40+
},
41+
{
42+
Ext: "rs",
43+
File_count: 10,
44+
Code: 365,
45+
Gap: 40,
46+
Comments: 23,
47+
Line_count: 428,
48+
Code_percent: 57.67,
49+
},
50+
{
51+
Ext: "cpp",
52+
File_count: 10,
53+
Code: 365,
54+
Gap: 40,
55+
Comments: 23,
56+
Line_count: 428,
57+
Code_percent: 57.67,
58+
},
59+
}
60+
return test_list
61+
}
62+
63+
func TestJSONEXT(t *testing.T) {
64+
test_data := dummyData()
65+
ext := "go, c"
66+
next := "none"
67+
expected_output_list := []utils.OutputStructure{
68+
{
69+
Ext: "go",
70+
File_count: 10,
71+
Code: 365,
72+
Gap: 40,
73+
Comments: 23,
74+
Line_count: 428,
75+
Code_percent: 57.67,
76+
},
77+
{
78+
Ext: "c",
79+
File_count: 10,
80+
Code: 365,
81+
Gap: 40,
82+
Comments: 23,
83+
Line_count: 428,
84+
Code_percent: 57.67,
85+
},
86+
}
87+
88+
jsonOP, _ := json.MarshalIndent(expected_output_list, "", " ")
89+
90+
if out, _ := utils.EmitJSON(&ext, &next, &test_data); out != string(jsonOP) {
91+
t.Fatal("Failed!")
92+
}
93+
94+
}
95+
96+
func TestJSONEXTNonExistingExt(t *testing.T) {
97+
test_data := dummyData()
98+
ext := "md, rb"
99+
next := "none"
100+
expected_output_list := "No file with extension(s) 'md, rb' exists in this directory"
101+
if _, err := utils.EmitJSON(&ext, &next, &test_data); fmt.Sprintf("%s", err) != expected_output_list {
102+
t.Fatal("Failed!")
103+
}
104+
}
105+
106+
func TestYAMLEXTNonExistingExt(t *testing.T) {
107+
test_data := dummyData()
108+
ext := "md, rb"
109+
next := "none"
110+
expected_output_list := "No file with extension(s) 'md, rb' exists in this directory"
111+
if _, err := utils.EmitYAML(&ext, &next, &test_data); fmt.Sprintf("%s", err) != expected_output_list {
112+
t.Fatal("Failed!")
113+
}
114+
}
115+
116+
func TestYAMLEXT(t *testing.T) {
117+
test_data := dummyData()
118+
ext := "go, c"
119+
next := "none"
120+
expected_output_list := []utils.OutputStructure{
121+
{
122+
Ext: "go",
123+
File_count: 10,
124+
Code: 365,
125+
Gap: 40,
126+
Comments: 23,
127+
Line_count: 428,
128+
Code_percent: 57.67,
129+
},
130+
{
131+
Ext: "c",
132+
File_count: 10,
133+
Code: 365,
134+
Gap: 40,
135+
Comments: 23,
136+
Line_count: 428,
137+
Code_percent: 57.67,
138+
},
139+
}
140+
141+
yamlOP, _ := yaml.Marshal(expected_output_list)
142+
143+
if out, _ := utils.EmitYAML(&ext, &next, &test_data); out != string(yamlOP) {
144+
t.Fatal("Failed!")
145+
}
146+
147+
}
148+
149+
func TestYAMLNEXT(t *testing.T) {
150+
test_data := dummyData()
151+
ext := "none"
152+
next := "c, go"
153+
expected_output_list := []utils.OutputStructure{
154+
{
155+
Ext: "py",
156+
File_count: 10,
157+
Code: 365,
158+
Gap: 40,
159+
Comments: 23,
160+
Line_count: 428,
161+
Code_percent: 57.67,
162+
},
163+
{
164+
Ext: "rs",
165+
File_count: 10,
166+
Code: 365,
167+
Gap: 40,
168+
Comments: 23,
169+
Line_count: 428,
170+
Code_percent: 57.67,
171+
},
172+
{
173+
Ext: "cpp",
174+
File_count: 10,
175+
Code: 365,
176+
Gap: 40,
177+
Comments: 23,
178+
Line_count: 428,
179+
Code_percent: 57.67,
180+
},
181+
}
182+
183+
yamlOP, _ := yaml.Marshal(expected_output_list)
184+
185+
if out, _ := utils.EmitYAML(&ext, &next, &test_data); out != string(yamlOP) {
186+
t.Fatal("Failed!")
187+
}
188+
189+
}
190+
191+
func TestJSONNEXT(t *testing.T) {
192+
test_data := dummyData()
193+
ext := "none"
194+
next := "c, go"
195+
expected_output_list := []utils.OutputStructure{
196+
{
197+
Ext: "py",
198+
File_count: 10,
199+
Code: 365,
200+
Gap: 40,
201+
Comments: 23,
202+
Line_count: 428,
203+
Code_percent: 57.67,
204+
},
205+
{
206+
Ext: "rs",
207+
File_count: 10,
208+
Code: 365,
209+
Gap: 40,
210+
Comments: 23,
211+
Line_count: 428,
212+
Code_percent: 57.67,
213+
},
214+
{
215+
Ext: "cpp",
216+
File_count: 10,
217+
Code: 365,
218+
Gap: 40,
219+
Comments: 23,
220+
Line_count: 428,
221+
Code_percent: 57.67,
222+
},
223+
}
224+
225+
jsonOP, _ := json.MarshalIndent(expected_output_list, "", " ")
226+
227+
if out, _ := utils.EmitJSON(&ext, &next, &test_data); out != string(jsonOP) {
228+
t.Fatal("Failed!")
229+
}
230+
231+
}

0 commit comments

Comments
 (0)