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

mlange-42 / modo / 12865346682

20 Jan 2025 09:52AM UTC coverage: 60.673% (+4.0%) from 56.633%
12865346682

Pull #74

github

web-flow
Merge 113b12f91 into 7efbd21aa
Pull Request #74: Full file to file test

901 of 1485 relevant lines covered (60.67%)

22.3 hits per line

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

81.16
/document/processor.go
1
package document
2

3
import (
4
        "fmt"
5
        "log"
6
        "os"
7
        "strings"
8
        "text/template"
9
)
10

11
type Config struct {
12
        InputFile       string
13
        OutputDir       string
14
        TemplateDirs    []string
15
        UseExports      bool
16
        ShortLinks      bool
17
        CaseInsensitive bool
18
        Strict          bool
19
        DryRun          bool
20
}
21

22
type Processor struct {
23
        Config             *Config
24
        Template           *template.Template
25
        Formatter          Formatter
26
        Docs               *Docs
27
        ExportDocs         *Docs
28
        allPaths           map[string]bool
29
        linkTargets        map[string]elemPath
30
        linkExports        map[string]string
31
        linkExportsReverse map[string]*exportError
32
        writer             func(file, text string) error
33
}
34

35
func NewProcessor(docs *Docs, f Formatter, t *template.Template, config *Config) *Processor {
9✔
36
        return NewProcessorWithWriter(docs, f, t, config, func(file, text string) error {
16✔
37
                return os.WriteFile(file, []byte(text), 0666)
7✔
38
        })
7✔
39
}
40

41
func NewProcessorWithWriter(docs *Docs, f Formatter, t *template.Template, config *Config, writer func(file, text string) error) *Processor {
14✔
42
        return &Processor{
14✔
43
                Config:    config,
14✔
44
                Template:  t,
14✔
45
                Formatter: f,
14✔
46
                Docs:      docs,
14✔
47
                writer:    writer,
14✔
48
        }
14✔
49
}
14✔
50

51
// PrepareDocs processes the API docs for subsequent rendering.
52
func (proc *Processor) PrepareDocs() error {
6✔
53
        // Collect the paths of all (sub)-elements in the original structure.
6✔
54
        proc.collectElementPaths()
6✔
55

6✔
56
        // Re-structure according to exports.
6✔
57
        err := proc.filterPackages()
6✔
58
        if err != nil {
6✔
59
                return err
×
60
        }
×
61
        // Collect all link target paths.
62
        proc.collectPaths()
6✔
63
        if !proc.Config.UseExports {
9✔
64
                for k := range proc.linkTargets {
16✔
65
                        proc.linkExports[k] = k
13✔
66
                }
13✔
67
        }
68
        // Replaces cross-refs by placeholders.
69
        if err := proc.processLinksPackage(proc.Docs.Decl, []string{}); err != nil {
6✔
70
                return err
×
71
        }
×
72
        return nil
6✔
73
}
74

75
func (proc *Processor) WriteFile(file, text string) error {
29✔
76
        return proc.writer(file, text)
29✔
77
}
29✔
78

79
func (proc *Processor) warnOrError(pattern string, args ...any) error {
×
80
        if proc.Config.Strict {
×
81
                return fmt.Errorf(pattern, args...)
×
82
        }
×
83
        log.Printf("WARNING: "+pattern+"\n", args...)
×
84
        return nil
×
85
}
86

87
func (proc *Processor) addLinkExport(oldPath, newPath []string) {
64✔
88
        pNew := strings.Join(newPath, ".")
64✔
89
        pOld := strings.Join(oldPath, ".")
64✔
90
        if present, ok := proc.linkExportsReverse[pNew]; ok {
64✔
91
                present.OldPaths = append(present.OldPaths, pOld)
×
92
        } else {
64✔
93
                proc.linkExportsReverse[pNew] = &exportError{
64✔
94
                        NewPath:  pNew,
64✔
95
                        OldPaths: []string{pOld},
64✔
96
                }
64✔
97
        }
64✔
98
        proc.linkExports[pOld] = pNew
64✔
99
}
100

101
func (proc *Processor) addLinkTarget(elPath, filePath []string, kind string, isSection bool) {
70✔
102
        proc.linkTargets[strings.Join(elPath, ".")] = elemPath{Elements: filePath, Kind: kind, IsSection: isSection}
70✔
103
}
70✔
104

105
func (proc *Processor) addElementPath(elPath, filePath []string, kind string, isSection bool) {
84✔
106
        if isSection && kind != "package" && kind != "module" { // actually, we are catching aliases here
109✔
107
                return
25✔
108
        }
25✔
109
        proc.allPaths[strings.Join(elPath, ".")] = true
59✔
110
        _, _ = filePath, kind
59✔
111
}
112

113
func (proc *Processor) mkDirs(path string) error {
14✔
114
        if proc.Config.DryRun {
17✔
115
                return nil
3✔
116
        }
3✔
117
        if err := os.MkdirAll(path, os.ModePerm); err != nil && !os.IsExist(err) {
11✔
118
                return err
×
119
        }
×
120
        return nil
11✔
121
}
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