@@ -8,35 +8,22 @@ import (
88)
99
1010func TestFunctionStatements (t * testing.T ) {
11- var expectedCognitiveComplexity = 3
12- filename := "testdata/function.vbs"
13- vbscript := domain.VBScript {}
14-
15- vbscript .CognitiveComplexity = internal .Read (filename , & vbscript )
16-
17- if expectedCognitiveComplexity != vbscript .CognitiveComplexity {
18- t .Errorf ("wrong output: got %v, expected %v" , vbscript .CognitiveComplexity , expectedCognitiveComplexity )
19- }
20- }
21-
22- func TestTwoFunctionStatements (t * testing.T ) {
23- var expectedCognitiveComplexity = 3
24- var expectedFirstCognitiveComplexity = 2
25- var expectedSecondCognitiveComplexity = 1
26- filename := "testdata/two_function.vbs"
27- vbscript := domain.VBScript {}
28-
29- vbscript .CognitiveComplexity = internal .Read (filename , & vbscript )
30-
31- if expectedCognitiveComplexity != vbscript .CognitiveComplexity {
32- t .Errorf ("wrong output: got %v, expected %v" , vbscript .CognitiveComplexity , expectedCognitiveComplexity )
33- }
34-
35- if expectedFirstCognitiveComplexity != vbscript .Functions [0 ].CognitiveComplexity {
36- t .Errorf ("wrong output: got %v, expected %v" , vbscript .Functions [0 ].CognitiveComplexity , expectedFirstCognitiveComplexity )
11+ tests := []struct {
12+ filename string
13+ expectedValue int
14+ }{
15+ {"testdata/function/function.vbs" , 2 },
16+ {"testdata/function/public_function.vbs" , 3 },
17+ {"testdata/function/public_default_function.vbs" , 4 },
18+ {"testdata/function/private_function.vbs" , 1 },
19+ {"testdata/function/two_function.vbs" , 3 },
3720 }
21+ for _ , test := range tests {
22+ vbscript := domain.VBScript {}
23+ internal .Read (test .filename , & vbscript )
3824
39- if expectedSecondCognitiveComplexity != vbscript .Functions [1 ].CognitiveComplexity {
40- t .Errorf ("wrong output: got %v, expected %v" , vbscript .Functions [1 ].CognitiveComplexity , expectedSecondCognitiveComplexity )
25+ if test .expectedValue != vbscript .CognitiveComplexity {
26+ t .Errorf ("wrong cognitive complexity output: got %v, expected %v (%s)" , vbscript .CognitiveComplexity , test .expectedValue , test .filename )
27+ }
4128 }
4229}
0 commit comments