• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlange-42 / modo / 14906456369

08 May 2025 12:28PM CUT coverage: 73.859% (-0.3%) from 74.172%
14906456369

push

github

web-flow
Add support for aliases in traits (#235)

* fix CI for test on nightly stdlib

* add support for aliases in traits

* update changelog

4 of 19 new or added lines in 4 files covered. (21.05%)

2379 of 3221 relevant lines covered (73.86%)

48.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.12
/internal/document/paths.go
1
package document
2

3
import (
4
        "strings"
5
)
6

7
type elemPath struct {
8
        Elements  []string
9
        Kind      string
10
        IsSection bool
11
}
12

13
type addPathFunc = func(Named, []string, []string, string, bool)
14

15
type pathHelper struct {
16
        AddPathFunc addPathFunc
17
        SetLink     bool
18
}
19

20
// Collects lookup for link target paths.
21
// Runs on the re-structured package.
22
func (proc *Processor) collectPaths() {
10✔
23
        pc := pathHelper{
10✔
24
                AddPathFunc: proc.addLinkTarget,
10✔
25
                SetLink:     false,
10✔
26
        }
10✔
27
        pc.collectPathsPackage(proc.ExportDocs.Decl, []string{}, []string{})
10✔
28
}
10✔
29

30
// Collects the paths of all (sub)-elements in the original structure.
31
func (proc *Processor) collectElementPaths() {
12✔
32
        pc := pathHelper{
12✔
33
                AddPathFunc: proc.addElementPath,
12✔
34
                SetLink:     true,
12✔
35
        }
12✔
36
        pc.collectPathsPackage(proc.Docs.Decl, []string{}, []string{})
12✔
37
}
12✔
38

39
func (pc *pathHelper) collectPathsPackage(p *Package, elems []string, pathElem []string) {
36✔
40
        newElems := appendNew(elems, p.GetName())
36✔
41
        newPath := appendNew(pathElem, p.GetFileName())
36✔
42
        if pc.SetLink {
56✔
43
                p.SetLink(newElems, p.Kind)
20✔
44
        }
20✔
45
        pc.AddPathFunc(p, newElems, newPath, "package", false)
36✔
46

36✔
47
        for _, pkg := range p.Packages {
50✔
48
                pc.collectPathsPackage(pkg, newElems, newPath)
14✔
49
        }
14✔
50
        for _, mod := range p.Modules {
80✔
51
                pc.collectPathsModule(mod, newElems, newPath)
44✔
52
        }
44✔
53

54
        for _, e := range p.Structs {
42✔
55
                pc.collectPathsStruct(e, newElems, newPath)
6✔
56
        }
6✔
57

58
        for _, e := range p.Traits {
41✔
59
                pc.collectPathsTrait(e, newElems, newPath)
5✔
60
        }
5✔
61
        for _, e := range p.Aliases {
46✔
62
                newElems := appendNew(newElems, e.GetName())
10✔
63
                newPath := appendNew(newPath, "#aliases")
10✔
64
                pc.AddPathFunc(e, newElems, newPath, "package", true) // kind=package for correct link paths
10✔
65
        }
10✔
66
        for _, e := range p.Functions {
41✔
67
                if pc.SetLink {
5✔
68
                        e.SetLink(newElems, e.Kind)
×
69
                }
×
70
                newElems := appendNew(newElems, e.GetName())
5✔
71
                newPath := appendNew(newPath, e.GetFileName())
5✔
72
                pc.AddPathFunc(e, newElems, newPath, "function", false)
5✔
73
        }
74
}
75

76
func (pc *pathHelper) collectPathsModule(m *Module, elems []string, pathElem []string) {
44✔
77
        newElems := appendNew(elems, m.GetName())
44✔
78
        newPath := appendNew(pathElem, m.GetFileName())
44✔
79
        if pc.SetLink {
73✔
80
                m.SetLink(newElems, m.Kind)
29✔
81
        }
29✔
82
        pc.AddPathFunc(m, newElems, newPath, "module", false)
44✔
83

44✔
84
        for _, e := range m.Structs {
86✔
85
                pc.collectPathsStruct(e, newElems, newPath)
42✔
86
        }
42✔
87
        for _, e := range m.Traits {
57✔
88
                pc.collectPathsTrait(e, newElems, newPath)
13✔
89
        }
13✔
90
        for _, e := range m.Aliases {
74✔
91
                newElems := appendNew(newElems, e.GetName())
30✔
92
                newPath := appendNew(newPath, "#aliases")
30✔
93
                pc.AddPathFunc(e, newElems, newPath, "module", true) // kind=module for correct link paths
30✔
94
        }
30✔
95
        for _, f := range m.Functions {
57✔
96
                if pc.SetLink {
23✔
97
                        f.SetLink(newElems, f.Kind)
10✔
98
                }
10✔
99
                newElems := appendNew(newElems, f.GetName())
13✔
100
                newPath := appendNew(newPath, f.GetFileName())
13✔
101
                pc.AddPathFunc(f, newElems, newPath, "function", false)
13✔
102
        }
103
}
104

105
func (pc *pathHelper) collectPathsStruct(s *Struct, elems []string, pathElem []string) {
48✔
106
        newElems := appendNew(elems, s.GetName())
48✔
107
        newPath := appendNew(pathElem, s.GetFileName())
48✔
108
        if pc.SetLink {
77✔
109
                s.SetLink(elems, s.Kind)
29✔
110
        }
29✔
111
        pc.AddPathFunc(s, newElems, newPath, "struct", false)
48✔
112

48✔
113
        for _, e := range s.Aliases {
83✔
114
                newElems := appendNew(newElems, e.GetName())
35✔
115
                newPath := appendNew(newPath, "#aliases")
35✔
116
                pc.AddPathFunc(e, newElems, newPath, "member", true)
35✔
117
        }
35✔
118
        for _, e := range s.Parameters {
73✔
119
                newElems := appendNew(newElems, e.GetName())
25✔
120
                newPath := appendNew(newPath, "#parameters")
25✔
121
                pc.AddPathFunc(e, newElems, newPath, "member", true)
25✔
122
        }
25✔
123
        for _, e := range s.Fields {
75✔
124
                newElems := appendNew(newElems, e.GetName())
27✔
125
                newPath := appendNew(newPath, "#fields")
27✔
126
                pc.AddPathFunc(e, newElems, newPath, "member", true)
27✔
127
        }
27✔
128
        for _, e := range s.Functions {
95✔
129
                newElems := appendNew(newElems, e.GetName())
47✔
130
                newPath := appendNew(newPath, "#"+strings.ToLower(e.GetName()))
47✔
131
                pc.AddPathFunc(e, newElems, newPath, "member", true)
47✔
132
        }
47✔
133
}
134

135
func (pc *pathHelper) collectPathsTrait(t *Trait, elems []string, pathElem []string) {
18✔
136
        newElems := appendNew(elems, t.GetName())
18✔
137
        newPath := appendNew(pathElem, t.GetFileName())
18✔
138
        if pc.SetLink {
28✔
139
                t.SetLink(elems, t.Kind)
10✔
140
        }
10✔
141
        pc.AddPathFunc(t, newElems, newPath, "trait", false)
18✔
142

18✔
143
        for _, e := range t.Aliases {
18✔
NEW
144
                newElems := appendNew(newElems, e.GetName())
×
NEW
145
                newPath := appendNew(newPath, "#aliases")
×
NEW
146
                pc.AddPathFunc(e, newElems, newPath, "member", true)
×
NEW
147
        }
×
148
        for _, e := range t.Fields {
21✔
149
                newElems := appendNew(newElems, e.GetName())
3✔
150
                newPath := appendNew(newPath, "#fields")
3✔
151
                pc.AddPathFunc(e, newElems, newPath, "member", true)
3✔
152
        }
3✔
153
        for _, e := range t.Functions {
43✔
154
                newElems := appendNew(newElems, e.GetName())
25✔
155
                newPath := appendNew(newPath, "#"+strings.ToLower(e.GetName()))
25✔
156
                pc.AddPathFunc(e, newElems, newPath, "member", true)
25✔
157
        }
25✔
158
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc