File: basic.svtest

package info (click to toggle)
dovecot 1:2.2.13-12~deb8u4
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 38,792 kB
  • sloc: ansic: 341,472; sh: 16,920; makefile: 5,393; cpp: 1,474; perl: 265; xml: 44; python: 34; pascal: 27
file content (223 lines) | stat: -rw-r--r-- 4,763 bytes parent folder | download | duplicates (11)
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
require "vnd.dovecot.testsuite";
require "variables";

test_set "message" text:
From: stephan@example.org
To: test@example.com
Subject: Variables test

Testing variables...
.
;

/*
 * Substitution syntax
 */

test "Unknown variables" {
	set "q" "a";
	set "qw" "bb";
	set "qwe" "ccc";
	set "qwer" "dddd";
	set "qwert" "ccc";

	if anyof (
		not string "[${qwerty}]" "[]",
		not string "[${20}]" "[]"
	) {
		test_fail "unknown variable not substituted with empty string";
	}
}

test "One pass" {
	set "something" "value";
	set "s" "$";

	if string "${s}{something}" "value" {
		test_fail "somehow variable string is scanned multiple times";
	}

	if not string :matches "${s}{something}" "?{something}" {
		test_fail "unexpected result";
	}
}

test "Syntax errors" {
	set "s" "$";
	set "variable" "nonsense";

	if anyof (
		not string "$" "${s}",
		not string "${" "${s}{",
		not string "${a" "${s}{a",
		not string "${$}" "${s}{$}",
		not string "${%%%%}" "${s}{%%%%}",
		not string "${0.s}" "${s}{0.s}",
		not string "&%${}!" "&%${s}{}!",
		not string "${doh!}" "${s}{doh!}" )
	{
		test_fail "variables substitution changed substring not matching variable-ref";
	}
}

test "RFC syntax examples" {
	# The variable "company" holds the value "ACME".  No other variables
    # are set.
	set "company" "ACME";

	# "${full}"         => the empty string
	if not string :is "${full}" "" {
		test_fail "unknown variable did not yield empty string";
	}

	# "${company}"      => "ACME"
	if not string :is "${company}" "ACME" {
		test_fail "assigned variable did not get substituted";
	}

	# "${BAD${Company}" => "${BADACME"
	if not string :is "${BAD${Company}" "${BADACME" {
		test_fail "'BADACME' test did not yield expected result";
	}

	#"${President, ${Company} Inc.}"
	#                        => "${President, ACME Inc.}"
	if not string "${President, ${Company} Inc.}"
		"${President, ACME Inc.}" {
		test_fail "'Company president' test did not yield expected result";
	}
}

/*
 * Variable assignments
 */

test "Basic assignment" {
	set "test" "Value";

	if not string :is "${test}" "Value" {
		test_fail "variable assignment failed";
	}

	if string :is "${test}" "value" {
		test_fail "string test failed";
	}
}

test "Assignment overwritten" {
	set "test" "Value";
	set "test" "More";

	if not string :is "${test}" "More" {
		test_fail "variable assignment failed";
	}

	if string :is "${test}" "Value" {
		test_fail "value not overwritten";
	}

	if string :is "${test}" "nonsense" {
		test_fail "string test failed";
	}
}

test "Two assignments" {
	set "test" "Value";
	set "test2" "More";

	if not string :is "${test}" "Value" {
		test_fail "variable assignment failed";
	}

	if string :is "${test}" "More" {
		test_fail "assignments to different variables overlap";
	}

	if string :is "${test}" "nonsense" {
		test_fail "string test failed";
	}
}

test "Variables case-insensitive" {
	set "VeRyElAboRATeVaRIABLeName" "interesting value";

	if not string "${veryelaboratevariablename}" "interesting value" {
		test_fail "variable names are case sensitive (lower case try)";
	}

	if not string "${VERYELABORATEVARIABLENAME}" "interesting value" {
		test_fail "variable names are case sensitive (upper case try)";
	}
}

test "RFC set command example" {
	set "honorific"  "Mr";
	set "first_name" "Wile";
	set "last_name"  "Coyote";
	set "vacation" text:
Dear ${HONORIFIC} ${last_name},
I'm out, please leave a message after the meep.
.
;
	if not string :is :comparator "i;octet" "${VAcaTION}" text:
Dear Mr Coyote,
I'm out, please leave a message after the meep.
.
	{
		test_fail "failed to set variable correctly: ${VAcaTION}";
	}
}

/*
 * Variable substitution
 */

test "Multi-line string substitution" {
	set "name" "Stephan Bosch";
	set "address" "stephan@example.org";
	set "subject" "Test message";

	set "message" text: # Message with substitutions
From: ${name} <${address}>
To: Bertus van Asseldonk <b.vanasseldonk@nl.example.com>
Subject: ${subject}

This is a test message.
.
;
	if not string :is "${message}" text:
From: Stephan Bosch <stephan@example.org>
To: Bertus van Asseldonk <b.vanasseldonk@nl.example.com>
Subject: Test message

This is a test message.
.
	{
		test_fail "variable substitution failed";
	}
}

test "Multiple substitutions" {
	set "a" "the monkey";
	set "b" "a nut";
	set "c" "the fish";
	set "d" "on fire";
	set "e" "eats";
	set "f" "is";

	if not string :is "${a} ${e} ${b}" "the monkey eats a nut" {
		test_fail "variable substitution failed (1)";
	}

	if not string :is "${c} ${f} ${d}" "the fish is on fire" {
		test_fail "variable substitution failed (2)";
	}

	set :upperfirst "sentence" "${a} ${e} ${b}";

	if not string :is "${sentence}" "The monkey eats a nut" {
		test_fail "modified variable substitution failed";
	}
}