-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser_test.go
64 lines (52 loc) · 1.39 KB
/
parser_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
55
56
57
58
59
60
61
62
63
64
package todo
import (
"os"
"testing"
)
func assertEqual(t *testing.T, expected interface{}, value interface{}, msg string) bool {
if value != expected {
t.Errorf("%s: got %v but expected %v", msg, value, expected)
return false
}
return true
}
func TestImportPkg(t *testing.T) {
// Standard package
pkg, err := importPkg("fmt", "")
if err != nil {
t.Fatal("err should be nil")
}
assertEqual(t, "fmt", pkg.Name, "the wrong package was imported")
// Command package
_, err = importPkg("cmd/go", "")
if err == nil {
t.Error(err)
}
// Non-existing package
_, err = importPkg("", "")
if err == nil {
t.Error(err)
}
}
func TestExtractPattern(t *testing.T) {
// TODO: Comment used for testing
comments, err := extractPattern("parser_test.go", "TODO")
if err != nil {
// If no comment was extracted, don't execute the following tests
t.Fatal(err)
}
if !assertEqual(t, 1, len(comments), "retrieved an invalid number of comments") {
return
}
assertEqual(t, "parser_test.go", comments[0].Filename, "invalid filename")
assertEqual(t, "TODO: Comment used for testing\n", comments[0].Text, "invalid comment text")
}
func TestCommentsParse(t *testing.T) {
var comments Comments
workdir, _ := os.Getwd()
err := comments.Parse("fmt", workdir, "TODO")
if err != nil {
t.Fatal("err should be nil")
}
// The implementation is already tested by TestImportPkg and TestExtractPattern
}