|
1 | 1 | package substring
|
2 | 2 |
|
3 |
| -import . "gopkg.in/check.v1" |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/matryer/is" |
| 7 | +) |
| 8 | + |
| 9 | +func TestBytesAny(t *testing.T) { |
| 10 | + is := is.New(t) |
4 | 11 |
|
5 |
| -func (s *LibSuite) TestBytesAny(c *C) { |
6 | 12 | a := BytesAny("foo") // search s in foo
|
7 |
| - c.Assert(a.MatchIndex([]byte("f")), Equals, 1) |
8 |
| - c.Assert(a.MatchIndex([]byte("foo")), Equals, 3) |
9 |
| - c.Assert(a.MatchIndex([]byte("foobar")), Equals, -1) |
10 |
| - c.Assert(a.MatchIndex([]byte("p")), Equals, -1) |
| 13 | + is.Equal(a.MatchIndex([]byte("f")), 1) |
| 14 | + is.Equal(a.MatchIndex([]byte("foo")), 3) |
| 15 | + is.Equal(a.MatchIndex([]byte("foobar")), -1) |
| 16 | + is.Equal(a.MatchIndex([]byte("p")), -1) |
11 | 17 | }
|
12 | 18 |
|
13 |
| -func (s *LibSuite) TestBytesHas(c *C) { |
| 19 | +func TestBytesHas(t *testing.T) { |
| 20 | + is := is.New(t) |
| 21 | + |
14 | 22 | h := BytesHas("foo") // search foo in s
|
15 |
| - c.Assert(h.MatchIndex([]byte("foo")), Equals, 3) |
16 |
| - c.Assert(h.MatchIndex([]byte("foobar")), Equals, 3) |
17 |
| - c.Assert(h.MatchIndex([]byte("f")), Equals, -1) |
| 23 | + is.Equal(h.MatchIndex([]byte("foo")), 3) |
| 24 | + is.Equal(h.MatchIndex([]byte("foobar")), 3) |
| 25 | + is.Equal(h.MatchIndex([]byte("f")), -1) |
18 | 26 | }
|
19 | 27 |
|
20 |
| -func (s *LibSuite) TestBytesPrefix(c *C) { |
| 28 | +func TestBytesPrefix(t *testing.T) { |
| 29 | + is := is.New(t) |
| 30 | + |
21 | 31 | p := BytesPrefix("foo")
|
22 |
| - c.Assert(p.Match([]byte("foo")), Equals, true) |
23 |
| - c.Assert(p.Match([]byte("foobar")), Equals, true) |
24 |
| - c.Assert(p.Match([]byte("barfoo")), Equals, false) |
25 |
| - c.Assert(p.Match([]byte(" foo")), Equals, false) |
26 |
| - c.Assert(p.Match([]byte("bar")), Equals, false) |
27 |
| - c.Assert(p.MatchIndex([]byte("foo")), Equals, 3) |
28 |
| - c.Assert(p.MatchIndex([]byte("foobar")), Equals, 3) |
29 |
| - c.Assert(p.MatchIndex([]byte("barfoo")), Equals, -1) |
30 |
| - c.Assert(p.MatchIndex([]byte(" foo")), Equals, -1) |
31 |
| - c.Assert(p.MatchIndex([]byte("bar")), Equals, -1) |
| 32 | + is.True(p.Match([]byte("foo"))) |
| 33 | + is.True(p.Match([]byte("foobar"))) |
| 34 | + is.Equal(p.Match([]byte("barfoo")), false) |
| 35 | + is.Equal(p.Match([]byte(" foo")), false) |
| 36 | + is.Equal(p.Match([]byte("bar")), false) |
| 37 | + is.Equal(p.MatchIndex([]byte("foo")), 3) |
| 38 | + is.Equal(p.MatchIndex([]byte("foobar")), 3) |
| 39 | + is.Equal(p.MatchIndex([]byte("barfoo")), -1) |
| 40 | + is.Equal(p.MatchIndex([]byte(" foo")), -1) |
| 41 | + is.Equal(p.MatchIndex([]byte("bar")), -1) |
32 | 42 | ps := BytesPrefixes("foo", "barfoo")
|
33 |
| - c.Assert(ps.Match([]byte("foo")), Equals, true) |
34 |
| - c.Assert(ps.Match([]byte("barfoo")), Equals, true) |
35 |
| - c.Assert(ps.Match([]byte("qux")), Equals, false) |
36 |
| - c.Assert(ps.MatchIndex([]byte("foo")), Equals, 2) |
37 |
| - c.Assert(ps.MatchIndex([]byte("barfoo")), Equals, 5) |
38 |
| - c.Assert(ps.MatchIndex([]byte("qux")), Equals, -1) |
| 43 | + is.True(ps.Match([]byte("foo"))) |
| 44 | + is.True(ps.Match([]byte("barfoo"))) |
| 45 | + is.Equal(ps.Match([]byte("qux")), false) |
| 46 | + is.Equal(ps.MatchIndex([]byte("foo")), 2) |
| 47 | + is.Equal(ps.MatchIndex([]byte("barfoo")), 5) |
| 48 | + is.Equal(ps.MatchIndex([]byte("qux")), -1) |
39 | 49 | }
|
40 | 50 |
|
41 |
| -func (s *LibSuite) TestBytesSuffix(c *C) { |
| 51 | +func TestBytesSuffix(t *testing.T) { |
| 52 | + is := is.New(t) |
| 53 | + |
42 | 54 | p := BytesSuffix("foo")
|
43 |
| - c.Assert(p.Match([]byte("foo")), Equals, true) |
44 |
| - c.Assert(p.Match([]byte("barfoo")), Equals, true) |
45 |
| - c.Assert(p.Match([]byte("foobar")), Equals, false) |
46 |
| - c.Assert(p.Match([]byte("foo ")), Equals, false) |
47 |
| - c.Assert(p.Match([]byte("bar")), Equals, false) |
48 |
| - c.Assert(p.MatchIndex([]byte("foo")), Equals, 3) |
49 |
| - c.Assert(p.MatchIndex([]byte("barfoo")), Equals, 3) |
50 |
| - c.Assert(p.MatchIndex([]byte("foobar")), Equals, -1) |
51 |
| - c.Assert(p.MatchIndex([]byte("foo ")), Equals, -1) |
52 |
| - c.Assert(p.MatchIndex([]byte("bar")), Equals, -1) |
| 55 | + is.True(p.Match([]byte("foo"))) |
| 56 | + is.True(p.Match([]byte("barfoo"))) |
| 57 | + is.Equal(p.Match([]byte("foobar")), false) |
| 58 | + is.Equal(p.Match([]byte("foo ")), false) |
| 59 | + is.Equal(p.Match([]byte("bar")), false) |
| 60 | + is.Equal(p.MatchIndex([]byte("foo")), 3) |
| 61 | + is.Equal(p.MatchIndex([]byte("barfoo")), 3) |
| 62 | + is.Equal(p.MatchIndex([]byte("foobar")), -1) |
| 63 | + is.Equal(p.MatchIndex([]byte("foo ")), -1) |
| 64 | + is.Equal(p.MatchIndex([]byte("bar")), -1) |
53 | 65 | ps := BytesSuffixes("foo", "foobar")
|
54 |
| - c.Assert(ps.Match([]byte("foo")), Equals, true) |
55 |
| - c.Assert(ps.Match([]byte("foobar")), Equals, true) |
56 |
| - c.Assert(ps.Match([]byte("qux")), Equals, false) |
57 |
| - c.Assert(ps.MatchIndex([]byte("foo")), Equals, 2) |
58 |
| - c.Assert(ps.MatchIndex([]byte("foobar")), Equals, 5) |
59 |
| - c.Assert(ps.MatchIndex([]byte("qux")), Equals, -1) |
| 66 | + is.True(ps.Match([]byte("foo"))) |
| 67 | + is.True(ps.Match([]byte("foobar"))) |
| 68 | + is.Equal(ps.Match([]byte("qux")), false) |
| 69 | + is.Equal(ps.MatchIndex([]byte("foo")), 2) |
| 70 | + is.Equal(ps.MatchIndex([]byte("foobar")), 5) |
| 71 | + is.Equal(ps.MatchIndex([]byte("qux")), -1) |
60 | 72 | ps2 := BytesSuffixes(".foo", ".bar", ".qux")
|
61 |
| - c.Assert(ps2.Match([]byte("bar.foo")), Equals, true) |
62 |
| - c.Assert(ps2.Match([]byte("bar.js")), Equals, false) |
63 |
| - c.Assert(ps2.Match([]byte("foo/foo.bar")), Equals, true) |
64 |
| - c.Assert(ps2.Match([]byte("foo/foo.js")), Equals, false) |
65 |
| - c.Assert(ps2.Match([]byte("foo/foo/bar.qux")), Equals, true) |
66 |
| - c.Assert(ps2.Match([]byte("foo/foo/bar.css")), Equals, false) |
| 73 | + is.True(ps2.Match([]byte("bar.foo"))) |
| 74 | + is.Equal(ps2.Match([]byte("bar.js")), false) |
| 75 | + is.True(ps2.Match([]byte("foo/foo.bar"))) |
| 76 | + is.Equal(ps2.Match([]byte("foo/foo.js")), false) |
| 77 | + is.True(ps2.Match([]byte("foo/foo/bar.qux"))) |
| 78 | + is.Equal(ps2.Match([]byte("foo/foo/bar.css")), false) |
67 | 79 | }
|
68 | 80 |
|
69 |
| -func (s *LibSuite) TestBytesExact(c *C) { |
| 81 | +func TestBytesExact(t *testing.T) { |
| 82 | + is := is.New(t) |
| 83 | + |
70 | 84 | a := BytesExact("foo")
|
71 |
| - c.Assert(a.Match([]byte("foo")), Equals, true) |
72 |
| - c.Assert(a.Match([]byte("bar")), Equals, false) |
73 |
| - c.Assert(a.Match([]byte("qux")), Equals, false) |
| 85 | + is.True(a.Match([]byte("foo"))) |
| 86 | + is.Equal(a.Match([]byte("bar")), false) |
| 87 | + is.Equal(a.Match([]byte("qux")), false) |
74 | 88 | }
|
75 | 89 |
|
76 |
| -func (s *LibSuite) TestBytesAfter(c *C) { |
| 90 | +func TestBytesAfter(t *testing.T) { |
| 91 | + is := is.New(t) |
| 92 | + |
77 | 93 | a1 := BytesAfter("foo", BytesExact("bar"))
|
78 |
| - c.Assert(a1.Match([]byte("foobar")), Equals, true) |
79 |
| - c.Assert(a1.Match([]byte("foo_bar")), Equals, false) |
| 94 | + is.True(a1.Match([]byte("foobar"))) |
| 95 | + is.Equal(a1.Match([]byte("foo_bar")), false) |
80 | 96 | a2 := BytesAfter("foo", BytesHas("bar"))
|
81 |
| - c.Assert(a2.Match([]byte("foobar")), Equals, true) |
82 |
| - c.Assert(a2.Match([]byte("foo_bar")), Equals, true) |
83 |
| - c.Assert(a2.Match([]byte("_foo_bar")), Equals, true) |
84 |
| - c.Assert(a2.Match([]byte("foo_nope")), Equals, false) |
85 |
| - c.Assert(a2.Match([]byte("qux")), Equals, false) |
| 97 | + is.True(a2.Match([]byte("foobar"))) |
| 98 | + is.True(a2.Match([]byte("foo_bar"))) |
| 99 | + is.True(a2.Match([]byte("_foo_bar"))) |
| 100 | + is.Equal(a2.Match([]byte("foo_nope")), false) |
| 101 | + is.Equal(a2.Match([]byte("qux")), false) |
86 | 102 | a3 := BytesAfter("foo", BytesPrefixes("bar", "qux"))
|
87 |
| - c.Assert(a3.Match([]byte("foobar")), Equals, true) |
88 |
| - c.Assert(a3.Match([]byte("fooqux")), Equals, true) |
89 |
| - c.Assert(a3.Match([]byte("foo bar")), Equals, false) |
90 |
| - c.Assert(a3.Match([]byte("foo_qux")), Equals, false) |
| 103 | + is.True(a3.Match([]byte("foobar"))) |
| 104 | + is.True(a3.Match([]byte("fooqux"))) |
| 105 | + is.Equal(a3.Match([]byte("foo bar")), false) |
| 106 | + is.Equal(a3.Match([]byte("foo_qux")), false) |
91 | 107 | }
|
92 | 108 |
|
93 |
| -func (s *LibSuite) TestBytesSuffixGroup(c *C) { |
| 109 | +func TestBytesSuffixGroup(t *testing.T) { |
| 110 | + is := is.New(t) |
| 111 | + |
94 | 112 | sg1 := BytesSuffixGroup(".foo", BytesHas("bar"))
|
95 |
| - c.Assert(sg1.Match([]byte("bar.foo")), Equals, true) |
96 |
| - c.Assert(sg1.Match([]byte("barqux.foo")), Equals, true) |
97 |
| - c.Assert(sg1.Match([]byte(".foo.bar")), Equals, false) |
| 113 | + is.True(sg1.Match([]byte("bar.foo"))) |
| 114 | + is.True(sg1.Match([]byte("barqux.foo"))) |
| 115 | + is.Equal(sg1.Match([]byte(".foo.bar")), false) |
98 | 116 | sg2 := BytesSuffixGroup(`.foo`,
|
99 | 117 | BytesAfter(`bar`, BytesHas("qux")),
|
100 | 118 | )
|
101 |
| - c.Assert(sg2.Match([]byte("barqux.foo")), Equals, true) |
102 |
| - c.Assert(sg2.Match([]byte("barbarqux.foo")), Equals, true) |
103 |
| - c.Assert(sg2.Match([]byte("bar.foo")), Equals, false) |
104 |
| - c.Assert(sg2.Match([]byte("foo.foo")), Equals, false) |
| 119 | + is.True(sg2.Match([]byte("barqux.foo"))) |
| 120 | + is.True(sg2.Match([]byte("barbarqux.foo"))) |
| 121 | + is.Equal(sg2.Match([]byte("bar.foo")), false) |
| 122 | + is.Equal(sg2.Match([]byte("foo.foo")), false) |
105 | 123 | sg3 := BytesSuffixGroup(`.foo`,
|
106 | 124 | BytesAfter(`bar`, BytesRegexp(`\d+`)),
|
107 | 125 | )
|
108 |
| - c.Assert(sg3.Match([]byte("bar0.foo")), Equals, true) |
109 |
| - c.Assert(sg3.Match([]byte("bar.foo")), Equals, false) |
110 |
| - c.Assert(sg3.Match([]byte("bar0.qux")), Equals, false) |
| 126 | + is.True(sg3.Match([]byte("bar0.foo"))) |
| 127 | + is.Equal(sg3.Match([]byte("bar.foo")), false) |
| 128 | + is.Equal(sg3.Match([]byte("bar0.qux")), false) |
111 | 129 | }
|
0 commit comments