Debian Codegraph @

resolve_test.go

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 package dots
2
3 import (
4 "path/filepath"
5 "strings"
6 "testing"
7 )
8
9 func TestResolveNoArgs(t *testing.T) {
10 result, err := Resolve([]string{}, []string{})
11 if err != nil {
12 t.Fatal(err)
13 }
14 if len(result) != 0 {
15 t.Errorf("Matched different number of files: got=%v, want=0", len(result))
16 }
17 }
18
19 func TestResolve(t *testing.T) {
20 result, err := Resolve([]string{"fixtures/dummy/..."}, []string{"fixtures/dummy/foo", "fixtures/dummy/UNKNOWN"})
21
22 files := []string{
23 filepath.FromSlash("fixtures/dummy/bar/bar1.go"),
24 filepath.FromSlash("fixtures/dummy/bar/bar2.go"),
25 filepath.FromSlash("fixtures/dummy/baz/baz1.go"),
26 filepath.FromSlash("fixtures/dummy/baz/baz2.go"),
27 filepath.FromSlash("fixtures/dummy/baz/baz3.go"),
28 }
29
30 if err != nil {
31 t.Fatal(err)
32 }
33 if len(result) != len(files) {
34 t.Fatalf("Matched different number of files: got=%v, want=%v", len(result), len(files))
35 }
36 for _, r := range result {
37 matched := false
38 for _, e := range files {
39 matched = matched || strings.HasSuffix(r, e)
40 }
41 if !matched {
42 t.Errorf("Not supposed to match: %v", r)
43 }
44 }
45 }
46
47 func TestResolveTests(t *testing.T) {
48 result, err := Resolve([]string{"fixtures/withtests/..."}, []string{})
49
50 files := []string{
51 filepath.FromSlash("fixtures/withtests/gofile.go"),
52 filepath.FromSlash("fixtures/withtests/testgo_test.go"),
53 filepath.FromSlash("fixtures/withtests/xtestgo_test.go"),
54 }
55
56 if err != nil {
57 t.Fatal(err)
58 }
59 if len(result) != len(files) {
60 t.Fatalf("Matched different number of files: got=%v, want=%v", len(result), len(files))
61 }
62 for _, r := range result {
63 matched := false
64 for _, e := range files {
65 matched = matched || strings.HasSuffix(r, e)
66 }
67 if !matched {
68 t.Errorf("Not supposed to match: %v", r)
69 }
70 }
71 }
72
73 func TestPackageResolve(t *testing.T) {
74 result, err := Resolve([]string{"github.com/mgechev/dots"}, []string{"resolve_test.go"})
75
76 files := []string{
77 "resolve.go",
78 }
79
80 if err != nil {
81 t.Fatal(err)
82 }
83 if len(result) != len(files) {
84 t.Fatalf("Matched different number of files: got=%v, want=%v", len(result), len(files))
85 }
86 for _, r := range result {
87 matched := false
88 for _, e := range files {
89 matched = matched || strings.HasSuffix(r, e)
90 }
91 if !matched {
92 t.Errorf("Not supposed to match: %v", r)
93 }
94 }
95 }
96
97 func TestSkipWildcard(t *testing.T) {
98 result, err := Resolve([]string{"fixtures/dummy/"}, []string{"fixtures/dummy/..."})
99
100 files := map[string]bool{}
101
102 if err != nil {
103 t.Fatal(err)
104 }
105 if len(result) != len(files) {
106 t.Fatalf("Matched different number of files: got=%v, want=%v", len(result), len(files))
107 }
108 }
109
110 func TestPackageWildcard(t *testing.T) {
111 result, err := Resolve([]string{"github.com/mgechev/dots/fixtures/pkg/foo/...", "github.com/mgechev/dots/fixtures/pkg/baz"}, []string{})
112 files := []string{
113 "baz1.go",
114 "baz2.go",
115 }
116
117 if err != nil {
118 t.Fatal(err)
119 }
120 if len(result) != len(files) {
121 t.Fatalf("Matched different number of files: got=%v, want=%v", len(result), len(files))
122 }
123 for _, r := range result {
124 matched := false
125 for _, e := range files {
126 matched = matched || strings.HasSuffix(r, e)
127 }
128 if !matched {
129 t.Errorf("Not supposed to match: %v", r)
130 }
131 }
132 }
133
134 func TestPackageWildcardWithSkip(t *testing.T) {
135 result, err := Resolve([]string{"github.com/mgechev/dots/fixtures/pkg/baz"}, []string{"github.com/mgechev/dots/fixtures/pkg/foo/..."})
136
137 files := []string{
138 "baz1.go",
139 "baz2.go",
140 }
141
142 if err != nil {
143 t.Fatal(err)
144 }
145 if len(result) != len(files) {
146 t.Fatalf("Matched different number of files: got=%v, want=%v", len(result), len(files))
147 }
148 for _, r := range result {
149 matched := false
150 for _, e := range files {
151 matched = matched || strings.HasSuffix(r, e)
152 }
153 if !matched {
154 t.Errorf("Not supposed to match: %v", r)
155 }
156 }
157 }
158
159 func TestComplainForMissingDirectories(t *testing.T) {
160 _, err := Resolve([]string{"./fixturess"}, []string{})
161
162 if err == nil {
163 t.Error("Should get an error")
164 }
165 }
166
167 func TestComplainForMissingPackages(t *testing.T) {
168 _, err := Resolve([]string{"github.com/mgechev/bazbaz"}, []string{})
169
170 if err == nil {
171 t.Error("Should get an error")
172 }
173 }
174
175 func TestResolvePackages(t *testing.T) {
176 result, err := ResolvePackages([]string{"github.com/mgechev/dots/fixtures/pkg/foo/...", "github.com/mgechev/dots/fixtures/pkg/baz"}, []string{})
177 if err != nil {
178 t.Fatal(err)
179 }
180 if len(result) != 1 {
181 t.Fatalf("Matched different number of files: got=%v, want=%v", len(result), 1)
182 }
183 for _, pkg := range result {
184 if len(pkg) == 0 {
185 t.Error("Empty package")
186 }
187 }
188 }