Skip to content

Commit 3b409d3

Browse files
committed
fixed coverage to also count overloads
1 parent 351daea commit 3b409d3

File tree

3 files changed

+71
-7
lines changed

3 files changed

+71
-7
lines changed

tests/stdlib_coverage_test.go

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,38 @@ func (v funcCallVisitor) VisitFuncCall(f *ast.FuncCall) ast.VisitResult {
5555
return ast.VisitRecurse
5656
}
5757

58+
type unaryExprVisitor func(*ast.UnaryExpr)
59+
60+
func (unaryExprVisitor) Visitor() {}
61+
func (v unaryExprVisitor) VisitUnaryExpr(c *ast.UnaryExpr) ast.VisitResult {
62+
v(c)
63+
return ast.VisitRecurse
64+
}
65+
66+
type binaryExprVisitor func(*ast.BinaryExpr)
67+
68+
func (binaryExprVisitor) Visitor() {}
69+
func (v binaryExprVisitor) VisitBinaryExpr(c *ast.BinaryExpr) ast.VisitResult {
70+
v(c)
71+
return ast.VisitRecurse
72+
}
73+
74+
type ternaryExprVisitor func(*ast.TernaryExpr)
75+
76+
func (ternaryExprVisitor) Visitor() {}
77+
func (v ternaryExprVisitor) VisitTernaryExpr(c *ast.TernaryExpr) ast.VisitResult {
78+
v(c)
79+
return ast.VisitRecurse
80+
}
81+
82+
type castExprVisitor func(*ast.CastExpr)
83+
84+
func (castExprVisitor) Visitor() {}
85+
func (v castExprVisitor) VisitCastExpr(c *ast.CastExpr) ast.VisitResult {
86+
v(c)
87+
return ast.VisitRecurse
88+
}
89+
5890
var (
5991
duden_modules = make(map[string]*ast.Module, 30)
6092
duden_funcs = make(map[*ast.FuncDecl]struct{}, 100)
@@ -117,6 +149,17 @@ func TestStdlibCoverage(t *testing.T) {
117149

118150
const stdlib_testdata = "testdata/stdlib"
119151
called_functions := make(map[*ast.FuncDecl]int, len(duden_funcs))
152+
func_called := func(f *ast.FuncDecl) {
153+
if _, ok := duden_funcs[f]; !ok {
154+
return
155+
}
156+
if n, ok := called_functions[f]; ok {
157+
called_functions[f] = n + 1
158+
} else {
159+
called_functions[f] = 1
160+
}
161+
}
162+
120163
err = filepath.WalkDir(stdlib_testdata, func(path string, d fs.DirEntry, err error) error {
121164
if err != nil || !d.IsDir() || path == stdlib_testdata {
122165
return nil
@@ -135,13 +178,30 @@ func TestStdlibCoverage(t *testing.T) {
135178
}
136179

137180
ast.VisitModule(module, funcCallVisitor(func(f *ast.FuncCall) {
138-
if _, ok := duden_funcs[f.Func]; !ok {
139-
return
181+
func_called(f.Func)
182+
}))
183+
184+
ast.VisitModule(module, unaryExprVisitor(func(c *ast.UnaryExpr) {
185+
if c.OverloadedBy != nil {
186+
func_called(c.OverloadedBy.Decl)
140187
}
141-
if n, ok := called_functions[f.Func]; ok {
142-
called_functions[f.Func] = n + 1
143-
} else {
144-
called_functions[f.Func] = 1
188+
}))
189+
190+
ast.VisitModule(module, binaryExprVisitor(func(c *ast.BinaryExpr) {
191+
if c.OverloadedBy != nil {
192+
func_called(c.OverloadedBy.Decl)
193+
}
194+
}))
195+
196+
ast.VisitModule(module, ternaryExprVisitor(func(c *ast.TernaryExpr) {
197+
if c.OverloadedBy != nil {
198+
func_called(c.OverloadedBy.Decl)
199+
}
200+
}))
201+
202+
ast.VisitModule(module, castExprVisitor(func(c *ast.CastExpr) {
203+
if c.OverloadedBy != nil {
204+
func_called(c.OverloadedBy.Decl)
145205
}
146206
}))
147207

tests/testdata/stdlib/Uri/Uri.ddp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,7 @@ Schreibe ((alle AbfragenParameter aus "") als Text) auf eine Zeile.
5454
Schreibe (den Wert des AbfragenParameters "a" aus "a=b&c=d") auf eine Zeile.
5555
Schreibe (den Wert des AbfragenParameters "a" aus "a&c=d") auf eine Zeile.
5656
Schreibe (den Wert des AbfragenParameters "a" aus "a=hi&c=d") auf eine Zeile.
57-
Schreibe (den Wert des AbfragenParameters "a" aus "") auf eine Zeile.
57+
Schreibe (den Wert des AbfragenParameters "a" aus "") auf eine Zeile.
58+
59+
Der AbfragenParameter param ist ein AbfragenParameter "a"="3".
60+
Schreibe (param als Text) auf eine Zeile.

tests/testdata/stdlib/Uri/expected.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ b
3535

3636
hi
3737

38+
a=3

0 commit comments

Comments
 (0)