-
Notifications
You must be signed in to change notification settings - Fork 24
/
sparse_test.go
54 lines (48 loc) · 895 Bytes
/
sparse_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package sparse
import (
"bufio"
"fmt"
"log"
"os"
"path/filepath"
"strings"
"testing"
)
func TestTodo(t *testing.T) {
// Show all to do`s in comment code
source, err := filepath.Glob(fmt.Sprintf("./%s", "*.go"))
if err != nil {
t.Fatal(err)
}
var amount int
for i := range source {
t.Run(source[i], func(t *testing.T) {
file, err := os.Open(source[i])
if err != nil {
t.Fatal(err)
}
defer file.Close()
pos := 0
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
pos++
index := strings.Index(line, "//")
if index < 0 {
continue
}
if !strings.Contains(line, "TODO") {
continue
}
t.Logf("%13s:%-4d %s", source[i], pos, line[index:])
amount++
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
})
}
if amount > 0 {
t.Logf("Amount TODO: %d", amount)
}
}