summaryrefslogtreecommitdiffstats
path: root/pigeonhole/tests/extensions/encoded-character.svtest
blob: 150d812513386d1df7000f4cf5b72e0ca6fee3eb (plain)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
require "vnd.dovecot.testsuite";

require "encoded-character";
require "variables";

test "HEX equality one" {
	if not string "${hex:42}" "B" {
		test_fail "failed to match the string 'B'";
	}

	if string "${hex:42}" "b" {
		test_fail "matched nonsense";
	}

	if string "${hex:42}" "" {
		test_fail "substitution failed";
	}
}

test "HEX equality one middle" {
	if not string " ${hex:42} " " B " {
		test_fail "failed to match the string ' B '";
	}

	if string " ${hex:42} " " b " {
		test_fail "matched nonsense";
	}

	if string " ${hex:42} " "  " {
		test_fail "substitution failed";
	}
}

test "HEX equality one begin" {
	if not string "${hex:42} " "B " {
		test_fail "failed to match the string 'B '";
	}

	if string "${hex:42} " " b" {
		test_fail "matched nonsense";
	}

	if string "${hex:42} " " " {
		test_fail "substitution failed";
	}
}

test "HEX equality one end" {
	if not string " ${hex:42}" " B" {
		test_fail "failed to match the string ' B'";
	}

	if string " ${hex:42}" " b " {
		test_fail "matched nonsense";
	}

	if string " ${hex:42}" " " {
		test_fail "substitution failed";
	}
}

test "HEX equality two triple" {
	if not string "${hex:42 61 64}${hex: 61 73 73}" "Badass" {
		test_fail "failed to match the string 'Badass'";
	}

	if string "${hex:42 61 64}${hex: 61 73 73}" "Sadass" {
		test_fail "matched nonsense";
	}

	if string "${hex:42 61 64}${hex: 61 73 73}" "" {
		test_fail "substitution failed";
	}
}

test "HEX equality braindead" {
	if not string "${hex:42 72 61 69 6E 64 65 61 64}" "Braindead" {
		test_fail "failed to match the string 'Braindead'";
	}

	if string "${hex:42 72 61 69 6E 64 65 61 64}" "Brian Nut" {
		test_fail "matched nonsense";
	}
}

test "Syntax errors" {
	if anyof( not string "$" "${hex:24}", not string "$ " "${hex:24} ", not string " $" " ${hex:24}" ) {
		test_fail "loose $ handled inappropriately";
	}

	if anyof( not string "${" "${hex:24}{", not string "a${" "a${hex:24}{", not string "${a" "${hex:24}{a" ) {
		test_fail "loose ${ handled inappropriately";
	}

	if anyof( not string "${}" "${hex:24}{}", not string "b${}" "b${hex:24}{}", not string "${}b" "${hex:24}{}b" ) {
		test_fail "entirely missing content handled inappropriately";
	}

	if not string "${:}" "${hex:24}{:}" {
		test_fail "missing content handled inappropriately";
	}

	if not string "${hex:}" "${hex:24}{hex:}" {
		test_fail "missing hex content handled inappropriately";
	}

	if not string "${unicode:}" "${hex:24}{unicode:}" {
		test_fail "missing unicode content handled inappropriately";
	}

	if not string "${hex:sss}" "${hex:24}{hex:sss}" {
		test_fail "erroneous hex content handled inappropriately";
	}

	if not string "${unicode:ttt}" "${hex:24}{unicode:ttt}" {
		test_fail "erroneous unicode content handled inappropriately";
	}

	if not string "${hex:aa aa" "${hex:24}{hex:aa aa" {
		test_fail "unterminated hex content handled inappropriately";
	}

	if not string "${unicode: aaaa aaaa" "${hex:24}{unicode: aaaa aaaa" {
		test_fail "unterminated unicode content handled inappropriately";
	}
}

/*
 * RFC Examples
 */

test "RFC Examples" {
	if not string "$${hex:40}" "$@" {
		test_fail "failed RFC example 1";
	}

	if not string "${hex: 40 }" "@" {
		test_fail "failed RFC example 2";
	}

	if not string "${HEX: 40}" "@" {
		test_fail "failed RFC example 3";
	}

	if not string "${hex:40" "${hex:40" {
		test_fail "failed RFC example 4";
	}

	if not string "${hex:400}" "${hex:400}" {
		test_fail "failed RFC example 5";
	}

	if not string "${hex:4${hex:30}}" "${hex: 24}{hex:40}" {
		test_fail "failed RFC example 6";
	}

	if not string "${unicode:40}" "@" {
		test_fail "failed RFC example 7";
	}

	if not string "${ unicode:40}" "${ unicode:40}" {
		test_fail "failed RFC example 8";
	}

	if not string "${UNICODE:40}" "@" {
		test_fail "failed RFC example 9";
	}

	if not string "${UnICoDE:0000040}" "@" {
		test_fail "failed RFC example 10";
	}

	if not string "${Unicode:40}" "@" {
		test_fail "failed RFC example 11";
	}

	if not string "${Unicode:Cool}" "${Unicode:Cool}" {
		test_fail "failed RFC example 12";
	}
}