Mercurial > irccd
comparison tests/test-jsapi-file.c @ 965:a518664b20a0
irccd: move javascript API from library to frontend
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 29 Jan 2021 15:03:23 +0100 |
parents | 371e1cc2c697 |
children | 6da542806ed3 |
comparison
equal
deleted
inserted
replaced
964:0dd6afe7386d | 965:a518664b20a0 |
---|---|
24 | 24 |
25 #include <irccd/js-plugin.h> | 25 #include <irccd/js-plugin.h> |
26 #include <irccd/plugin.h> | 26 #include <irccd/plugin.h> |
27 | 27 |
28 static struct irc_plugin *plugin; | 28 static struct irc_plugin *plugin; |
29 static struct irc_js_plugin_data *data; | 29 static duk_context *ctx; |
30 | 30 |
31 static void | 31 static void |
32 setup(void *udata) | 32 setup(void *udata) |
33 { | 33 { |
34 (void)udata; | 34 (void)udata; |
35 | 35 |
36 plugin = irc_js_plugin_open(SOURCE "/data/example-plugin.js"); | 36 plugin = js_plugin_open(SOURCE "/data/example-plugin.js"); |
37 data = plugin->data; | 37 ctx = js_plugin_get_context(plugin); |
38 | 38 |
39 duk_push_string(data->ctx, SOURCE); | 39 duk_push_string(ctx, SOURCE); |
40 duk_put_global_string(data->ctx, "SOURCE"); | 40 duk_put_global_string(ctx, "SOURCE"); |
41 | 41 |
42 duk_push_string(data->ctx, BINARY); | 42 duk_push_string(ctx, BINARY); |
43 duk_put_global_string(data->ctx, "BINARY"); | 43 duk_put_global_string(ctx, "BINARY"); |
44 } | 44 } |
45 | 45 |
46 static void | 46 static void |
47 teardown(void *udata) | 47 teardown(void *udata) |
48 { | 48 { |
49 (void)udata; | 49 (void)udata; |
50 | 50 |
51 irc_plugin_finish(plugin); | 51 irc_plugin_finish(plugin); |
52 | 52 |
53 plugin = NULL; | 53 plugin = NULL; |
54 data = NULL; | 54 ctx = NULL; |
55 } | 55 } |
56 | 56 |
57 GREATEST_TEST | 57 GREATEST_TEST |
58 free_basename(void) | 58 free_basename(void) |
59 { | 59 { |
60 if (duk_peval_string(data->ctx, "result = Irccd.File.basename('/usr/local/etc/irccd.conf');")) | 60 if (duk_peval_string(ctx, "result = Irccd.File.basename('/usr/local/etc/irccd.conf');")) |
61 GREATEST_FAIL(); | 61 GREATEST_FAIL(); |
62 | 62 |
63 GREATEST_ASSERT(duk_get_global_string(data->ctx, "result")); | 63 GREATEST_ASSERT(duk_get_global_string(ctx, "result")); |
64 GREATEST_ASSERT_STR_EQ("irccd.conf", duk_get_string(data->ctx, -1)); | 64 GREATEST_ASSERT_STR_EQ("irccd.conf", duk_get_string(ctx, -1)); |
65 | 65 |
66 GREATEST_PASS(); | 66 GREATEST_PASS(); |
67 } | 67 } |
68 | 68 |
69 GREATEST_TEST | 69 GREATEST_TEST |
70 free_dirname(void) | 70 free_dirname(void) |
71 { | 71 { |
72 if (duk_peval_string(data->ctx, "result = Irccd.File.dirname('/usr/local/etc/irccd.conf');")) | 72 if (duk_peval_string(ctx, "result = Irccd.File.dirname('/usr/local/etc/irccd.conf');")) |
73 GREATEST_FAIL(); | 73 GREATEST_FAIL(); |
74 | 74 |
75 GREATEST_ASSERT(duk_get_global_string(data->ctx, "result")); | 75 GREATEST_ASSERT(duk_get_global_string(ctx, "result")); |
76 GREATEST_ASSERT_STR_EQ("/usr/local/etc", duk_get_string(data->ctx, -1)); | 76 GREATEST_ASSERT_STR_EQ("/usr/local/etc", duk_get_string(ctx, -1)); |
77 | 77 |
78 GREATEST_PASS(); | 78 GREATEST_PASS(); |
79 } | 79 } |
80 | 80 |
81 GREATEST_TEST | 81 GREATEST_TEST |
82 free_exists(void) | 82 free_exists(void) |
83 { | 83 { |
84 if (duk_peval_string(data->ctx, "result = Irccd.File.exists(SOURCE + '/data/root/file-1.txt')")) | 84 if (duk_peval_string(ctx, "result = Irccd.File.exists(SOURCE + '/data/root/file-1.txt')")) |
85 GREATEST_FAIL(); | 85 GREATEST_FAIL(); |
86 | 86 |
87 GREATEST_ASSERT(duk_get_global_string(data->ctx, "result")); | 87 GREATEST_ASSERT(duk_get_global_string(ctx, "result")); |
88 GREATEST_ASSERT(duk_get_boolean(data->ctx, -1)); | 88 GREATEST_ASSERT(duk_get_boolean(ctx, -1)); |
89 | 89 |
90 GREATEST_PASS(); | 90 GREATEST_PASS(); |
91 } | 91 } |
92 | 92 |
93 GREATEST_TEST | 93 GREATEST_TEST |
94 free_exists2(void) | 94 free_exists2(void) |
95 { | 95 { |
96 if (duk_peval_string(data->ctx, "result = Irccd.File.exists('file_which_does_not_exist.txt')")) | 96 if (duk_peval_string(ctx, "result = Irccd.File.exists('file_which_does_not_exist.txt')")) |
97 GREATEST_FAIL(); | 97 GREATEST_FAIL(); |
98 | 98 |
99 GREATEST_ASSERT(duk_get_global_string(data->ctx, "result")); | 99 GREATEST_ASSERT(duk_get_global_string(ctx, "result")); |
100 GREATEST_ASSERT(!duk_get_boolean(data->ctx, -1)); | 100 GREATEST_ASSERT(!duk_get_boolean(ctx, -1)); |
101 | 101 |
102 GREATEST_PASS(); | 102 GREATEST_PASS(); |
103 } | 103 } |
104 | 104 |
105 GREATEST_TEST | 105 GREATEST_TEST |
111 if (!(fp = fopen(BINARY "/test.bin", "w"))) | 111 if (!(fp = fopen(BINARY "/test.bin", "w"))) |
112 GREATEST_FAIL(); | 112 GREATEST_FAIL(); |
113 | 113 |
114 fclose(fp); | 114 fclose(fp); |
115 | 115 |
116 if (duk_peval_string(data->ctx, "Irccd.File.remove(BINARY + '/test.bin')") != 0) | 116 if (duk_peval_string(ctx, "Irccd.File.remove(BINARY + '/test.bin')") != 0) |
117 GREATEST_FAIL(); | 117 GREATEST_FAIL(); |
118 | 118 |
119 GREATEST_ASSERT(stat(BINARY "/test.bin", &st) < 0); | 119 GREATEST_ASSERT(stat(BINARY "/test.bin", &st) < 0); |
120 | 120 |
121 GREATEST_PASS(); | 121 GREATEST_PASS(); |
133 } | 133 } |
134 | 134 |
135 GREATEST_TEST | 135 GREATEST_TEST |
136 object_basename(void) | 136 object_basename(void) |
137 { | 137 { |
138 const int ret = duk_peval_string(data->ctx, | 138 const int ret = duk_peval_string(ctx, |
139 "f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" | 139 "f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" |
140 "result = f.basename();" | 140 "result = f.basename();" |
141 ); | 141 ); |
142 | 142 |
143 if (ret != 0) | 143 if (ret != 0) |
144 GREATEST_FAIL(); | 144 GREATEST_FAIL(); |
145 | 145 |
146 GREATEST_ASSERT(duk_get_global_string(data->ctx, "result")); | 146 GREATEST_ASSERT(duk_get_global_string(ctx, "result")); |
147 GREATEST_ASSERT_STR_EQ("file-1.txt", duk_get_string(data->ctx, -1)); | 147 GREATEST_ASSERT_STR_EQ("file-1.txt", duk_get_string(ctx, -1)); |
148 | 148 |
149 GREATEST_PASS(); | 149 GREATEST_PASS(); |
150 } | 150 } |
151 | 151 |
152 GREATEST_TEST | 152 GREATEST_TEST |
153 object_basename_closed(void) | 153 object_basename_closed(void) |
154 { | 154 { |
155 const int ret = duk_peval_string(data->ctx, | 155 const int ret = duk_peval_string(ctx, |
156 "f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" | 156 "f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" |
157 "f.close();" | 157 "f.close();" |
158 "result = f.basename();" | 158 "result = f.basename();" |
159 ); | 159 ); |
160 | 160 |
161 if (ret != 0) | 161 if (ret != 0) |
162 GREATEST_FAIL(); | 162 GREATEST_FAIL(); |
163 | 163 |
164 GREATEST_ASSERT(duk_get_global_string(data->ctx, "result")); | 164 GREATEST_ASSERT(duk_get_global_string(ctx, "result")); |
165 GREATEST_ASSERT_STR_EQ("file-1.txt", duk_get_string(data->ctx, -1)); | 165 GREATEST_ASSERT_STR_EQ("file-1.txt", duk_get_string(ctx, -1)); |
166 | 166 |
167 GREATEST_PASS(); | 167 GREATEST_PASS(); |
168 } | 168 } |
169 | 169 |
170 GREATEST_TEST | 170 GREATEST_TEST |
171 object_dirname(void) | 171 object_dirname(void) |
172 { | 172 { |
173 const int ret = duk_peval_string(data->ctx, | 173 const int ret = duk_peval_string(ctx, |
174 "f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" | 174 "f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" |
175 "result = f.dirname();" | 175 "result = f.dirname();" |
176 ); | 176 ); |
177 | 177 |
178 if (ret != 0) | 178 if (ret != 0) |
179 GREATEST_FAIL(); | 179 GREATEST_FAIL(); |
180 | 180 |
181 GREATEST_ASSERT(duk_get_global_string(data->ctx, "result")); | 181 GREATEST_ASSERT(duk_get_global_string(ctx, "result")); |
182 GREATEST_ASSERT_STR_EQ(SOURCE "/data/root", duk_get_string(data->ctx, -1)); | 182 GREATEST_ASSERT_STR_EQ(SOURCE "/data/root", duk_get_string(ctx, -1)); |
183 | 183 |
184 GREATEST_PASS(); | 184 GREATEST_PASS(); |
185 } | 185 } |
186 | 186 |
187 GREATEST_TEST | 187 GREATEST_TEST |
188 object_dirname_closed(void) | 188 object_dirname_closed(void) |
189 { | 189 { |
190 const int ret = duk_peval_string(data->ctx, | 190 const int ret = duk_peval_string(ctx, |
191 "f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" | 191 "f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" |
192 "f.close();" | 192 "f.close();" |
193 "result = f.dirname();" | 193 "result = f.dirname();" |
194 ); | 194 ); |
195 | 195 |
196 if (ret != 0) | 196 if (ret != 0) |
197 GREATEST_FAIL(); | 197 GREATEST_FAIL(); |
198 | 198 |
199 GREATEST_ASSERT(duk_get_global_string(data->ctx, "result")); | 199 GREATEST_ASSERT(duk_get_global_string(ctx, "result")); |
200 GREATEST_ASSERT_STR_EQ(SOURCE "/data/root", duk_get_string(data->ctx, -1)); | 200 GREATEST_ASSERT_STR_EQ(SOURCE "/data/root", duk_get_string(ctx, -1)); |
201 | 201 |
202 GREATEST_PASS(); | 202 GREATEST_PASS(); |
203 } | 203 } |
204 | 204 |
205 GREATEST_TEST | 205 GREATEST_TEST |
206 object_lines(void) | 206 object_lines(void) |
207 { | 207 { |
208 const int ret = duk_peval_string(data->ctx, | 208 const int ret = duk_peval_string(ctx, |
209 "result = new Irccd.File(SOURCE + '/data/root/lines.txt', 'r').lines();" | 209 "result = new Irccd.File(SOURCE + '/data/root/lines.txt', 'r').lines();" |
210 ); | 210 ); |
211 | 211 |
212 if (ret != 0) | 212 if (ret != 0) |
213 GREATEST_FAIL(); | 213 GREATEST_FAIL(); |
214 | 214 |
215 GREATEST_ASSERT(duk_get_global_string(data->ctx, "result")); | 215 GREATEST_ASSERT(duk_get_global_string(ctx, "result")); |
216 GREATEST_ASSERT_EQ(3, duk_get_length(data->ctx, -1)); | 216 GREATEST_ASSERT_EQ(3, duk_get_length(ctx, -1)); |
217 GREATEST_ASSERT(duk_get_prop_index(data->ctx, -1, 0)); | 217 GREATEST_ASSERT(duk_get_prop_index(ctx, -1, 0)); |
218 GREATEST_ASSERT_STR_EQ("a", duk_get_string(data->ctx, -1)); | 218 GREATEST_ASSERT_STR_EQ("a", duk_get_string(ctx, -1)); |
219 GREATEST_ASSERT(duk_get_prop_index(data->ctx, -2, 1)); | 219 GREATEST_ASSERT(duk_get_prop_index(ctx, -2, 1)); |
220 GREATEST_ASSERT_STR_EQ("b", duk_get_string(data->ctx, -1)); | 220 GREATEST_ASSERT_STR_EQ("b", duk_get_string(ctx, -1)); |
221 GREATEST_ASSERT(duk_get_prop_index(data->ctx, -3, 2)); | 221 GREATEST_ASSERT(duk_get_prop_index(ctx, -3, 2)); |
222 GREATEST_ASSERT_STR_EQ("c", duk_get_string(data->ctx, -1)); | 222 GREATEST_ASSERT_STR_EQ("c", duk_get_string(ctx, -1)); |
223 | 223 |
224 GREATEST_PASS(); | 224 GREATEST_PASS(); |
225 } | 225 } |
226 | 226 |
227 GREATEST_TEST | 227 GREATEST_TEST |
228 object_lines_closed(void) | 228 object_lines_closed(void) |
229 { | 229 { |
230 const int ret = duk_peval_string(data->ctx, | 230 const int ret = duk_peval_string(ctx, |
231 "try {" | 231 "try {" |
232 " f = new Irccd.File(SOURCE + '/data/root/lines.txt', 'r');" | 232 " f = new Irccd.File(SOURCE + '/data/root/lines.txt', 'r');" |
233 " f.close();" | 233 " f.close();" |
234 " f.lines();" | 234 " f.lines();" |
235 "} catch (e) {" | 235 "} catch (e) {" |
238 ); | 238 ); |
239 | 239 |
240 if (ret != 0) | 240 if (ret != 0) |
241 GREATEST_FAIL(); | 241 GREATEST_FAIL(); |
242 | 242 |
243 GREATEST_ASSERT(duk_get_global_string(data->ctx, "name")); | 243 GREATEST_ASSERT(duk_get_global_string(ctx, "name")); |
244 GREATEST_ASSERT_STR_EQ("SystemError", duk_get_string(data->ctx, -1)); | 244 GREATEST_ASSERT_STR_EQ("SystemError", duk_get_string(ctx, -1)); |
245 | 245 |
246 GREATEST_PASS(); | 246 GREATEST_PASS(); |
247 } | 247 } |
248 | 248 |
249 GREATEST_TEST | 249 GREATEST_TEST |
250 object_seek1(void) | 250 object_seek1(void) |
251 { | 251 { |
252 const int ret = duk_peval_string(data->ctx, | 252 const int ret = duk_peval_string(ctx, |
253 "f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" | 253 "f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" |
254 "f.seek(Irccd.File.SeekSet, 6);" | 254 "f.seek(Irccd.File.SeekSet, 6);" |
255 "result = f.read(1);" | 255 "result = f.read(1);" |
256 ); | 256 ); |
257 | 257 |
258 if (ret != 0) | 258 if (ret != 0) |
259 GREATEST_FAIL(); | 259 GREATEST_FAIL(); |
260 | 260 |
261 GREATEST_ASSERT(duk_get_global_string(data->ctx, "result")); | 261 GREATEST_ASSERT(duk_get_global_string(ctx, "result")); |
262 GREATEST_ASSERT_STR_EQ(".", duk_get_string(data->ctx, -1)); | 262 GREATEST_ASSERT_STR_EQ(".", duk_get_string(ctx, -1)); |
263 | 263 |
264 GREATEST_PASS(); | 264 GREATEST_PASS(); |
265 } | 265 } |
266 | 266 |
267 GREATEST_TEST | 267 GREATEST_TEST |
268 object_seek2(void) | 268 object_seek2(void) |
269 { | 269 { |
270 const int ret = duk_peval_string(data->ctx, | 270 const int ret = duk_peval_string(ctx, |
271 "f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" | 271 "f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" |
272 "f.seek(Irccd.File.SeekSet, 2);" | 272 "f.seek(Irccd.File.SeekSet, 2);" |
273 "f.seek(Irccd.File.SeekCur, 4);" | 273 "f.seek(Irccd.File.SeekCur, 4);" |
274 "result = f.read(1);" | 274 "result = f.read(1);" |
275 ); | 275 ); |
276 | 276 |
277 if (ret != 0) | 277 if (ret != 0) |
278 GREATEST_FAIL(); | 278 GREATEST_FAIL(); |
279 | 279 |
280 GREATEST_ASSERT(duk_get_global_string(data->ctx, "result")); | 280 GREATEST_ASSERT(duk_get_global_string(ctx, "result")); |
281 GREATEST_ASSERT_STR_EQ(".", duk_get_string(data->ctx, -1)); | 281 GREATEST_ASSERT_STR_EQ(".", duk_get_string(ctx, -1)); |
282 | 282 |
283 GREATEST_PASS(); | 283 GREATEST_PASS(); |
284 } | 284 } |
285 | 285 |
286 GREATEST_TEST | 286 GREATEST_TEST |
287 object_seek3(void) | 287 object_seek3(void) |
288 { | 288 { |
289 const int ret = duk_peval_string(data->ctx, | 289 const int ret = duk_peval_string(ctx, |
290 "f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" | 290 "f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" |
291 "f.seek(Irccd.File.SeekEnd, -2);" | 291 "f.seek(Irccd.File.SeekEnd, -2);" |
292 "result = f.read(1);" | 292 "result = f.read(1);" |
293 ); | 293 ); |
294 | 294 |
295 if (ret != 0) | 295 if (ret != 0) |
296 GREATEST_FAIL(); | 296 GREATEST_FAIL(); |
297 | 297 |
298 GREATEST_ASSERT(duk_get_global_string(data->ctx, "result")); | 298 GREATEST_ASSERT(duk_get_global_string(ctx, "result")); |
299 GREATEST_ASSERT_STR_EQ("t", duk_get_string(data->ctx, -1)); | 299 GREATEST_ASSERT_STR_EQ("t", duk_get_string(ctx, -1)); |
300 | 300 |
301 GREATEST_PASS(); | 301 GREATEST_PASS(); |
302 } | 302 } |
303 | 303 |
304 GREATEST_TEST | 304 GREATEST_TEST |
305 object_seek_closed(void) | 305 object_seek_closed(void) |
306 { | 306 { |
307 const int ret = duk_peval_string(data->ctx, | 307 const int ret = duk_peval_string(ctx, |
308 "try {" | 308 "try {" |
309 " f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" | 309 " f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" |
310 " f.close();" | 310 " f.close();" |
311 " f.seek(Irccd.File.SeekEnd, -2);" | 311 " f.seek(Irccd.File.SeekEnd, -2);" |
312 "} catch (e) {" | 312 "} catch (e) {" |
315 ); | 315 ); |
316 | 316 |
317 if (ret != 0) | 317 if (ret != 0) |
318 GREATEST_FAIL(); | 318 GREATEST_FAIL(); |
319 | 319 |
320 GREATEST_ASSERT(duk_get_global_string(data->ctx, "name")); | 320 GREATEST_ASSERT(duk_get_global_string(ctx, "name")); |
321 GREATEST_ASSERT_STR_EQ("SystemError", duk_get_string(data->ctx, -1)); | 321 GREATEST_ASSERT_STR_EQ("SystemError", duk_get_string(ctx, -1)); |
322 | 322 |
323 GREATEST_PASS(); | 323 GREATEST_PASS(); |
324 } | 324 } |
325 | 325 |
326 GREATEST_TEST | 326 GREATEST_TEST |
327 object_read(void) | 327 object_read(void) |
328 { | 328 { |
329 const int ret = duk_peval_string(data->ctx, | 329 const int ret = duk_peval_string(ctx, |
330 "f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" | 330 "f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" |
331 "result = f.read();" | 331 "result = f.read();" |
332 ); | 332 ); |
333 | 333 |
334 if (ret != 0) | 334 if (ret != 0) |
335 GREATEST_FAIL(); | 335 GREATEST_FAIL(); |
336 | 336 |
337 GREATEST_ASSERT(duk_get_global_string(data->ctx, "result")); | 337 GREATEST_ASSERT(duk_get_global_string(ctx, "result")); |
338 GREATEST_ASSERT_STR_EQ("file-1.txt\n", duk_get_string(data->ctx, -1)); | 338 GREATEST_ASSERT_STR_EQ("file-1.txt\n", duk_get_string(ctx, -1)); |
339 | 339 |
340 GREATEST_PASS(); | 340 GREATEST_PASS(); |
341 } | 341 } |
342 | 342 |
343 GREATEST_TEST | 343 GREATEST_TEST |
344 object_read_closed(void) | 344 object_read_closed(void) |
345 { | 345 { |
346 const int ret = duk_peval_string(data->ctx, | 346 const int ret = duk_peval_string(ctx, |
347 "try {" | 347 "try {" |
348 " f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" | 348 " f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" |
349 " f.close();" | 349 " f.close();" |
350 " f.read();" | 350 " f.read();" |
351 "} catch (e) {" | 351 "} catch (e) {" |
354 ); | 354 ); |
355 | 355 |
356 if (ret != 0) | 356 if (ret != 0) |
357 GREATEST_FAIL(); | 357 GREATEST_FAIL(); |
358 | 358 |
359 GREATEST_ASSERT(duk_get_global_string(data->ctx, "name")); | 359 GREATEST_ASSERT(duk_get_global_string(ctx, "name")); |
360 GREATEST_ASSERT_STR_EQ("SystemError", duk_get_string(data->ctx, -1)); | 360 GREATEST_ASSERT_STR_EQ("SystemError", duk_get_string(ctx, -1)); |
361 | 361 |
362 GREATEST_PASS(); | 362 GREATEST_PASS(); |
363 } | 363 } |
364 | 364 |
365 GREATEST_TEST | 365 GREATEST_TEST |
366 object_readline(void) | 366 object_readline(void) |
367 { | 367 { |
368 const int ret = duk_peval_string(data->ctx, | 368 const int ret = duk_peval_string(ctx, |
369 "result = [];" | 369 "result = [];" |
370 "f = new Irccd.File(SOURCE + '/data/root/lines.txt', 'r');" | 370 "f = new Irccd.File(SOURCE + '/data/root/lines.txt', 'r');" |
371 "for (var s; s = f.readline(); ) {" | 371 "for (var s; s = f.readline(); ) {" |
372 " result.push(s);" | 372 " result.push(s);" |
373 "}" | 373 "}" |
374 ); | 374 ); |
375 | 375 |
376 if (ret != 0) { | 376 if (ret != 0) { |
377 puts(duk_to_string(data->ctx, -1)); | 377 puts(duk_to_string(ctx, -1)); |
378 GREATEST_FAIL(); | 378 GREATEST_FAIL(); |
379 } | 379 } |
380 | 380 |
381 GREATEST_ASSERT(duk_get_global_string(data->ctx, "result")); | 381 GREATEST_ASSERT(duk_get_global_string(ctx, "result")); |
382 GREATEST_ASSERT_EQ(3, duk_get_length(data->ctx, -1)); | 382 GREATEST_ASSERT_EQ(3, duk_get_length(ctx, -1)); |
383 GREATEST_ASSERT(duk_get_prop_index(data->ctx, -1, 0)); | 383 GREATEST_ASSERT(duk_get_prop_index(ctx, -1, 0)); |
384 GREATEST_ASSERT_STR_EQ("a", duk_get_string(data->ctx, -1)); | 384 GREATEST_ASSERT_STR_EQ("a", duk_get_string(ctx, -1)); |
385 GREATEST_ASSERT(duk_get_prop_index(data->ctx, -2, 1)); | 385 GREATEST_ASSERT(duk_get_prop_index(ctx, -2, 1)); |
386 GREATEST_ASSERT_STR_EQ("b", duk_get_string(data->ctx, -1)); | 386 GREATEST_ASSERT_STR_EQ("b", duk_get_string(ctx, -1)); |
387 GREATEST_ASSERT(duk_get_prop_index(data->ctx, -3, 2)); | 387 GREATEST_ASSERT(duk_get_prop_index(ctx, -3, 2)); |
388 GREATEST_ASSERT_STR_EQ("c", duk_get_string(data->ctx, -1)); | 388 GREATEST_ASSERT_STR_EQ("c", duk_get_string(ctx, -1)); |
389 | 389 |
390 GREATEST_PASS(); | 390 GREATEST_PASS(); |
391 } | 391 } |
392 | 392 |
393 GREATEST_TEST | 393 GREATEST_TEST |
394 object_readline_closed(void) | 394 object_readline_closed(void) |
395 { | 395 { |
396 const int ret = duk_peval_string(data->ctx, | 396 const int ret = duk_peval_string(ctx, |
397 "try {" | 397 "try {" |
398 " result = [];" | 398 " result = [];" |
399 " f = new Irccd.File(SOURCE + '/data/root/lines.txt', 'r');" | 399 " f = new Irccd.File(SOURCE + '/data/root/lines.txt', 'r');" |
400 " f.close();" | 400 " f.close();" |
401 " for (var s; s = f.readline(); ) {" | 401 " for (var s; s = f.readline(); ) {" |
408 ); | 408 ); |
409 | 409 |
410 if (ret != 0) | 410 if (ret != 0) |
411 GREATEST_FAIL(); | 411 GREATEST_FAIL(); |
412 | 412 |
413 GREATEST_ASSERT(duk_get_global_string(data->ctx, "result")); | 413 GREATEST_ASSERT(duk_get_global_string(ctx, "result")); |
414 GREATEST_ASSERT_EQ(0, duk_get_length(data->ctx, -1)); | 414 GREATEST_ASSERT_EQ(0, duk_get_length(ctx, -1)); |
415 GREATEST_ASSERT(duk_get_global_string(data->ctx, "name")); | 415 GREATEST_ASSERT(duk_get_global_string(ctx, "name")); |
416 GREATEST_ASSERT_STR_EQ("SystemError", duk_get_string(data->ctx, -1)); | 416 GREATEST_ASSERT_STR_EQ("SystemError", duk_get_string(ctx, -1)); |
417 | 417 |
418 GREATEST_PASS(); | 418 GREATEST_PASS(); |
419 } | 419 } |
420 | 420 |
421 GREATEST_SUITE(suite_object) | 421 GREATEST_SUITE(suite_object) |