Software /
code /
prosody
Annotate
spec/util_format_spec.lua @ 12660:e8f57970ced5
mod_admin_shell: Show session role in c2s:show
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 15 Aug 2022 16:36:00 +0200 |
parent | 12571:c4337ff4f1c4 |
child | 12985:c0e3e0d79574 |
rev | line source |
---|---|
8383 | 1 local format = require "util.format".format; |
12034 | 2 -- There are eight basic types in Lua: |
3 -- nil, boolean, number, string, function, userdata, thread, and table | |
8383 | 4 |
5 describe("util.format", function() | |
6 describe("#format()", function() | |
7 it("should work", function() | |
8619
b96b0141cb61
util.format: Fix tests to have expected value first
Kim Alvefur <zash@zash.se>
parents:
8383
diff
changeset
|
8 assert.equal("hello", format("%s", "hello")); |
11644
fc1b8fe94d04
util.format: Change formatting of nil values to avoid looking like XML
Kim Alvefur <zash@zash.se>
parents:
11638
diff
changeset
|
9 assert.equal("(nil)", format("%s")); |
fc1b8fe94d04
util.format: Change formatting of nil values to avoid looking like XML
Kim Alvefur <zash@zash.se>
parents:
11638
diff
changeset
|
10 assert.equal("(nil)", format("%d")); |
fc1b8fe94d04
util.format: Change formatting of nil values to avoid looking like XML
Kim Alvefur <zash@zash.se>
parents:
11638
diff
changeset
|
11 assert.equal("(nil)", format("%q")); |
fc1b8fe94d04
util.format: Change formatting of nil values to avoid looking like XML
Kim Alvefur <zash@zash.se>
parents:
11638
diff
changeset
|
12 assert.equal(" [(nil)]", format("", nil)); |
8619
b96b0141cb61
util.format: Fix tests to have expected value first
Kim Alvefur <zash@zash.se>
parents:
8383
diff
changeset
|
13 assert.equal("true", format("%s", true)); |
b96b0141cb61
util.format: Fix tests to have expected value first
Kim Alvefur <zash@zash.se>
parents:
8383
diff
changeset
|
14 assert.equal("[true]", format("%d", true)); |
b96b0141cb61
util.format: Fix tests to have expected value first
Kim Alvefur <zash@zash.se>
parents:
8383
diff
changeset
|
15 assert.equal("% [true]", format("%%", true)); |
9693
6ed0d6224d64
util.format: Serialize values for the %q format
Kim Alvefur <zash@zash.se>
parents:
9656
diff
changeset
|
16 assert.equal("{ }", format("%q", { })); |
10034
4fca92d60040
util.format: Handle formats expecting an integer in Lua 5.3+ (fixes #1371)
Kim Alvefur <zash@zash.se>
parents:
9693
diff
changeset
|
17 assert.equal("[1.5]", format("%d", 1.5)); |
10035
386f085820e6
util.format: Handle integer formats the same way on Lua versions without integer support
Kim Alvefur <zash@zash.se>
parents:
10034
diff
changeset
|
18 assert.equal("[7.3786976294838e+19]", format("%d", 73786976294838206464)); |
8383 | 19 end); |
11638
5f4a657136bc
util.format: Escape ASCII control characters in output
Kim Alvefur <zash@zash.se>
parents:
10035
diff
changeset
|
20 |
5f4a657136bc
util.format: Escape ASCII control characters in output
Kim Alvefur <zash@zash.se>
parents:
10035
diff
changeset
|
21 it("escapes ascii control stuff", function () |
5f4a657136bc
util.format: Escape ASCII control characters in output
Kim Alvefur <zash@zash.se>
parents:
10035
diff
changeset
|
22 assert.equal("␁", format("%s", "\1")); |
12032
3db09eb4c43b
util.format: Ensure sanitation of strings passed to wrong format
Kim Alvefur <zash@zash.se>
parents:
12031
diff
changeset
|
23 assert.equal("[␁]", format("%d", "\1")); |
11638
5f4a657136bc
util.format: Escape ASCII control characters in output
Kim Alvefur <zash@zash.se>
parents:
10035
diff
changeset
|
24 end); |
5f4a657136bc
util.format: Escape ASCII control characters in output
Kim Alvefur <zash@zash.se>
parents:
10035
diff
changeset
|
25 |
12031
87bc26f23d9b
util.format: Escape invalid UTF-8 by passing trough serialization
Kim Alvefur <zash@zash.se>
parents:
11644
diff
changeset
|
26 it("escapes invalid UTF-8", function () |
87bc26f23d9b
util.format: Escape invalid UTF-8 by passing trough serialization
Kim Alvefur <zash@zash.se>
parents:
11644
diff
changeset
|
27 assert.equal("\"Hello w\\195rld\"", format("%s", "Hello w\195rld")); |
87bc26f23d9b
util.format: Escape invalid UTF-8 by passing trough serialization
Kim Alvefur <zash@zash.se>
parents:
11644
diff
changeset
|
28 end); |
87bc26f23d9b
util.format: Escape invalid UTF-8 by passing trough serialization
Kim Alvefur <zash@zash.se>
parents:
11644
diff
changeset
|
29 |
12033
161f8268c4b3
util.format: Also handle the %p format added in Lua 5.4
Kim Alvefur <zash@zash.se>
parents:
12032
diff
changeset
|
30 if _VERSION >= "Lua 5.4" then |
161f8268c4b3
util.format: Also handle the %p format added in Lua 5.4
Kim Alvefur <zash@zash.se>
parents:
12032
diff
changeset
|
31 it("handles %p formats", function () |
161f8268c4b3
util.format: Also handle the %p format added in Lua 5.4
Kim Alvefur <zash@zash.se>
parents:
12032
diff
changeset
|
32 assert.matches("a 0x%x+ b", format("%s %p %s", "a", {}, "b")); |
161f8268c4b3
util.format: Also handle the %p format added in Lua 5.4
Kim Alvefur <zash@zash.se>
parents:
12032
diff
changeset
|
33 end) |
161f8268c4b3
util.format: Also handle the %p format added in Lua 5.4
Kim Alvefur <zash@zash.se>
parents:
12032
diff
changeset
|
34 else |
161f8268c4b3
util.format: Also handle the %p format added in Lua 5.4
Kim Alvefur <zash@zash.se>
parents:
12032
diff
changeset
|
35 it("does something with %p formats", function () |
161f8268c4b3
util.format: Also handle the %p format added in Lua 5.4
Kim Alvefur <zash@zash.se>
parents:
12032
diff
changeset
|
36 assert.string(format("%p", {})); |
161f8268c4b3
util.format: Also handle the %p format added in Lua 5.4
Kim Alvefur <zash@zash.se>
parents:
12032
diff
changeset
|
37 end) |
161f8268c4b3
util.format: Also handle the %p format added in Lua 5.4
Kim Alvefur <zash@zash.se>
parents:
12032
diff
changeset
|
38 end |
12034 | 39 |
12220
25b853e64d83
util.format: Skip control code escaping when doing full serialization
Kim Alvefur <zash@zash.se>
parents:
12039
diff
changeset
|
40 it("escapes multi-line strings", function () |
25b853e64d83
util.format: Skip control code escaping when doing full serialization
Kim Alvefur <zash@zash.se>
parents:
12039
diff
changeset
|
41 assert.equal("Hello\n\tWorld", format("%s", "Hello\nWorld")) |
25b853e64d83
util.format: Skip control code escaping when doing full serialization
Kim Alvefur <zash@zash.se>
parents:
12039
diff
changeset
|
42 assert.equal("\"Hello\\nWorld\"", format("%q", "Hello\nWorld")) |
25b853e64d83
util.format: Skip control code escaping when doing full serialization
Kim Alvefur <zash@zash.se>
parents:
12039
diff
changeset
|
43 end) |
25b853e64d83
util.format: Skip control code escaping when doing full serialization
Kim Alvefur <zash@zash.se>
parents:
12039
diff
changeset
|
44 |
12034 | 45 -- Tests generated with loops! |
46 describe("nil", function () | |
47 describe("to %c", function () | |
48 it("works", function () | |
49 assert.equal("(nil)", format("%c", nil)) | |
50 end); | |
51 end); | |
52 | |
53 describe("to %d", function () | |
54 it("works", function () | |
55 assert.equal("(nil)", format("%d", nil)) | |
56 end); | |
57 end); | |
58 | |
59 describe("to %i", function () | |
60 it("works", function () | |
61 assert.equal("(nil)", format("%i", nil)) | |
62 end); | |
63 end); | |
64 | |
65 describe("to %o", function () | |
66 it("works", function () | |
67 assert.equal("(nil)", format("%o", nil)) | |
68 end); | |
69 end); | |
70 | |
71 describe("to %u", function () | |
72 it("works", function () | |
73 assert.equal("(nil)", format("%u", nil)) | |
74 end); | |
75 end); | |
76 | |
77 describe("to %x", function () | |
78 it("works", function () | |
79 assert.equal("(nil)", format("%x", nil)) | |
80 end); | |
81 end); | |
82 | |
83 describe("to %X", function () | |
84 it("works", function () | |
85 assert.equal("(nil)", format("%X", nil)) | |
86 end); | |
87 end); | |
88 | |
89 describe("to %a", function () | |
90 it("works", function () | |
91 assert.equal("(nil)", format("%a", nil)) | |
92 end); | |
93 end); | |
94 | |
95 describe("to %A", function () | |
96 it("works", function () | |
97 assert.equal("(nil)", format("%A", nil)) | |
98 end); | |
99 end); | |
100 | |
101 describe("to %e", function () | |
102 it("works", function () | |
103 assert.equal("(nil)", format("%e", nil)) | |
104 end); | |
105 end); | |
106 | |
107 describe("to %E", function () | |
108 it("works", function () | |
109 assert.equal("(nil)", format("%E", nil)) | |
110 end); | |
111 end); | |
112 | |
113 describe("to %f", function () | |
114 it("works", function () | |
115 assert.equal("(nil)", format("%f", nil)) | |
116 end); | |
117 end); | |
118 | |
119 describe("to %g", function () | |
120 it("works", function () | |
121 assert.equal("(nil)", format("%g", nil)) | |
122 end); | |
123 end); | |
124 | |
125 describe("to %G", function () | |
126 it("works", function () | |
127 assert.equal("(nil)", format("%G", nil)) | |
128 end); | |
129 end); | |
130 | |
131 describe("to %q", function () | |
132 it("works", function () | |
133 assert.equal("(nil)", format("%q", nil)) | |
134 end); | |
135 end); | |
136 | |
137 describe("to %s", function () | |
138 it("works", function () | |
139 assert.equal("(nil)", format("%s", nil)) | |
140 end); | |
141 end); | |
142 | |
143 end); | |
144 | |
145 describe("boolean", function () | |
146 describe("to %c", function () | |
147 it("works", function () | |
148 assert.equal("[true]", format("%c", true)) | |
149 assert.equal("[false]", format("%c", false)) | |
150 end); | |
151 end); | |
152 | |
153 describe("to %d", function () | |
154 it("works", function () | |
155 assert.equal("[true]", format("%d", true)) | |
156 assert.equal("[false]", format("%d", false)) | |
157 end); | |
158 end); | |
159 | |
160 describe("to %i", function () | |
161 it("works", function () | |
162 assert.equal("[true]", format("%i", true)) | |
163 assert.equal("[false]", format("%i", false)) | |
164 end); | |
165 end); | |
166 | |
167 describe("to %o", function () | |
168 it("works", function () | |
169 assert.equal("[true]", format("%o", true)) | |
170 assert.equal("[false]", format("%o", false)) | |
171 end); | |
172 end); | |
173 | |
174 describe("to %u", function () | |
175 it("works", function () | |
176 assert.equal("[true]", format("%u", true)) | |
177 assert.equal("[false]", format("%u", false)) | |
178 end); | |
179 end); | |
180 | |
181 describe("to %x", function () | |
182 it("works", function () | |
183 assert.equal("[true]", format("%x", true)) | |
184 assert.equal("[false]", format("%x", false)) | |
185 end); | |
186 end); | |
187 | |
188 describe("to %X", function () | |
189 it("works", function () | |
190 assert.equal("[true]", format("%X", true)) | |
191 assert.equal("[false]", format("%X", false)) | |
192 end); | |
193 end); | |
194 | |
195 describe("to %a", function () | |
196 it("works", function () | |
197 assert.equal("[true]", format("%a", true)) | |
198 assert.equal("[false]", format("%a", false)) | |
199 end); | |
200 end); | |
201 | |
202 describe("to %A", function () | |
203 it("works", function () | |
204 assert.equal("[true]", format("%A", true)) | |
205 assert.equal("[false]", format("%A", false)) | |
206 end); | |
207 end); | |
208 | |
209 describe("to %e", function () | |
210 it("works", function () | |
211 assert.equal("[true]", format("%e", true)) | |
212 assert.equal("[false]", format("%e", false)) | |
213 end); | |
214 end); | |
215 | |
216 describe("to %E", function () | |
217 it("works", function () | |
218 assert.equal("[true]", format("%E", true)) | |
219 assert.equal("[false]", format("%E", false)) | |
220 end); | |
221 end); | |
222 | |
223 describe("to %f", function () | |
224 it("works", function () | |
225 assert.equal("[true]", format("%f", true)) | |
226 assert.equal("[false]", format("%f", false)) | |
227 end); | |
228 end); | |
229 | |
230 describe("to %g", function () | |
231 it("works", function () | |
232 assert.equal("[true]", format("%g", true)) | |
233 assert.equal("[false]", format("%g", false)) | |
234 end); | |
235 end); | |
236 | |
237 describe("to %G", function () | |
238 it("works", function () | |
239 assert.equal("[true]", format("%G", true)) | |
240 assert.equal("[false]", format("%G", false)) | |
241 end); | |
242 end); | |
243 | |
244 describe("to %q", function () | |
245 it("works", function () | |
246 assert.equal("true", format("%q", true)) | |
247 assert.equal("false", format("%q", false)) | |
248 end); | |
249 end); | |
250 | |
251 describe("to %s", function () | |
252 it("works", function () | |
253 assert.equal("true", format("%s", true)) | |
254 assert.equal("false", format("%s", false)) | |
255 end); | |
256 end); | |
257 | |
258 end); | |
259 | |
260 describe("number", function () | |
261 describe("to %c", function () | |
262 it("works", function () | |
263 assert.equal("a", format("%c", 97)) | |
264 assert.equal("[1.5]", format("%c", 1.5)) | |
265 assert.equal("[7.3786976294838e+19]", format("%c", 73786976294838206464)) | |
266 assert.equal("[inf]", format("%c", math.huge)) | |
267 end); | |
268 end); | |
269 | |
270 describe("to %d", function () | |
271 it("works", function () | |
272 assert.equal("97", format("%d", 97)) | |
273 assert.equal("-12345", format("%d", -12345)) | |
274 assert.equal("[1.5]", format("%d", 1.5)) | |
275 assert.equal("[7.3786976294838e+19]", format("%d", 73786976294838206464)) | |
276 assert.equal("[inf]", format("%d", math.huge)) | |
277 assert.equal("2147483647", format("%d", 2147483647)) | |
278 end); | |
279 end); | |
280 | |
281 describe("to %i", function () | |
282 it("works", function () | |
283 assert.equal("97", format("%i", 97)) | |
284 assert.equal("-12345", format("%i", -12345)) | |
285 assert.equal("[1.5]", format("%i", 1.5)) | |
286 assert.equal("[7.3786976294838e+19]", format("%i", 73786976294838206464)) | |
287 assert.equal("[inf]", format("%i", math.huge)) | |
288 assert.equal("2147483647", format("%i", 2147483647)) | |
289 end); | |
290 end); | |
291 | |
292 describe("to %o", function () | |
293 it("works", function () | |
294 assert.equal("141", format("%o", 97)) | |
12036
2ce06f788093
util.format: Fix some formats expecting positive numbers in Lua 5.2
Kim Alvefur <zash@zash.se>
parents:
12034
diff
changeset
|
295 assert.equal("[-12345]", format("%o", -12345)) |
12034 | 296 assert.equal("[1.5]", format("%o", 1.5)) |
297 assert.equal("[7.3786976294838e+19]", format("%o", 73786976294838206464)) | |
298 assert.equal("[inf]", format("%o", math.huge)) | |
299 assert.equal("17777777777", format("%o", 2147483647)) | |
300 end); | |
301 end); | |
302 | |
303 describe("to %u", function () | |
304 it("works", function () | |
305 assert.equal("97", format("%u", 97)) | |
12036
2ce06f788093
util.format: Fix some formats expecting positive numbers in Lua 5.2
Kim Alvefur <zash@zash.se>
parents:
12034
diff
changeset
|
306 assert.equal("[-12345]", format("%u", -12345)) |
12034 | 307 assert.equal("[1.5]", format("%u", 1.5)) |
308 assert.equal("[7.3786976294838e+19]", format("%u", 73786976294838206464)) | |
309 assert.equal("[inf]", format("%u", math.huge)) | |
310 assert.equal("2147483647", format("%u", 2147483647)) | |
311 end); | |
312 end); | |
313 | |
314 describe("to %x", function () | |
315 it("works", function () | |
316 assert.equal("61", format("%x", 97)) | |
12036
2ce06f788093
util.format: Fix some formats expecting positive numbers in Lua 5.2
Kim Alvefur <zash@zash.se>
parents:
12034
diff
changeset
|
317 assert.equal("[-12345]", format("%x", -12345)) |
12034 | 318 assert.equal("[1.5]", format("%x", 1.5)) |
319 assert.equal("[7.3786976294838e+19]", format("%x", 73786976294838206464)) | |
320 assert.equal("[inf]", format("%x", math.huge)) | |
321 assert.equal("7fffffff", format("%x", 2147483647)) | |
322 end); | |
323 end); | |
324 | |
325 describe("to %X", function () | |
326 it("works", function () | |
327 assert.equal("61", format("%X", 97)) | |
12036
2ce06f788093
util.format: Fix some formats expecting positive numbers in Lua 5.2
Kim Alvefur <zash@zash.se>
parents:
12034
diff
changeset
|
328 assert.equal("[-12345]", format("%X", -12345)) |
12034 | 329 assert.equal("[1.5]", format("%X", 1.5)) |
330 assert.equal("[7.3786976294838e+19]", format("%X", 73786976294838206464)) | |
331 assert.equal("[inf]", format("%X", math.huge)) | |
332 assert.equal("7FFFFFFF", format("%X", 2147483647)) | |
333 end); | |
334 end); | |
335 | |
12571
c4337ff4f1c4
tests: Remove special-casing of Lua 5.1
Kim Alvefur <zash@zash.se>
parents:
12220
diff
changeset
|
336 describe("to %a", function () |
c4337ff4f1c4
tests: Remove special-casing of Lua 5.1
Kim Alvefur <zash@zash.se>
parents:
12220
diff
changeset
|
337 it("works", function () |
c4337ff4f1c4
tests: Remove special-casing of Lua 5.1
Kim Alvefur <zash@zash.se>
parents:
12220
diff
changeset
|
338 assert.equal("0x1.84p+6", format("%a", 97)) |
c4337ff4f1c4
tests: Remove special-casing of Lua 5.1
Kim Alvefur <zash@zash.se>
parents:
12220
diff
changeset
|
339 assert.equal("-0x1.81c8p+13", format("%a", -12345)) |
c4337ff4f1c4
tests: Remove special-casing of Lua 5.1
Kim Alvefur <zash@zash.se>
parents:
12220
diff
changeset
|
340 assert.equal("0x1.8p+0", format("%a", 1.5)) |
c4337ff4f1c4
tests: Remove special-casing of Lua 5.1
Kim Alvefur <zash@zash.se>
parents:
12220
diff
changeset
|
341 assert.equal("0x1p+66", format("%a", 73786976294838206464)) |
c4337ff4f1c4
tests: Remove special-casing of Lua 5.1
Kim Alvefur <zash@zash.se>
parents:
12220
diff
changeset
|
342 assert.equal("inf", format("%a", math.huge)) |
c4337ff4f1c4
tests: Remove special-casing of Lua 5.1
Kim Alvefur <zash@zash.se>
parents:
12220
diff
changeset
|
343 assert.equal("0x1.fffffffcp+30", format("%a", 2147483647)) |
12034 | 344 end); |
12571
c4337ff4f1c4
tests: Remove special-casing of Lua 5.1
Kim Alvefur <zash@zash.se>
parents:
12220
diff
changeset
|
345 end); |
12034 | 346 |
12571
c4337ff4f1c4
tests: Remove special-casing of Lua 5.1
Kim Alvefur <zash@zash.se>
parents:
12220
diff
changeset
|
347 describe("to %A", function () |
c4337ff4f1c4
tests: Remove special-casing of Lua 5.1
Kim Alvefur <zash@zash.se>
parents:
12220
diff
changeset
|
348 it("works", function () |
c4337ff4f1c4
tests: Remove special-casing of Lua 5.1
Kim Alvefur <zash@zash.se>
parents:
12220
diff
changeset
|
349 assert.equal("0X1.84P+6", format("%A", 97)) |
c4337ff4f1c4
tests: Remove special-casing of Lua 5.1
Kim Alvefur <zash@zash.se>
parents:
12220
diff
changeset
|
350 assert.equal("-0X1.81C8P+13", format("%A", -12345)) |
c4337ff4f1c4
tests: Remove special-casing of Lua 5.1
Kim Alvefur <zash@zash.se>
parents:
12220
diff
changeset
|
351 assert.equal("0X1.8P+0", format("%A", 1.5)) |
c4337ff4f1c4
tests: Remove special-casing of Lua 5.1
Kim Alvefur <zash@zash.se>
parents:
12220
diff
changeset
|
352 assert.equal("0X1P+66", format("%A", 73786976294838206464)) |
c4337ff4f1c4
tests: Remove special-casing of Lua 5.1
Kim Alvefur <zash@zash.se>
parents:
12220
diff
changeset
|
353 assert.equal("INF", format("%A", math.huge)) |
c4337ff4f1c4
tests: Remove special-casing of Lua 5.1
Kim Alvefur <zash@zash.se>
parents:
12220
diff
changeset
|
354 assert.equal("0X1.FFFFFFFCP+30", format("%A", 2147483647)) |
12034 | 355 end); |
12571
c4337ff4f1c4
tests: Remove special-casing of Lua 5.1
Kim Alvefur <zash@zash.se>
parents:
12220
diff
changeset
|
356 end); |
12034 | 357 |
358 describe("to %e", function () | |
359 it("works", function () | |
360 assert.equal("9.700000e+01", format("%e", 97)) | |
361 assert.equal("-1.234500e+04", format("%e", -12345)) | |
362 assert.equal("1.500000e+00", format("%e", 1.5)) | |
363 assert.equal("7.378698e+19", format("%e", 73786976294838206464)) | |
364 assert.equal("inf", format("%e", math.huge)) | |
365 assert.equal("2.147484e+09", format("%e", 2147483647)) | |
366 end); | |
367 end); | |
368 | |
369 describe("to %E", function () | |
370 it("works", function () | |
371 assert.equal("9.700000E+01", format("%E", 97)) | |
372 assert.equal("-1.234500E+04", format("%E", -12345)) | |
373 assert.equal("1.500000E+00", format("%E", 1.5)) | |
374 assert.equal("7.378698E+19", format("%E", 73786976294838206464)) | |
375 assert.equal("INF", format("%E", math.huge)) | |
376 assert.equal("2.147484E+09", format("%E", 2147483647)) | |
377 end); | |
378 end); | |
379 | |
380 describe("to %f", function () | |
381 it("works", function () | |
382 assert.equal("97.000000", format("%f", 97)) | |
383 assert.equal("-12345.000000", format("%f", -12345)) | |
384 assert.equal("1.500000", format("%f", 1.5)) | |
385 assert.equal("73786976294838206464.000000", format("%f", 73786976294838206464)) | |
386 assert.equal("inf", format("%f", math.huge)) | |
387 assert.equal("2147483647.000000", format("%f", 2147483647)) | |
388 end); | |
389 end); | |
390 | |
391 describe("to %g", function () | |
392 it("works", function () | |
393 assert.equal("97", format("%g", 97)) | |
394 assert.equal("-12345", format("%g", -12345)) | |
395 assert.equal("1.5", format("%g", 1.5)) | |
396 assert.equal("7.3787e+19", format("%g", 73786976294838206464)) | |
397 assert.equal("inf", format("%g", math.huge)) | |
398 assert.equal("2.14748e+09", format("%g", 2147483647)) | |
399 end); | |
400 end); | |
401 | |
402 describe("to %G", function () | |
403 it("works", function () | |
404 assert.equal("97", format("%G", 97)) | |
405 assert.equal("-12345", format("%G", -12345)) | |
406 assert.equal("1.5", format("%G", 1.5)) | |
407 assert.equal("7.3787E+19", format("%G", 73786976294838206464)) | |
408 assert.equal("INF", format("%G", math.huge)) | |
409 assert.equal("2.14748E+09", format("%G", 2147483647)) | |
410 end); | |
411 end); | |
412 | |
413 describe("to %q", function () | |
414 it("works", function () | |
415 assert.equal("97", format("%q", 97)) | |
416 assert.equal("-12345", format("%q", -12345)) | |
417 assert.equal("1.5", format("%q", 1.5)) | |
418 assert.equal("7.37869762948382065e+19", format("%q", 73786976294838206464)) | |
419 assert.equal("(1/0)", format("%q", math.huge)) | |
420 assert.equal("2147483647", format("%q", 2147483647)) | |
421 end); | |
422 end); | |
423 | |
424 describe("to %s", function () | |
425 it("works", function () | |
426 assert.equal("97", format("%s", 97)) | |
427 assert.equal("-12345", format("%s", -12345)) | |
428 assert.equal("1.5", format("%s", 1.5)) | |
429 assert.equal("7.3786976294838e+19", format("%s", 73786976294838206464)) | |
430 assert.equal("inf", format("%s", math.huge)) | |
431 assert.equal("2147483647", format("%s", 2147483647)) | |
432 end); | |
433 end); | |
434 | |
435 end); | |
436 | |
437 describe("string", function () | |
438 describe("to %c", function () | |
439 it("works", function () | |
440 assert.equal("[hello]", format("%c", "hello")) | |
441 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%c", "foo \001\002\003 bar")) | |
442 assert.equal("[nödåtgärd]", format("%c", "n\195\182d\195\165tg\195\164rd")) | |
443 assert.equal("\"n\\195\\182d\\195\\165tg\\195\"", format("%c", "n\195\182d\195\165tg\195")) | |
444 end); | |
445 end); | |
446 | |
447 describe("to %d", function () | |
448 it("works", function () | |
449 assert.equal("[hello]", format("%d", "hello")) | |
450 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%d", "foo \001\002\003 bar")) | |
451 assert.equal("[nödåtgärd]", format("%d", "n\195\182d\195\165tg\195\164rd")) | |
452 assert.equal("\"n\\195\\182d\\195\\165tg\\195\"", format("%d", "n\195\182d\195\165tg\195")) | |
453 end); | |
454 end); | |
455 | |
456 describe("to %i", function () | |
457 it("works", function () | |
458 assert.equal("[hello]", format("%i", "hello")) | |
459 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%i", "foo \001\002\003 bar")) | |
460 assert.equal("[nödåtgärd]", format("%i", "n\195\182d\195\165tg\195\164rd")) | |
461 assert.equal("\"n\\195\\182d\\195\\165tg\\195\"", format("%i", "n\195\182d\195\165tg\195")) | |
462 end); | |
463 end); | |
464 | |
465 describe("to %o", function () | |
466 it("works", function () | |
467 assert.equal("[hello]", format("%o", "hello")) | |
468 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%o", "foo \001\002\003 bar")) | |
469 assert.equal("[nödåtgärd]", format("%o", "n\195\182d\195\165tg\195\164rd")) | |
470 assert.equal("\"n\\195\\182d\\195\\165tg\\195\"", format("%o", "n\195\182d\195\165tg\195")) | |
471 end); | |
472 end); | |
473 | |
474 describe("to %u", function () | |
475 it("works", function () | |
476 assert.equal("[hello]", format("%u", "hello")) | |
477 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%u", "foo \001\002\003 bar")) | |
478 assert.equal("[nödåtgärd]", format("%u", "n\195\182d\195\165tg\195\164rd")) | |
479 assert.equal("\"n\\195\\182d\\195\\165tg\\195\"", format("%u", "n\195\182d\195\165tg\195")) | |
480 end); | |
481 end); | |
482 | |
483 describe("to %x", function () | |
484 it("works", function () | |
485 assert.equal("[hello]", format("%x", "hello")) | |
486 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%x", "foo \001\002\003 bar")) | |
487 assert.equal("[nödåtgärd]", format("%x", "n\195\182d\195\165tg\195\164rd")) | |
488 assert.equal("\"n\\195\\182d\\195\\165tg\\195\"", format("%x", "n\195\182d\195\165tg\195")) | |
489 end); | |
490 end); | |
491 | |
492 describe("to %X", function () | |
493 it("works", function () | |
494 assert.equal("[hello]", format("%X", "hello")) | |
495 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%X", "foo \001\002\003 bar")) | |
496 assert.equal("[nödåtgärd]", format("%X", "n\195\182d\195\165tg\195\164rd")) | |
497 assert.equal("\"n\\195\\182d\\195\\165tg\\195\"", format("%X", "n\195\182d\195\165tg\195")) | |
498 end); | |
499 end); | |
500 | |
501 describe("to %a", function () | |
502 it("works", function () | |
503 assert.equal("[hello]", format("%a", "hello")) | |
504 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%a", "foo \001\002\003 bar")) | |
505 assert.equal("[nödåtgärd]", format("%a", "n\195\182d\195\165tg\195\164rd")) | |
506 assert.equal("\"n\\195\\182d\\195\\165tg\\195\"", format("%a", "n\195\182d\195\165tg\195")) | |
507 end); | |
508 end); | |
509 | |
510 describe("to %A", function () | |
511 it("works", function () | |
512 assert.equal("[hello]", format("%A", "hello")) | |
513 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%A", "foo \001\002\003 bar")) | |
514 assert.equal("[nödåtgärd]", format("%A", "n\195\182d\195\165tg\195\164rd")) | |
515 assert.equal("\"n\\195\\182d\\195\\165tg\\195\"", format("%A", "n\195\182d\195\165tg\195")) | |
516 end); | |
517 end); | |
518 | |
519 describe("to %e", function () | |
520 it("works", function () | |
521 assert.equal("[hello]", format("%e", "hello")) | |
522 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%e", "foo \001\002\003 bar")) | |
523 assert.equal("[nödåtgärd]", format("%e", "n\195\182d\195\165tg\195\164rd")) | |
524 assert.equal("\"n\\195\\182d\\195\\165tg\\195\"", format("%e", "n\195\182d\195\165tg\195")) | |
525 end); | |
526 end); | |
527 | |
528 describe("to %E", function () | |
529 it("works", function () | |
530 assert.equal("[hello]", format("%E", "hello")) | |
531 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%E", "foo \001\002\003 bar")) | |
532 assert.equal("[nödåtgärd]", format("%E", "n\195\182d\195\165tg\195\164rd")) | |
533 assert.equal("\"n\\195\\182d\\195\\165tg\\195\"", format("%E", "n\195\182d\195\165tg\195")) | |
534 end); | |
535 end); | |
536 | |
537 describe("to %f", function () | |
538 it("works", function () | |
539 assert.equal("[hello]", format("%f", "hello")) | |
540 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%f", "foo \001\002\003 bar")) | |
541 assert.equal("[nödåtgärd]", format("%f", "n\195\182d\195\165tg\195\164rd")) | |
542 assert.equal("\"n\\195\\182d\\195\\165tg\\195\"", format("%f", "n\195\182d\195\165tg\195")) | |
543 end); | |
544 end); | |
545 | |
546 describe("to %g", function () | |
547 it("works", function () | |
548 assert.equal("[hello]", format("%g", "hello")) | |
549 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%g", "foo \001\002\003 bar")) | |
550 assert.equal("[nödåtgärd]", format("%g", "n\195\182d\195\165tg\195\164rd")) | |
551 assert.equal("\"n\\195\\182d\\195\\165tg\\195\"", format("%g", "n\195\182d\195\165tg\195")) | |
552 end); | |
553 end); | |
554 | |
555 describe("to %G", function () | |
556 it("works", function () | |
557 assert.equal("[hello]", format("%G", "hello")) | |
558 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%G", "foo \001\002\003 bar")) | |
559 assert.equal("[nödåtgärd]", format("%G", "n\195\182d\195\165tg\195\164rd")) | |
560 assert.equal("\"n\\195\\182d\\195\\165tg\\195\"", format("%G", "n\195\182d\195\165tg\195")) | |
561 end); | |
562 end); | |
563 | |
564 describe("to %q", function () | |
565 it("works", function () | |
566 assert.equal("\"hello\"", format("%q", "hello")) | |
12220
25b853e64d83
util.format: Skip control code escaping when doing full serialization
Kim Alvefur <zash@zash.se>
parents:
12039
diff
changeset
|
567 assert.equal("\"foo \\001\\002\\003 bar\"", format("%q", "foo \001\002\003 bar")) |
25b853e64d83
util.format: Skip control code escaping when doing full serialization
Kim Alvefur <zash@zash.se>
parents:
12039
diff
changeset
|
568 assert.equal("\"n\\195\\182d\\195\\165tg\\195\\164rd\"", format("%q", "n\195\182d\195\165tg\195\164rd")) |
12034 | 569 assert.equal("\"n\\195\\182d\\195\\165tg\\195\"", format("%q", "n\195\182d\195\165tg\195")) |
570 end); | |
571 end); | |
572 | |
573 describe("to %s", function () | |
574 it("works", function () | |
575 assert.equal("hello", format("%s", "hello")) | |
576 assert.equal("foo \226\144\129\226\144\130\226\144\131 bar", format("%s", "foo \001\002\003 bar")) | |
577 assert.equal("nödåtgärd", format("%s", "n\195\182d\195\165tg\195\164rd")) | |
578 assert.equal("\"n\\195\\182d\\195\\165tg\\195\"", format("%s", "n\195\182d\195\165tg\195")) | |
579 end); | |
580 end); | |
581 | |
582 end); | |
583 | |
584 describe("function", function () | |
585 describe("to %c", function () | |
586 it("works", function () | |
587 assert.matches("[function: 0[xX]%x+]", format("%c", function() end)) | |
588 end); | |
589 end); | |
590 | |
591 describe("to %d", function () | |
592 it("works", function () | |
593 assert.matches("[function: 0[xX]%x+]", format("%d", function() end)) | |
594 end); | |
595 end); | |
596 | |
597 describe("to %i", function () | |
598 it("works", function () | |
599 assert.matches("[function: 0[xX]%x+]", format("%i", function() end)) | |
600 end); | |
601 end); | |
602 | |
603 describe("to %o", function () | |
604 it("works", function () | |
605 assert.matches("[function: 0[xX]%x+]", format("%o", function() end)) | |
606 end); | |
607 end); | |
608 | |
609 describe("to %u", function () | |
610 it("works", function () | |
611 assert.matches("[function: 0[xX]%x+]", format("%u", function() end)) | |
612 end); | |
613 end); | |
614 | |
615 describe("to %x", function () | |
616 it("works", function () | |
617 assert.matches("[function: 0[xX]%x+]", format("%x", function() end)) | |
618 end); | |
619 end); | |
620 | |
621 describe("to %X", function () | |
622 it("works", function () | |
623 assert.matches("[function: 0[xX]%x+]", format("%X", function() end)) | |
624 end); | |
625 end); | |
626 | |
627 describe("to %a", function () | |
628 it("works", function () | |
629 assert.matches("[function: 0[xX]%x+]", format("%a", function() end)) | |
630 end); | |
631 end); | |
632 | |
633 describe("to %A", function () | |
634 it("works", function () | |
635 assert.matches("[function: 0[xX]%x+]", format("%A", function() end)) | |
636 end); | |
637 end); | |
638 | |
639 describe("to %e", function () | |
640 it("works", function () | |
641 assert.matches("[function: 0[xX]%x+]", format("%e", function() end)) | |
642 end); | |
643 end); | |
644 | |
645 describe("to %E", function () | |
646 it("works", function () | |
647 assert.matches("[function: 0[xX]%x+]", format("%E", function() end)) | |
648 end); | |
649 end); | |
650 | |
651 describe("to %f", function () | |
652 it("works", function () | |
653 assert.matches("[function: 0[xX]%x+]", format("%f", function() end)) | |
654 end); | |
655 end); | |
656 | |
657 describe("to %g", function () | |
658 it("works", function () | |
659 assert.matches("[function: 0[xX]%x+]", format("%g", function() end)) | |
660 end); | |
661 end); | |
662 | |
663 describe("to %G", function () | |
664 it("works", function () | |
665 assert.matches("[function: 0[xX]%x+]", format("%G", function() end)) | |
666 end); | |
667 end); | |
668 | |
669 describe("to %q", function () | |
670 it("works", function () | |
671 assert.matches('{__type="function",__error="fail"}', format("%q", function() end)) | |
672 end); | |
673 end); | |
674 | |
675 describe("to %s", function () | |
676 it("works", function () | |
677 assert.matches("function: 0[xX]%x+", format("%s", function() end)) | |
678 end); | |
679 end); | |
680 | |
681 end); | |
682 | |
683 describe("thread", function () | |
684 describe("to %c", function () | |
685 it("works", function () | |
686 assert.matches("[thread: 0[xX]%x+]", format("%c", coroutine.create(function() end))) | |
687 end); | |
688 end); | |
689 | |
690 describe("to %d", function () | |
691 it("works", function () | |
692 assert.matches("[thread: 0[xX]%x+]", format("%d", coroutine.create(function() end))) | |
693 end); | |
694 end); | |
695 | |
696 describe("to %i", function () | |
697 it("works", function () | |
698 assert.matches("[thread: 0[xX]%x+]", format("%i", coroutine.create(function() end))) | |
699 end); | |
700 end); | |
701 | |
702 describe("to %o", function () | |
703 it("works", function () | |
704 assert.matches("[thread: 0[xX]%x+]", format("%o", coroutine.create(function() end))) | |
705 end); | |
706 end); | |
707 | |
708 describe("to %u", function () | |
709 it("works", function () | |
710 assert.matches("[thread: 0[xX]%x+]", format("%u", coroutine.create(function() end))) | |
711 end); | |
712 end); | |
713 | |
714 describe("to %x", function () | |
715 it("works", function () | |
716 assert.matches("[thread: 0[xX]%x+]", format("%x", coroutine.create(function() end))) | |
717 end); | |
718 end); | |
719 | |
720 describe("to %X", function () | |
721 it("works", function () | |
722 assert.matches("[thread: 0[xX]%x+]", format("%X", coroutine.create(function() end))) | |
723 end); | |
724 end); | |
725 | |
726 describe("to %a", function () | |
727 it("works", function () | |
728 assert.matches("[thread: 0[xX]%x+]", format("%a", coroutine.create(function() end))) | |
729 end); | |
730 end); | |
731 | |
732 describe("to %A", function () | |
733 it("works", function () | |
734 assert.matches("[thread: 0[xX]%x+]", format("%A", coroutine.create(function() end))) | |
735 end); | |
736 end); | |
737 | |
738 describe("to %e", function () | |
739 it("works", function () | |
740 assert.matches("[thread: 0[xX]%x+]", format("%e", coroutine.create(function() end))) | |
741 end); | |
742 end); | |
743 | |
744 describe("to %E", function () | |
745 it("works", function () | |
746 assert.matches("[thread: 0[xX]%x+]", format("%E", coroutine.create(function() end))) | |
747 end); | |
748 end); | |
749 | |
750 describe("to %f", function () | |
751 it("works", function () | |
752 assert.matches("[thread: 0[xX]%x+]", format("%f", coroutine.create(function() end))) | |
753 end); | |
754 end); | |
755 | |
756 describe("to %g", function () | |
757 it("works", function () | |
758 assert.matches("[thread: 0[xX]%x+]", format("%g", coroutine.create(function() end))) | |
759 end); | |
760 end); | |
761 | |
762 describe("to %G", function () | |
763 it("works", function () | |
764 assert.matches("[thread: 0[xX]%x+]", format("%G", coroutine.create(function() end))) | |
765 end); | |
766 end); | |
767 | |
768 describe("to %q", function () | |
769 it("works", function () | |
770 assert.matches('{__type="thread",__error="fail"}', format("%q", coroutine.create(function() end))) | |
771 end); | |
772 end); | |
773 | |
774 describe("to %s", function () | |
775 it("works", function () | |
776 assert.matches("thread: 0[xX]%x+", format("%s", coroutine.create(function() end))) | |
777 end); | |
778 end); | |
779 | |
780 end); | |
781 | |
782 describe("table", function () | |
783 describe("to %c", function () | |
784 it("works", function () | |
785 assert.matches("[table: 0[xX]%x+]", format("%c", { })) | |
12039
e0a8c5b1ab4f
util.format: Ensure metatable __tostring results are also sanitized
Kim Alvefur <zash@zash.se>
parents:
12036
diff
changeset
|
786 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%c", setmetatable({},{__tostring=function ()return "foo \1\2\3 bar"end}))) |
12034 | 787 end); |
788 end); | |
789 | |
790 describe("to %d", function () | |
791 it("works", function () | |
792 assert.matches("[table: 0[xX]%x+]", format("%d", { })) | |
12039
e0a8c5b1ab4f
util.format: Ensure metatable __tostring results are also sanitized
Kim Alvefur <zash@zash.se>
parents:
12036
diff
changeset
|
793 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%d", setmetatable({},{__tostring=function ()return "foo \1\2\3 bar"end}))) |
12034 | 794 end); |
795 end); | |
796 | |
797 describe("to %i", function () | |
798 it("works", function () | |
799 assert.matches("[table: 0[xX]%x+]", format("%i", { })) | |
12039
e0a8c5b1ab4f
util.format: Ensure metatable __tostring results are also sanitized
Kim Alvefur <zash@zash.se>
parents:
12036
diff
changeset
|
800 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%i", setmetatable({},{__tostring=function ()return "foo \1\2\3 bar"end}))) |
12034 | 801 end); |
802 end); | |
803 | |
804 describe("to %o", function () | |
805 it("works", function () | |
806 assert.matches("[table: 0[xX]%x+]", format("%o", { })) | |
12039
e0a8c5b1ab4f
util.format: Ensure metatable __tostring results are also sanitized
Kim Alvefur <zash@zash.se>
parents:
12036
diff
changeset
|
807 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%o", setmetatable({},{__tostring=function ()return "foo \1\2\3 bar"end}))) |
12034 | 808 end); |
809 end); | |
810 | |
811 describe("to %u", function () | |
812 it("works", function () | |
813 assert.matches("[table: 0[xX]%x+]", format("%u", { })) | |
12039
e0a8c5b1ab4f
util.format: Ensure metatable __tostring results are also sanitized
Kim Alvefur <zash@zash.se>
parents:
12036
diff
changeset
|
814 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%u", setmetatable({},{__tostring=function ()return "foo \1\2\3 bar"end}))) |
12034 | 815 end); |
816 end); | |
817 | |
818 describe("to %x", function () | |
819 it("works", function () | |
820 assert.matches("[table: 0[xX]%x+]", format("%x", { })) | |
12039
e0a8c5b1ab4f
util.format: Ensure metatable __tostring results are also sanitized
Kim Alvefur <zash@zash.se>
parents:
12036
diff
changeset
|
821 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%x", setmetatable({},{__tostring=function ()return "foo \1\2\3 bar"end}))) |
12034 | 822 end); |
823 end); | |
824 | |
825 describe("to %X", function () | |
826 it("works", function () | |
827 assert.matches("[table: 0[xX]%x+]", format("%X", { })) | |
12039
e0a8c5b1ab4f
util.format: Ensure metatable __tostring results are also sanitized
Kim Alvefur <zash@zash.se>
parents:
12036
diff
changeset
|
828 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%X", setmetatable({},{__tostring=function ()return "foo \1\2\3 bar"end}))) |
12034 | 829 end); |
830 end); | |
831 | |
832 describe("to %a", function () | |
833 it("works", function () | |
834 assert.matches("[table: 0[xX]%x+]", format("%a", { })) | |
12039
e0a8c5b1ab4f
util.format: Ensure metatable __tostring results are also sanitized
Kim Alvefur <zash@zash.se>
parents:
12036
diff
changeset
|
835 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%a", setmetatable({},{__tostring=function ()return "foo \1\2\3 bar"end}))) |
12034 | 836 end); |
837 end); | |
838 | |
839 describe("to %A", function () | |
840 it("works", function () | |
841 assert.matches("[table: 0[xX]%x+]", format("%A", { })) | |
12039
e0a8c5b1ab4f
util.format: Ensure metatable __tostring results are also sanitized
Kim Alvefur <zash@zash.se>
parents:
12036
diff
changeset
|
842 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%A", setmetatable({},{__tostring=function ()return "foo \1\2\3 bar"end}))) |
12034 | 843 end); |
844 end); | |
845 | |
846 describe("to %e", function () | |
847 it("works", function () | |
848 assert.matches("[table: 0[xX]%x+]", format("%e", { })) | |
12039
e0a8c5b1ab4f
util.format: Ensure metatable __tostring results are also sanitized
Kim Alvefur <zash@zash.se>
parents:
12036
diff
changeset
|
849 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%e", setmetatable({},{__tostring=function ()return "foo \1\2\3 bar"end}))) |
12034 | 850 end); |
851 end); | |
852 | |
853 describe("to %E", function () | |
854 it("works", function () | |
855 assert.matches("[table: 0[xX]%x+]", format("%E", { })) | |
12039
e0a8c5b1ab4f
util.format: Ensure metatable __tostring results are also sanitized
Kim Alvefur <zash@zash.se>
parents:
12036
diff
changeset
|
856 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%E", setmetatable({},{__tostring=function ()return "foo \1\2\3 bar"end}))) |
12034 | 857 end); |
858 end); | |
859 | |
860 describe("to %f", function () | |
861 it("works", function () | |
862 assert.matches("[table: 0[xX]%x+]", format("%f", { })) | |
12039
e0a8c5b1ab4f
util.format: Ensure metatable __tostring results are also sanitized
Kim Alvefur <zash@zash.se>
parents:
12036
diff
changeset
|
863 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%f", setmetatable({},{__tostring=function ()return "foo \1\2\3 bar"end}))) |
12034 | 864 end); |
865 end); | |
866 | |
867 describe("to %g", function () | |
868 it("works", function () | |
869 assert.matches("[table: 0[xX]%x+]", format("%g", { })) | |
12039
e0a8c5b1ab4f
util.format: Ensure metatable __tostring results are also sanitized
Kim Alvefur <zash@zash.se>
parents:
12036
diff
changeset
|
870 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%g", setmetatable({},{__tostring=function ()return "foo \1\2\3 bar"end}))) |
12034 | 871 end); |
872 end); | |
873 | |
874 describe("to %G", function () | |
875 it("works", function () | |
876 assert.matches("[table: 0[xX]%x+]", format("%G", { })) | |
12039
e0a8c5b1ab4f
util.format: Ensure metatable __tostring results are also sanitized
Kim Alvefur <zash@zash.se>
parents:
12036
diff
changeset
|
877 assert.equal("[foo \226\144\129\226\144\130\226\144\131 bar]", format("%G", setmetatable({},{__tostring=function ()return "foo \1\2\3 bar"end}))) |
12034 | 878 end); |
879 end); | |
880 | |
881 describe("to %q", function () | |
882 it("works", function () | |
883 assert.matches("{ }", format("%q", { })) | |
12039
e0a8c5b1ab4f
util.format: Ensure metatable __tostring results are also sanitized
Kim Alvefur <zash@zash.se>
parents:
12036
diff
changeset
|
884 assert.equal("{ }", format("%q", setmetatable({},{__tostring=function ()return "foo \1\2\3 bar"end}))) |
12034 | 885 end); |
886 end); | |
887 | |
888 describe("to %s", function () | |
889 it("works", function () | |
890 assert.matches("table: 0[xX]%x+", format("%s", { })) | |
12039
e0a8c5b1ab4f
util.format: Ensure metatable __tostring results are also sanitized
Kim Alvefur <zash@zash.se>
parents:
12036
diff
changeset
|
891 assert.equal("foo \226\144\129\226\144\130\226\144\131 bar", format("%s", setmetatable({},{__tostring=function ()return "foo \1\2\3 bar"end}))) |
12034 | 892 end); |
893 end); | |
894 | |
895 end); | |
896 | |
897 | |
8383 | 898 end); |
899 end); |