1 #include <stic.h>
2
3 #include <unistd.h> /* chdir() */
4
5 #include <stdlib.h>
6 #include <string.h>
7
8 #include "../../src/cfg/config.h"
9 #include "../../src/ui/ui.h"
10 #include "../../src/utils/dynarray.h"
11 #include "../../src/filelist.h"
12 #include "../../src/macros.h"
13 #include "../../src/registers.h"
14 #include "../../src/status.h"
15
16 #ifdef _WIN32
17 #define SL "\\\\"
18 #else
19 #define SL "/"
20 #endif
21
22 static void
setup_lwin(void)23 setup_lwin(void)
24 {
25 strcpy(lwin.curr_dir, "/lwin");
26
27 lwin.list_rows = 5;
28 lwin.list_pos = 2;
29 lwin.dir_entry = dynarray_cextend(NULL,
30 lwin.list_rows*sizeof(*lwin.dir_entry));
31 lwin.dir_entry[0].name = strdup("lfile0");
32 lwin.dir_entry[0].origin = &lwin.curr_dir[0];
33 lwin.dir_entry[1].name = strdup("lfile1");
34 lwin.dir_entry[1].origin = &lwin.curr_dir[0];
35 lwin.dir_entry[2].name = strdup("lfile2");
36 lwin.dir_entry[2].origin = &lwin.curr_dir[0];
37 lwin.dir_entry[3].name = strdup("lfile3");
38 lwin.dir_entry[3].origin = &lwin.curr_dir[0];
39 lwin.dir_entry[4].name = strdup(".lfile4");
40 lwin.dir_entry[4].origin = &lwin.curr_dir[0];
41
42 lwin.dir_entry[0].selected = 1;
43 lwin.dir_entry[2].selected = 1;
44 lwin.selected_files = 2;
45 }
46
47 static void
setup_rwin(void)48 setup_rwin(void)
49 {
50 strcpy(rwin.curr_dir, "/rwin");
51
52 rwin.list_rows = 7;
53 rwin.list_pos = 5;
54 rwin.dir_entry = dynarray_cextend(NULL,
55 rwin.list_rows*sizeof(*rwin.dir_entry));
56 rwin.dir_entry[0].name = strdup("rfile0");
57 rwin.dir_entry[0].origin = &rwin.curr_dir[0];
58 rwin.dir_entry[1].name = strdup("rfile1");
59 rwin.dir_entry[1].origin = &rwin.curr_dir[0];
60 rwin.dir_entry[2].name = strdup("rfile2");
61 rwin.dir_entry[2].origin = &rwin.curr_dir[0];
62 rwin.dir_entry[3].name = strdup("rfile3");
63 rwin.dir_entry[3].origin = &rwin.curr_dir[0];
64 rwin.dir_entry[4].name = strdup("rfile4.tar.gz");
65 rwin.dir_entry[4].origin = &rwin.curr_dir[0];
66 rwin.dir_entry[5].name = strdup("rfile5");
67 rwin.dir_entry[5].origin = &rwin.curr_dir[0];
68 rwin.dir_entry[6].name = strdup("rdir6");
69 rwin.dir_entry[6].origin = &rwin.curr_dir[0];
70
71 rwin.dir_entry[1].selected = 1;
72 rwin.dir_entry[3].selected = 1;
73 rwin.dir_entry[5].selected = 1;
74 rwin.selected_files = 3;
75 }
76
77 static void
setup_registers(void)78 setup_registers(void)
79 {
80 regs_init();
81 regs_append('z', "existing-files/a");
82 regs_append('z', "existing-files/b");
83 regs_append('z', "existing-files/c");
84 }
85
SETUP_ONCE()86 SETUP_ONCE()
87 {
88 stats_update_shell_type("/bin/sh");
89 }
90
SETUP()91 SETUP()
92 {
93 assert_success(chdir(TEST_DATA_PATH));
94
95 setup_lwin();
96 setup_rwin();
97
98 curr_view = &lwin;
99 other_view = &rwin;
100
101 strcpy(cfg.home_dir, "/rwin/");
102
103 setup_registers();
104 }
105
TEARDOWN()106 TEARDOWN()
107 {
108 int i;
109
110 for(i = 0; i < lwin.list_rows; i++)
111 free(lwin.dir_entry[i].name);
112 dynarray_free(lwin.dir_entry);
113
114 for(i = 0; i < rwin.list_rows; i++)
115 free(rwin.dir_entry[i].name);
116 dynarray_free(rwin.dir_entry);
117
118 regs_reset();
119 }
120
TEST(colon_p)121 TEST(colon_p)
122 {
123 MacroFlags flags;
124 char *expanded;
125
126 expanded = ma_expand(" cp %f:p ", "", &flags, 1);
127 assert_string_equal(" cp " SL "lwin" SL "lfile0 " SL "lwin" SL "lfile2 ",
128 expanded);
129 free(expanded);
130
131 expanded = ma_expand(" cp %F:p ", "", &flags, 1);
132 assert_string_equal(" cp " SL "rwin" SL "rfile1 " SL "rwin" SL "rfile3 " SL "rwin" SL "rfile5 ",
133 expanded);
134 free(expanded);
135
136 expanded = ma_expand(" cp %b:p ", "", &flags, 1);
137 assert_string_equal(
138 " cp " SL "lwin" SL "lfile0 " SL "lwin" SL "lfile2 " SL "rwin" SL"rfile1 " SL "rwin" SL "rfile3 " SL "rwin" SL "rfile5 ",
139 expanded);
140 free(expanded);
141
142 expanded = ma_expand(" cp %c:p ", "", &flags, 1);
143 assert_string_equal(" cp " SL "lwin" SL "lfile2 ", expanded);
144 free(expanded);
145
146 expanded = ma_expand(" cp %C:p ", "", &flags, 1);
147 assert_string_equal(" cp " SL "rwin" SL "rfile5 ", expanded);
148 free(expanded);
149
150 expanded = ma_expand(" cp %d:p ", "", &flags, 1);
151 assert_string_equal(" cp " SL "lwin ", expanded);
152 free(expanded);
153
154 expanded = ma_expand(" cp %D:p ", "", &flags, 1);
155 assert_string_equal(" cp " SL "rwin ", expanded);
156 free(expanded);
157
158 expanded = ma_expand(" cp %rz:p ", "", &flags, 1);
159 assert_string_equal(" cp " SL "lwin" SL "existing-files" SL "a " SL "lwin" SL "existing-files" SL "b " SL "lwin" SL "existing-files" SL "c ", expanded);
160 free(expanded);
161 }
162
TEST(colon_p_in_root)163 TEST(colon_p_in_root)
164 {
165 MacroFlags flags;
166 char *expanded;
167
168 strcpy(lwin.curr_dir, "/");
169
170 expanded = ma_expand(" cp %f:p ", "", &flags, 1);
171 assert_string_equal(" cp " SL "lfile0 " SL "lfile2 ", expanded);
172 free(expanded);
173
174 expanded = ma_expand(" cp %F:p ", "", &flags, 1);
175 assert_string_equal(" cp " SL "rwin" SL "rfile1 " SL "rwin" SL "rfile3 " SL "rwin" SL "rfile5 ",
176 expanded);
177 free(expanded);
178
179 expanded = ma_expand(" cp %b:p ", "", &flags, 1);
180 assert_string_equal(
181 " cp " SL "lfile0 " SL "lfile2 " SL "rwin" SL"rfile1 " SL "rwin" SL "rfile3 " SL "rwin" SL "rfile5 ",
182 expanded);
183 free(expanded);
184
185 expanded = ma_expand(" cp %c:p ", "", &flags, 1);
186 assert_string_equal(" cp " SL "lfile2 ", expanded);
187 free(expanded);
188
189 expanded = ma_expand(" cp %C:p ", "", &flags, 1);
190 assert_string_equal(" cp " SL "rwin" SL "rfile5 ", expanded);
191 free(expanded);
192
193 expanded = ma_expand(" cp %d:p ", "", &flags, 1);
194 assert_string_equal(" cp " SL " ", expanded);
195 free(expanded);
196
197 expanded = ma_expand(" cp %D:p ", "", &flags, 1);
198 assert_string_equal(" cp " SL "rwin ", expanded);
199 free(expanded);
200
201 expanded = ma_expand(" cp %rz:p ", "", &flags, 1);
202 assert_string_equal(" cp " SL "existing-files" SL "a " SL "existing-files" SL "b " SL "existing-files" SL "c ", expanded);
203 free(expanded);
204 }
205
TEST(colon_tilde)206 TEST(colon_tilde)
207 {
208 MacroFlags flags;
209 char *expanded;
210
211 expanded = ma_expand(" cp %f:~ ", "", &flags, 1);
212 assert_string_equal(" cp lfile0 lfile2 ", expanded);
213 free(expanded);
214
215 expanded = ma_expand(" cp %f:p:~ ", "", &flags, 1);
216 assert_string_equal(" cp " SL "lwin" SL "lfile0 " SL "lwin" SL "lfile2 ",
217 expanded);
218 free(expanded);
219
220 expanded = ma_expand(" cp %F:~ ", "", &flags, 1);
221 assert_string_equal(" cp \\~" SL "rfile1 \\~" SL "rfile3 \\~" SL "rfile5 ",
222 expanded);
223 free(expanded);
224
225 expanded = ma_expand(" cp %b:p:~ ", "", &flags, 1);
226 assert_string_equal(
227 " cp " SL "lwin" SL "lfile0 " SL "lwin" SL "lfile2 \\~" SL "rfile1 \\~" SL "rfile3 \\~" SL "rfile5 ",
228 expanded);
229 free(expanded);
230
231 expanded = ma_expand(" cp %b:~ ", "", &flags, 1);
232 assert_string_equal(" cp lfile0 lfile2 \\~" SL "rfile1 \\~" SL "rfile3 \\~" SL "rfile5 ",
233 expanded);
234 free(expanded);
235
236 expanded = ma_expand(" cp %c:~ ", "", &flags, 1);
237 assert_string_equal(" cp lfile2 ", expanded);
238 free(expanded);
239
240 expanded = ma_expand(" cp %c:p:~ ", "", &flags, 1);
241 assert_string_equal(" cp " SL "lwin" SL "lfile2 ", expanded);
242 free(expanded);
243
244 expanded = ma_expand(" cp %C:~ ", "", &flags, 1);
245 assert_string_equal(" cp \\~" SL "rfile5 ", expanded);
246 free(expanded);
247
248 expanded = ma_expand(" cp %d:~ ", "", &flags, 1);
249 assert_string_equal(" cp " SL "lwin ", expanded);
250 free(expanded);
251
252 expanded = ma_expand(" cp %D:~ ", "", &flags, 1);
253 assert_string_equal(" cp \\~ ", expanded);
254 free(expanded);
255
256 expanded = ma_expand(" cp %rz:~ ", "", &flags, 1);
257 assert_string_equal(" cp existing-files" SL "a existing-files" SL "b existing-files" SL "c ", expanded);
258 free(expanded);
259 }
260
TEST(colon_dot)261 TEST(colon_dot)
262 {
263 MacroFlags flags;
264 char *expanded;
265
266 expanded = ma_expand(" cp %f:. ", "", &flags, 1);
267 assert_string_equal(" cp lfile0 lfile2 ", expanded);
268 free(expanded);
269
270 expanded = ma_expand(" cp %f:p:. ", "", &flags, 1);
271 assert_string_equal(" cp lfile0 lfile2 ", expanded);
272 free(expanded);
273
274 expanded = ma_expand(" cp %F:~:. ", "", &flags, 1);
275 assert_string_equal(" cp \\~" SL "rfile1 \\~" SL "rfile3 \\~" SL "rfile5 ",
276 expanded);
277 free(expanded);
278
279 expanded = ma_expand(" cp %F:. ", "", &flags, 1);
280 assert_string_equal(" cp " SL "rwin" SL "rfile1 " SL "rwin" SL "rfile3 " SL "rwin" SL "rfile5 ",
281 expanded);
282 free(expanded);
283
284 expanded = ma_expand(" cp %b:. ", "", &flags, 1);
285 assert_string_equal(
286 " cp lfile0 lfile2 " SL "rwin" SL "rfile1 " SL "rwin" SL "rfile3 " SL "rwin" SL "rfile5 ",
287 expanded);
288 free(expanded);
289
290 expanded = ma_expand(" cp %b:p:. ", "", &flags, 1);
291 assert_string_equal(
292 " cp lfile0 lfile2 " SL "rwin" SL "rfile1 " SL "rwin" SL "rfile3 " SL "rwin" SL "rfile5 ",
293 expanded);
294 free(expanded);
295
296 expanded = ma_expand(" cp %c:. ", "", &flags, 1);
297 assert_string_equal(" cp lfile2 ", expanded);
298 free(expanded);
299
300 expanded = ma_expand(" cp %c:p:. ", "", &flags, 1);
301 assert_string_equal(" cp lfile2 ", expanded);
302 free(expanded);
303
304 expanded = ma_expand(" cp %C:. ", "", &flags, 1);
305 assert_string_equal(" cp " SL "rwin" SL "rfile5 ", expanded);
306 free(expanded);
307
308 expanded = ma_expand(" cp %d:. ", "", &flags, 1);
309 assert_string_equal(" cp " SL "lwin ", expanded);
310 free(expanded);
311
312 expanded = ma_expand(" cp %D:. ", "", &flags, 1);
313 assert_string_equal(" cp " SL "rwin ", expanded);
314 free(expanded);
315
316 expanded = ma_expand(" cp %rz:. ", "", &flags, 1);
317 assert_string_equal(" cp existing-files" SL "a existing-files" SL "b existing-files" SL "c ", expanded);
318 free(expanded);
319 }
320
TEST(colon_h)321 TEST(colon_h)
322 {
323 MacroFlags flags;
324 char *expanded;
325
326 expanded = ma_expand(" cp %f:h ", "", &flags, 1);
327 assert_string_equal(" cp . . ", expanded);
328 free(expanded);
329
330 expanded = ma_expand(" cp %f:p:h ", "", &flags, 1);
331 assert_string_equal(" cp " SL "lwin " SL "lwin ", expanded);
332 free(expanded);
333
334 expanded = ma_expand(" cp %F:~:h ", "", &flags, 1);
335 assert_string_equal(" cp \\~ \\~ \\~ ", expanded);
336 free(expanded);
337
338 expanded = ma_expand(" cp %F:h ", "", &flags, 1);
339 assert_string_equal(" cp " SL "rwin " SL "rwin " SL "rwin ", expanded);
340 free(expanded);
341
342 expanded = ma_expand(" cp %b:h ", "", &flags, 1);
343 assert_string_equal(" cp . . " SL "rwin " SL "rwin " SL "rwin ", expanded);
344 free(expanded);
345
346 expanded = ma_expand(" cp %b:p:h ", "", &flags, 1);
347 assert_string_equal(" cp " SL "lwin " SL "lwin " SL "rwin " SL "rwin " SL "rwin ",
348 expanded);
349 free(expanded);
350
351 expanded = ma_expand(" cp %c:p:h ", "", &flags, 1);
352 assert_string_equal(" cp " SL "lwin ", expanded);
353 free(expanded);
354
355 expanded = ma_expand(" cp %C:h ", "", &flags, 1);
356 assert_string_equal(" cp " SL "rwin ", expanded);
357 free(expanded);
358
359 expanded = ma_expand(" cp %d:h ", "", &flags, 1);
360 assert_string_equal(" cp " SL " ", expanded);
361 free(expanded);
362
363 expanded = ma_expand(" cp %D:h:h ", "", &flags, 1);
364 assert_string_equal(" cp " SL " ", expanded);
365 free(expanded);
366
367 expanded = ma_expand(" cp %rz:h ", "", &flags, 1);
368 assert_string_equal(" cp existing-files existing-files existing-files ", expanded);
369 free(expanded);
370 }
371
TEST(colon_t)372 TEST(colon_t)
373 {
374 MacroFlags flags;
375 char *expanded;
376
377 expanded = ma_expand(" cp %f:t ", "", &flags, 1);
378 assert_string_equal(" cp lfile0 lfile2 ", expanded);
379 free(expanded);
380
381 expanded = ma_expand(" cp %f:p:t ", "", &flags, 1);
382 assert_string_equal(" cp lfile0 lfile2 ", expanded);
383 free(expanded);
384
385 expanded = ma_expand(" cp %F:t ", "", &flags, 1);
386 assert_string_equal(" cp rfile1 rfile3 rfile5 ", expanded);
387 free(expanded);
388
389 expanded = ma_expand(" cp %b:t ", "", &flags, 1);
390 assert_string_equal(" cp lfile0 lfile2 rfile1 rfile3 rfile5 ", expanded);
391 free(expanded);
392
393 expanded = ma_expand(" cp %b:p:t ", "", &flags, 1);
394 assert_string_equal(" cp lfile0 lfile2 rfile1 rfile3 rfile5 ", expanded);
395 free(expanded);
396
397 expanded = ma_expand(" cp %c:t ", "", &flags, 1);
398 assert_string_equal(" cp lfile2 ", expanded);
399 free(expanded);
400
401 expanded = ma_expand(" cp %c:p:t ", "", &flags, 1);
402 assert_string_equal(" cp lfile2 ", expanded);
403 free(expanded);
404
405 expanded = ma_expand(" cp %C:t ", "", &flags, 1);
406 assert_string_equal(" cp rfile5 ", expanded);
407 free(expanded);
408
409 expanded = ma_expand(" cp %d:t ", "", &flags, 1);
410 assert_string_equal(" cp lwin ", expanded);
411 free(expanded);
412
413 expanded = ma_expand(" cp %D:t:t ", "", &flags, 1);
414 assert_string_equal(" cp rwin ", expanded);
415 free(expanded);
416
417 expanded = ma_expand(" cp %rz:t ", "", &flags, 1);
418 assert_string_equal(" cp a b c ", expanded);
419 free(expanded);
420 }
421
TEST(colon_r)422 TEST(colon_r)
423 {
424 MacroFlags flags;
425 char *expanded;
426
427 strcpy(rwin.curr_dir, "/rw.in");
428 rwin.list_pos = 4;
429
430 expanded = ma_expand(" cp %c:r ", "", &flags, 1);
431 assert_string_equal(" cp lfile2 ", expanded);
432 free(expanded);
433
434 expanded = ma_expand(" cp %c:r:r ", "", &flags, 1);
435 assert_string_equal(" cp lfile2 ", expanded);
436 free(expanded);
437
438 expanded = ma_expand(" cp %c:p:r ", "", &flags, 1);
439 assert_string_equal(" cp " SL "lwin" SL "lfile2 ", expanded);
440 free(expanded);
441
442 expanded = ma_expand(" cp %C:r ", "", &flags, 1);
443 assert_string_equal(" cp " SL "rw.in" SL "rfile4.tar ", expanded);
444 free(expanded);
445
446 expanded = ma_expand(" cp %C:r:r ", "", &flags, 1);
447 assert_string_equal(" cp " SL "rw.in" SL "rfile4 ", expanded);
448 free(expanded);
449
450 expanded = ma_expand(" cp %C:r:r:r ", "", &flags, 1);
451 assert_string_equal(" cp " SL "rw.in" SL "rfile4 ", expanded);
452 free(expanded);
453
454 expanded = ma_expand(" cp %d:r ", "", &flags, 1);
455 assert_string_equal(" cp " SL "lwin ", expanded);
456 free(expanded);
457
458 expanded = ma_expand(" cp %D:r ", "", &flags, 1);
459 assert_string_equal(" cp " SL "rw ", expanded);
460 free(expanded);
461
462 lwin.list_pos = 4;
463
464 expanded = ma_expand(" cp %c:r ", "", &flags, 1);
465 assert_string_equal(" cp .lfile4 ", expanded);
466 free(expanded);
467
468 expanded = ma_expand(" cp %c:p:r ", "", &flags, 1);
469 assert_string_equal(" cp " SL "lwin" SL ".lfile4 ", expanded);
470 free(expanded);
471
472 expanded = ma_expand(" cp %rz:t:r ", "", &flags, 1);
473 assert_string_equal(" cp a b c ", expanded);
474 free(expanded);
475 }
476
TEST(colon_e)477 TEST(colon_e)
478 {
479 MacroFlags flags;
480 char *expanded;
481
482 strcpy(rwin.curr_dir, "" SL "rw.in");
483 rwin.list_pos = 4;
484
485 expanded = ma_expand(" cp %c:e ", "", &flags, 1);
486 assert_string_equal(" cp ", expanded);
487 free(expanded);
488
489 expanded = ma_expand(" cp %c:e:e ", "", &flags, 1);
490 assert_string_equal(" cp ", expanded);
491 free(expanded);
492
493 expanded = ma_expand(" cp %c:p:e ", "", &flags, 1);
494 assert_string_equal(" cp ", expanded);
495 free(expanded);
496
497 expanded = ma_expand(" cp %C:e ", "", &flags, 1);
498 assert_string_equal(" cp gz ", expanded);
499 free(expanded);
500
501 expanded = ma_expand(" cp %C:e:e ", "", &flags, 1);
502 assert_string_equal(" cp ", expanded);
503 free(expanded);
504
505 rwin.list_pos = 2;
506
507 expanded = ma_expand(" cp %C:e ", "", &flags, 1);
508 assert_string_equal(" cp ", expanded);
509 free(expanded);
510
511 expanded = ma_expand(" cp %d:e ", "", &flags, 1);
512 assert_string_equal(" cp ", expanded);
513 free(expanded);
514
515 expanded = ma_expand(" cp %D:e ", "", &flags, 1);
516 assert_string_equal(" cp in ", expanded);
517 free(expanded);
518
519 lwin.list_pos = 4;
520
521 expanded = ma_expand(" cp %c:e ", "", &flags, 1);
522 assert_string_equal(" cp ", expanded);
523 free(expanded);
524
525 expanded = ma_expand(" cp %c:p:e ", "", &flags, 1);
526 assert_string_equal(" cp ", expanded);
527 free(expanded);
528
529 expanded = ma_expand(" cp %rz:t:. ", "", &flags, 1);
530 assert_string_equal(" cp a b c ", expanded);
531 free(expanded);
532 }
533
TEST(colon_s)534 TEST(colon_s)
535 {
536 MacroFlags flags;
537 char *expanded;
538
539 expanded = ma_expand(" cp %f:s?l?r ", "", &flags, 1);
540 assert_string_equal(" cp lfile0 lfile2", expanded);
541 free(expanded);
542
543 expanded = ma_expand(" cp %f:s?l?r? ", "", &flags, 1);
544 assert_string_equal(" cp rfile0 rfile2 ", expanded);
545 free(expanded);
546
547 expanded = ma_expand(" cp %f:salara ", "", &flags, 1);
548 assert_string_equal(" cp rfile0 rfile2 ", expanded);
549 free(expanded);
550
551 expanded = ma_expand(" cp %f:s?l?r?k? ", "", &flags, 1);
552 assert_string_equal(" cp rfile0 rfile2k? ", expanded);
553 free(expanded);
554
555 expanded = ma_expand(" cp %f:s?l?r?:s!f!k!k? ", "", &flags, 1);
556 assert_string_equal(" cp rkile0 rkile2k? ", expanded);
557 free(expanded);
558
559 expanded = ma_expand(" cp %rz:t:s?a?y? ", "", &flags, 1);
560 assert_string_equal(" cp y b c ", expanded);
561 free(expanded);
562 }
563
TEST(colon_gs)564 TEST(colon_gs)
565 {
566 MacroFlags flags;
567 char *expanded;
568
569 expanded = ma_expand(" cp %f:gs?l?r ", "", &flags, 1);
570 assert_string_equal(" cp lfile0 lfile2", expanded);
571 free(expanded);
572
573 expanded = ma_expand(" cp %f:gs?l?r? ", "", &flags, 1);
574 assert_string_equal(" cp rfire0 rfire2 ", expanded);
575 free(expanded);
576
577 expanded = ma_expand(" cp %f:gsalara ", "", &flags, 1);
578 assert_string_equal(" cp rfire0 rfire2 ", expanded);
579 free(expanded);
580
581 expanded = ma_expand(" cp %f:gs?l?r?k? ", "", &flags, 1);
582 assert_string_equal(" cp rfire0 rfire2k? ", expanded);
583 free(expanded);
584
585 expanded = ma_expand(" cp %rz:t:gs?b?y? ", "", &flags, 1);
586 assert_string_equal(" cp a y c ", expanded);
587 free(expanded);
588
589 #ifdef _WIN32
590 {
591 char *old = cfg.shell;
592 cfg.shell = strdup("bash");
593 expanded = ma_expand(" cp %f:p:gs?\\?/? ", "", &flags, 1);
594 assert_string_equal(" cp /lwin/lfile0 /lwin/lfile2 ", expanded);
595 free(expanded);
596 free(cfg.shell);
597 cfg.shell = old;
598 }
599 #endif
600 }
601
602 #ifdef _WIN32
603
TEST(colon_u)604 TEST(colon_u)
605 {
606 MacroFlags flags;
607 char *expanded;
608
609 expanded = ma_expand("%f:p:u", "", &flags, 1);
610 assert_string_starts_with("\\\\", expanded);
611 free(expanded);
612
613 strcpy(lwin.curr_dir, "//server/share/directory");
614
615 expanded = ma_expand(" cp %f:p:u ", "", &flags, 1);
616 assert_string_equal(" cp " SL SL "server " SL SL "server ", expanded);
617 free(expanded);
618 }
619
TEST(windows_specific)620 TEST(windows_specific)
621 {
622 MacroFlags flags;
623 char *expanded;
624
625 strcpy(lwin.curr_dir, "h:/rwin");
626
627 expanded = ma_expand(" %d:h ", "", &flags, 1);
628 assert_string_equal(" h:\\\\ ", expanded);
629 free(expanded);
630
631 expanded = ma_expand(" %d:h:h ", "", &flags, 1);
632 assert_string_equal(" h:\\\\ ", expanded);
633 free(expanded);
634
635 strcpy(lwin.curr_dir, "//ZX-Spectrum");
636
637 expanded = ma_expand(" %d:h ", "", &flags, 1);
638 assert_string_equal(" \\\\\\\\ZX-Spectrum ", expanded);
639 free(expanded);
640
641 expanded = ma_expand(" %d:h:h ", "", &flags, 1);
642 assert_string_equal(" \\\\\\\\ZX-Spectrum ", expanded);
643 free(expanded);
644 }
645
646 #endif
647
TEST(modif_without_macros)648 TEST(modif_without_macros)
649 {
650 MacroFlags flags;
651 char *expanded;
652
653 expanded = ma_expand(" cp %f:t :p :~ :. :h :t :r :e :s :gs ", "", &flags, 0);
654 assert_string_equal(" cp lfile0 lfile2 :p :~ :. :h :t :r :e :s :gs ",
655 expanded);
656 free(expanded);
657 }
658
TEST(with_quotes)659 TEST(with_quotes)
660 {
661 MacroFlags flags;
662
663 char *expanded = ma_expand(" cp %\"f:p ", "", &flags, 1);
664 assert_string_equal(" cp \"" SL "lwin" SL "lfile0\" \"" SL "lwin" SL "lfile2\" ",
665 expanded);
666 free(expanded);
667 }
668
669 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
670 /* vim: set cinoptions+=t0 filetype=c : */
671