-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_test.go
70 lines (68 loc) · 2.13 KB
/
new_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
65
66
67
68
69
70
package parser
import (
"github.com/mathbalduino/go-log/loggerCLI"
"go/token"
"testing"
)
func TestNewGoParser(t *testing.T) {
t.Run("Should return errors of packages.Load", func(t *testing.T) {
p, e := NewGoParser("wrongpattern=", Config{})
if e == nil {
t.Fatalf("The packages.Load error was expected to be returned")
}
if p != nil {
t.Fatalf("When there's errors, the GoParser should be nil")
}
})
t.Run("Should return a valid GoParser and nil error", func(t *testing.T) {
p, e := NewGoParser("--inexistentPackage--", Config{})
if e != nil {
t.Fatalf("The error was expected to be nil")
}
if p == nil {
t.Fatalf("GoParser expected to be not nil")
}
})
t.Run("The returned GoParser pkgs, focus, log (given by the user) and fileSet fields should be filled", func(t *testing.T) {
logger := loggerCLI.New(false, 0)
config := Config{Focus: &Focus{}, Fset: token.NewFileSet(), Logger: logger}
p, _ := NewGoParser("--inexistentPackage--", config)
if p == nil {
t.Fatalf("GoParser expected to be not nil")
}
if p.pkgs == nil {
t.Fatalf("GoParser.pkgs expected to be not nil")
}
if p.focus != config.Focus {
t.Fatalf("GoParser.focus expected to be equal to config.Focus")
}
if p.logger == nil {
t.Fatalf("GoParser.log expected to not be nil")
}
if p.logger != logger {
t.Fatalf("GoParser.log expected to not be nil")
}
if p.fileSet != config.Fset {
t.Fatalf("GoParser.fileSet expected to be equal to config.Fset")
}
})
t.Run("The returned GoParser pkgs, focus, log (dynamically created) and fileSet fields should be filled", func(t *testing.T) {
config := Config{Focus: &Focus{}, Fset: token.NewFileSet()}
p, _ := NewGoParser("--inexistentPackage--", config)
if p == nil {
t.Fatalf("GoParser expected to be not nil")
}
if p.pkgs == nil {
t.Fatalf("GoParser.pkgs expected to be not nil")
}
if p.focus != config.Focus {
t.Fatalf("GoParser.focus expected to be equal to config.Focus")
}
if p.logger == nil {
t.Fatalf("GoParser.log expected to not be nil")
}
if p.fileSet != config.Fset {
t.Fatalf("GoParser.fileSet expected to be equal to config.Fset")
}
})
}