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

mlange-42 / modo / 12737935283

12 Jan 2025 11:14PM CUT coverage: 24.557%. Remained the same
12737935283

Pull #26

github

web-flow
Merge fdc77f32e into ee3165c19
Pull Request #26: Add CI tests on stable and nightly

97 of 395 relevant lines covered (24.56%)

1.28 hits per line

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

69.61
/document/document.go
1
package document
2

3
import (
4
        "bytes"
5
        "encoding/json"
6
        "fmt"
7
        "strings"
8
        "unicode"
9
)
10

11
const capitalFileMarker = "-"
12

13
var CaseSensitiveSystem = true
14

15
type Docs struct {
16
        Decl    *Package
17
        Version string
18
}
19

20
type Package struct {
21
        MemberKind
22
        MemberName
23
        Description string
24
        Summary     string
25
        Modules     []*Module
26
        Packages    []*Package
27
}
28

29
type Module struct {
30
        MemberKind
31
        MemberName
32
        Summary     string
33
        Description string
34
        Aliases     []*Alias
35
        Functions   []*Function
36
        Structs     []*Struct
37
        Traits      []*Trait
38
}
39

40
type Alias struct {
41
        MemberKind
42
        MemberName
43
        Description string
44
        Summary     string
45
        Value       string
46
        Deprecated  string
47
}
48

49
type Struct struct {
50
        MemberKind
51
        MemberName
52
        Description  string
53
        Summary      string
54
        Aliases      []*Alias
55
        Constraints  string
56
        Convention   string
57
        Deprecated   string
58
        Fields       []*Field
59
        Functions    []*Function
60
        Parameters   []*Parameter
61
        ParentTraits []string
62
        Signature    string
63
}
64

65
type Function struct {
66
        MemberKind
67
        MemberName
68
        Description          string
69
        Summary              string
70
        Args                 []*Arg
71
        Overloads            []*Function
72
        Async                bool
73
        Constraints          string
74
        Deprecated           string
75
        IsDef                bool
76
        IsStatic             bool
77
        IsImplicitConversion bool
78
        Raises               bool
79
        RaisesDoc            string
80
        ReturnType           string
81
        ReturnsDoc           string
82
        Signature            string
83
        Parameters           []*Parameter
84
}
85

86
type Field struct {
87
        MemberKind
88
        MemberName
89
        Description string
90
        Summary     string
91
        Type        string
92
}
93

94
type Trait struct {
95
        MemberKind
96
        MemberName
97
        Description  string
98
        Summary      string
99
        Fields       []*Field
100
        Functions    []*Function
101
        ParentTraits []string
102
        Deprecated   string
103
}
104

105
type Arg struct {
106
        MemberKind
107
        MemberName
108
        Description string
109
        Convention  string
110
        Type        string
111
        PassingKind string
112
        Default     string
113
}
114

115
type Parameter struct {
116
        MemberKind
117
        MemberName
118
        Description string
119
        Type        string
120
        PassingKind string
121
        Default     string
122
}
123

124
func FromJson(data []byte) (*Docs, error) {
1✔
125
        reader := bytes.NewReader(data)
1✔
126
        dec := json.NewDecoder(reader)
1✔
127
        dec.DisallowUnknownFields()
1✔
128

1✔
129
        var docs Docs
1✔
130

1✔
131
        if err := dec.Decode(&docs); err != nil {
1✔
132
                return nil, err
×
133
        }
×
134

135
        cleanup(&docs)
1✔
136

1✔
137
        return &docs, nil
1✔
138
}
139

140
func cleanup(doc *Docs) {
2✔
141
        cleanupPackage(doc.Decl)
2✔
142
}
2✔
143

144
func cleanupPackage(p *Package) {
2✔
145
        for _, pp := range p.Packages {
2✔
146
                cleanupPackage(pp)
×
147
        }
×
148
        newModules := make([]*Module, 0, len(p.Modules))
2✔
149
        for _, m := range p.Modules {
4✔
150
                cleanupModule(m)
2✔
151
                if m.GetName() != "__init__" {
3✔
152
                        newModules = append(newModules, m)
1✔
153
                }
1✔
154
        }
155
        p.Modules = newModules
2✔
156
}
157

158
func cleanupModule(m *Module) {
2✔
159
        for _, s := range m.Structs {
2✔
160
                if s.Signature == "" {
×
161
                        s.Signature = createSignature(s)
×
162
                }
×
163
        }
164
}
165

166
func createSignature(s *Struct) string {
4✔
167
        b := strings.Builder{}
4✔
168
        b.WriteString("struct ")
4✔
169
        b.WriteString(s.GetName())
4✔
170

4✔
171
        if len(s.Parameters) == 0 {
4✔
172
                return b.String()
×
173
        }
×
174

175
        b.WriteString("[")
4✔
176

4✔
177
        prevKind := ""
4✔
178
        for i, par := range s.Parameters {
11✔
179
                written := false
7✔
180
                if par.PassingKind == "kw" && prevKind != par.PassingKind {
9✔
181
                        if i > 0 {
3✔
182
                                b.WriteString(", ")
1✔
183
                        }
1✔
184
                        b.WriteString("*")
2✔
185
                        written = true
2✔
186
                }
187
                if prevKind == "inferred" && par.PassingKind != prevKind {
8✔
188
                        b.WriteString(", //")
1✔
189
                        written = true
1✔
190
                }
1✔
191
                if prevKind == "pos" && par.PassingKind != prevKind {
8✔
192
                        b.WriteString(", /")
1✔
193
                        written = true
1✔
194
                }
1✔
195

196
                if i > 0 || written {
11✔
197
                        b.WriteString(", ")
4✔
198
                }
4✔
199

200
                b.WriteString(fmt.Sprintf("%s: %s", par.GetName(), par.Type))
7✔
201
                if len(par.Default) > 0 {
7✔
202
                        b.WriteString(fmt.Sprintf(" = %s", par.Default))
×
203
                }
×
204

205
                prevKind = par.PassingKind
7✔
206
        }
207
        if prevKind == "inferred" {
5✔
208
                b.WriteString(", //")
1✔
209
        }
1✔
210
        if prevKind == "pos" {
5✔
211
                b.WriteString(", /")
1✔
212
        }
1✔
213

214
        b.WriteString("]")
4✔
215

4✔
216
        return b.String()
4✔
217
}
218

219
type Kinded interface {
220
        GetKind() string
221
}
222

223
type Named interface {
224
        GetName() string
225
        GetFileName() string
226
}
227

228
type MemberKind struct {
229
        Kind string
230
}
231

232
func NewKind(kind string) MemberKind {
×
233
        return MemberKind{Kind: kind}
×
234
}
×
235

236
func (k *MemberKind) GetKind() string {
×
237
        return k.Kind
×
238
}
×
239

240
type MemberName struct {
241
        Name string
242
}
243

244
func NewName(name string) MemberName {
13✔
245
        return MemberName{Name: name}
13✔
246
}
13✔
247

248
func (k *MemberName) GetName() string {
13✔
249
        return k.Name
13✔
250
}
13✔
251

252
func (k *MemberName) GetFileName() string {
×
253
        if CaseSensitiveSystem {
×
254
                return k.Name
×
255
        }
×
256
        if isCap(k.Name) {
×
257
                return k.Name + capitalFileMarker
×
258
        }
×
259
        return k.Name
×
260
}
261

262
func isCap(s string) bool {
×
263
        if len(s) == 0 {
×
264
                return false
×
265
        }
×
266
        firstRune := []rune(s)[0]
×
267
        return unicode.IsUpper(firstRune)
×
268
}
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