1#!/usr/bin/perl
2
3# Z88DK Z80 Macro Assembler
4#
5# Copyright (C) Gunther Strube, InterLogic 1993-99
6# Copyright (C) Paulo Custodio, 2011-2020
7# License: The Artistic License 2.0, http://www.perlfoundation.org/artistic_license_2_0
8# Repository: https://github.com/z88dk/z88dk/
9#
10# Test https://github.com/z88dk/z88dk/issues/835
11# z80asm - ELIF assembly directive
12# Also: test IF et al
13
14use Modern::Perl;
15use Test::More;
16require './t/testlib.pl';
17
18unlink_testfiles();
19
20my @cond = ('', '-DONE', '-DTWO', '-DTHREE');
21
22# chained IF/ELSE IF
23spew("test.asm", <<'...');
24	if ONE
25		defb 1
26	else
27		if TWO
28			defb 2
29		else
30			if THREE
31				defb 3
32			else
33				defb 0
34			endif
35		endif
36	endif
37...
38
39for (0..$#cond) {
40	run("z80asm -b $cond[$_] test.asm", 0, '', '');
41	check_bin_file("test.bin", pack("C*", $_));
42}
43
44# IF/ELIF
45spew("test.asm", <<'...');
46	if ONE
47		defb 1
48	elif TWO
49		defb 2
50	elif THREE
51		defb 3
52	else
53		defb 0
54	endif
55...
56
57for (0..$#cond) {
58	run("z80asm -b $cond[$_] test.asm", 0, '', '');
59	check_bin_file("test.bin", pack("C*", $_));
60}
61
62# chained IFDEF/ELSE IFDEF
63spew("test.asm", <<'...');
64	ifdef ONE
65		defb 1
66	else
67		ifdef TWO
68			defb 2
69		else
70			ifdef THREE
71				defb 3
72			else
73				defb 0
74			endif
75		endif
76	endif
77...
78
79for (0..$#cond) {
80	run("z80asm -b $cond[$_] test.asm", 0, '', '');
81	check_bin_file("test.bin", pack("C*", $_));
82}
83
84# IF/ELIFDEF
85spew("test.asm", <<'...');
86	ifdef ONE
87		defb 1
88	elifdef TWO
89		defb 2
90	elifdef THREE
91		defb 3
92	else
93		defb 0
94	endif
95...
96
97for (0..$#cond) {
98	run("z80asm -b $cond[$_] test.asm", 0, '', '');
99	check_bin_file("test.bin", pack("C*", $_));
100}
101
102
103@cond = (
104	'-DONE -DTWO -DTHREE',
105	'      -DTWO -DTHREE',
106	'-DONE       -DTHREE',
107	'-DONE -DTWO        ');
108
109# chained IFNDEF/ELSE IFNDEF
110spew("test.asm", <<'...');
111	ifndef ONE
112		defb 1
113	else
114		ifndef TWO
115			defb 2
116		else
117			ifndef THREE
118				defb 3
119			else
120				defb 0
121			endif
122		endif
123	endif
124...
125
126for (0..$#cond) {
127	run("z80asm -b $cond[$_] test.asm", 0, '', '');
128	check_bin_file("test.bin", pack("C*", $_));
129}
130
131# IF/ELIFNDEF
132spew("test.asm", <<'...');
133	ifndef ONE
134		defb 1
135	elifndef TWO
136		defb 2
137	elifndef THREE
138		defb 3
139	else
140		defb 0
141	endif
142...
143
144for (0..$#cond) {
145	run("z80asm -b $cond[$_] test.asm", 0, '', '');
146	check_bin_file("test.bin", pack("C*", $_));
147}
148
149unlink_testfiles();
150done_testing();
151