-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_map_analysis_test.go
114 lines (111 loc) · 3.19 KB
/
parse_map_analysis_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package f8n
import (
"net/http"
"strings"
"testing"
)
// Тестирование ошибок анализатора карты сложной фильтрации.
func TestAnalysis(t *testing.T) {
type (
test struct {
Data string
Error Err
}
)
var (
err error
obj *impl
tests []test
n int
rq *http.Request
ero Err
ok bool
)
obj = New().(*impl)
tests = []test{
{
Error: Errors().PairedTagNotMatch("", ""),
Data: `http://host?map=g1:or:g2):or:g3)&g1=f1:eq:v1&g2=f2:ke:v2&g3=f3:ke:v3`,
},
{
Error: Errors().PairedTagNotMatch("", ""),
Data: `http://host?map=)):or:g3)&g1=f1:eq:v1&g2=f2:ke:v2&g3=f3:ke:v3`,
},
{
Error: Errors().PairedTagNotMatch("", ""),
Data: `http://host?map=(g1:and:g2&g1=f1:eq:v1&g2=f2:ke:v2&g3=f3:ke:v3`,
},
{
Error: Errors().PairedTagNotMatch("", ""),
Data: `http://host?map=g1:and:g2:or:(g1:and:g2&g1=f1:eq:v1&g2=f2:ke:v2&g3=f3:ke:v3`,
},
{
Error: Errors().OperatorBracketEmpty(),
Data: `http://host?map=g1:or:g2:or:g3:or:()&g1=f1:eq:v1&g2=f2:ke:v2&g3=f3:ke:v3`,
},
{
Error: Errors().OperatorBracketOneItem(),
Data: `http://host?map=(g1)&g1=f1:eq:v1`,
},
{
Error: Errors().NoLogicalOperationBetweenBrackets(),
Data: `http://host?map=(g1:or:g2:or:g3)(g2:and:g3)&g1=f1:eq:v1&g2=f2:ke:v2&g3=f3:ke:v3`,
},
{
Error: Errors().NoLogicalOperationBetweenBrackets(),
Data: `http://host?map=g1:or:(g1:or:g2:or:g3)(g2:and:g3)&g1=f1:eq:v1&g2=f2:ke:v2&g3=f3:ke:v3`,
},
{
Error: Errors().WrongLogicalOperation(OriginUnknown),
Data: `http://host?map=(g1:or:):and:g2&g1=f1:eq:v1&g2=f2:ke:v2&g3=f3:ke:v3`,
},
{
Error: Errors().WrongLogicalOperation(OriginUnknown),
Data: `http://host?map=(:or:g1):and:g2&g1=f1:eq:v1&g2=f2:ke:v2&g3=f3:ke:v3`,
},
{
Error: Errors().WrongLogicalOperation(OriginUnknown),
Data: `http://host?map=:and::or:`,
},
{
Error: Errors().WrongLogicalOperation(OriginUnknown),
Data: `http://host?map=:or::and:`,
},
{
Error: Errors().WrongLogicalOperation(OriginUnknown),
Data: `http://host?map=g1:or::and::or::or:&g1=f1:eq:v1`,
},
{
Error: Errors().WrongLogicalOperation(OriginUnknown),
Data: `http://host?map=:or::and::or::or:g1&g1=f1:eq:v1`,
},
{
Error: Errors().WrongLogicalOperation(OriginUnknown),
Data: `http://host?map=(g1:or:g1)g1&g1=f1:eq:v1&g2=f2:ke:v2`,
},
{
Error: Errors().WrongLogicalOperation(OriginUnknown),
Data: `http://host?map=g1(g1:or:g2)&g1=f1:eq:v1&g2=f2:ke:v2`,
},
}
for n = range tests {
obj.Reset()
if rq, err = http.NewRequest("GET", strings.ReplaceAll(tests[n].Data, "\n", ""), nil); err != nil {
t.Errorf("Ошибка создания запроса: %s", err)
}
if err = obj.ParseRequest(rq); err == nil {
t.Logf("данные: %s", tests[n].Data)
t.Errorf("ParseRequest() == nil, ожидалась ошибка.")
return
}
if ero, ok = err.(Err); !ok {
t.Errorf("ParseRequest() = %q, не верный тип ошибки.", err)
return
}
if ero.Anchor() != tests[n].Error.Anchor() {
t.Logf("данные: %s", tests[n].Data)
t.Errorf("ParseRequest() = %q, ожидалось: %q", ero.Error(), tests[n].Error.Error())
return
}
}
}