Repository navigation
Expand file tree
/
Copy pathwalk_test.go
More file actions
71 lines (66 loc) · 1.51 KB
/
Copy pathwalk_test.go
File metadata and controls
71 lines (66 loc) · 1.51 KB
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
71
package dbmeta_test
import (
"testing"
"github.com/xo/dbmeta"
)
func TestLike(t *testing.T) {
t.Parallel()
for _, c := range []struct {
pattern, s string
want bool
}{
{"", "anything", true},
{"book", "book", true},
{"book", "books", false},
{"bo%", "book", true},
{"%ok", "book", true},
{"b_ok", "book", true},
{"b_ok", "bok", false},
{"%", "", true},
{"a%b%c", "axxbyyc", true},
{"a%b%c", "axxbyy", false},
{`db\_x`, "db_x", true},
{`db\_x`, "dbax", false},
} {
if got := dbmeta.Like(c.pattern, c.s); got != c.want {
t.Errorf("Like(%q, %q) = %v, want %v", c.pattern, c.s, got, c.want)
}
}
}
func TestLikeFold(t *testing.T) {
t.Parallel()
for _, c := range []struct {
pattern, s string
want bool
}{
{"", "Anything", true},
{"BOOK", "book", true},
{"bo%", "BOOK", true},
{"b_OK", "Book", true},
{`DB\_x`, "db_X", true},
{`DB\_x`, "dbaX", false},
{"book", "books", false},
} {
if got := dbmeta.LikeFold(c.pattern, c.s); got != c.want {
t.Errorf("LikeFold(%q, %q) = %v, want %v", c.pattern, c.s, got, c.want)
}
}
}
func TestListHas(t *testing.T) {
t.Parallel()
for _, c := range []struct {
list, word string
want bool
}{
{"", "table", true},
{"table", "table", true},
{"table,view", "view", true},
{"table,view", "views", false},
{"table,view", "tab", false},
{"table, view", "view", false},
} {
if got := dbmeta.ListHas(c.list, c.word); got != c.want {
t.Errorf("ListHas(%q, %q) = %v, want %v", c.list, c.word, got, c.want)
}
}
}