-
Notifications
You must be signed in to change notification settings - Fork 0
/
delim_test.go
75 lines (69 loc) · 1.67 KB
/
delim_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
71
72
73
74
75
package beard
import (
"reflect"
"testing"
)
func Test_ldelim(t *testing.T) {
for _, v := range []struct {
giv string
del string
exp string
ma matchLevel
}{
{"hello {{c}}", "{{", "hello {{", exMatch},
{"hello {{{c}}}", "{{", "hello {{", exMatch},
{"hello {", "{{", "hello {", paMatch},
{"hello {", "{{{", "hello {", paMatch},
{"hello {{", "{{{", "hello {{", paMatch},
{"hello {c}", "{{", "hello {c}", noMatch},
{"hello {c}", "{{{", "hello {c}", noMatch},
{"hello {{c}}", "{{{", "hello {{c}}", noMatch},
} {
var exp = struct {
byt []byte
ma matchLevel
}{
[]byte(v.exp), v.ma,
}
byt, ma := (&Ldelim{[]byte(v.del)}).Match([]byte(v.giv))
if exp.ma != ma {
t.Errorf("expected a level %d match, got %d: %s %s",
exp.ma, ma, v.giv, v.del)
}
if !reflect.DeepEqual(exp.byt, byt) {
t.Errorf("expected %s, got %s", string(exp.byt), string(byt))
}
}
}
func Test_rdelim(t *testing.T) {
for _, v := range []struct {
giv string
del string
exp string
ma matchLevel
}{
{"c}}</h1>", "}}", "c}}", exMatch},
{"c}}}</h1>", "}}", "c}}", exMatch},
{"c}", "}}", "c}", paMatch},
{"c}", "}}}", "c}", paMatch},
{"c}}", "}}}", "c}}", paMatch},
{"c}</h1>", "}}", "c}</h1>", noMatch},
{"c}</h1>", "}}}", "c}</h1>", noMatch},
{"c}}</h1>", "}}}", "c}}</h1>", noMatch},
} {
var exp = struct {
byt []byte
ma matchLevel
}{
[]byte(v.exp), v.ma,
}
byt, ma := (&Rdelim{[]byte(v.del)}).Match([]byte(v.giv))
if exp.ma != ma {
t.Errorf("expected a level %d match, got %d: %s %s",
exp.ma, ma, v.giv, v.del)
}
if !reflect.DeepEqual(exp.byt, byt) {
t.Errorf("expected %s, got %s", string(exp.byt), string(byt))
}
}
}