summaryrefslogtreecommitdiff
path: root/tests/general/tpp.icn
blob: b2a7e829e0e3d335f6115ee1d6cd7c7770997288 (plain)
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# tpp.icn -- test file for Icon preprocessor
#
# generates lots of deliberate errors
# includes tpp1.icn, tpp2.icn, tpp3.icn

# force out #lines to test that this file is called "stdin"
$include "/dev/null"

# following should be legal
#line 11 "a.b.c"
#line 22 defgh
#line 33"ijklm"#
#line 44
#line 55xyzzy#comment

#line 0 "bad #lines"
# following should be illegal but ignored
#line 
#line 91 not.quoted
#line 92 extra stuff
#line 93 "extra" stuff
#line 94 extra+
# line 95 "passed through unrecognized"
#line 96 "unterminated
#line 97 "unterminated\
#line 98 ""

# following should be legal
$line 11 "a.b.c"
  $  line  22  defgh
$line 33"ijklm"#comment
$line 44
$line 55xyzzy#comment
$( digraphs for EBCDIC $)

$line 0 "bad.ppdirs"
# following should be illegal and diagnosed
$line
$line 91 not.quoted
$line 92 extra stuff
$line 93 "extra" stuff
$line 94 extra+
$line 96 "unterminated
$line 97 "unterminated\
$line 98""
$unknown/preprocessing/directive

$line 0 "include.tests"
=a=
$include "/dev/null"
=b=
    $ 	 include    "/dev/null"    		# comment
=c=
$include"abc\def\"ghi#jkl\#mno\\pqr stu"	# lots of escapes
=d=
$include					# no name (two ways)
=e=
$include			
=f=
$include "unterminated
=g=
$include "unterminated\
=h=
$include nonexistent
=i=
$include extra+
=j=
$include "more extra stuff" dafslkjasfd
=k=
$include "tpp1.icn"	# should get circularity error
=l=
$include"tpp3.icn"#likewise
=m=

$line 0 "predef.tst"
#== predef test ==
should be defined as 1:  _UNIX  _ASCII  _PIPES  _SYSTEM_FUNCTION
should not be defined:  _MACINTOSH  _VMS  _EBCDIC  _DOS_FUNCTIONS
it depends: _COMPILED _INTERPRETED
$undef _PIPES
$undef _ASCII
$define _ASCII 128
$define _EBCDIC 0
bogus:  pipes:_PIPES  ascii:_ASCII  ebcdic:_EBCDIC

$line 0 "define.tst"
#== define test ==

#= illegal =
$define
$define 12
$define "fred" 93
$define b1 "
$define b2 'dsfkjlfasd\'
$define f(x) (x^2+2*x+1)

#= null =
$define n1
$define n2    	# also null
a=n1=b=n2=c

#= simple =
$define one 1
$define pi 3.14159
$define plus +
$define twine "string"
$define vowels 'aeiou'
$define expr ((sqrt(5) + 1) / 2)	#phi
$define xy_47_Hike "fffrtb"
$undef nothing

one pi plus twine vowels expr xy_47_Hike
one+pi,plus/twine,vowels\expr?xy_47_Hike!	# one pi plus etc
one"pi"plus"twine"vowels"expr"xy_47_Hike
'one'pi'plus'twine'vowels'expr'xy_47_Hike'

#= redefinition =
$define pi 2.7183
pi
$undef pi
$define pi 2.7183
pi

#= deferred interpretation =
$define aaa bbb
$define bbb 42
aaa bbb

$define yyy xxx
$define xxx 47
xxx yyy

#= dubious pasting=
$define X e3
$define Y 456e
123X  Y+3

#= recursion =
$define r r
r
$define rr rr rr
rr
$define a b b b
$define b c c c
$define c a a a
a
b
c

= context =
$define _ <%>
123_abc+_+123_+abc_+_"_"_+36rX_+123e10_+12.e+5_+e7_+_#_

$line 0 "error.tst"
#= $error =
$error
   $error		
$error	# no text, just comment
   $    error     this program does not work

$line 0 "if.tst"
#= conditional compilation =

$define isdef

# $ifdef & $ifndef both true and false, with and without $else

$ifdef isdef
   "isdef is defined"
$endif

$ifdef notdef
   "notdef is defined"
$endif

$ifndef isdef
   "isdef is not defined"
$endif

$ifndef notdef
   "notdef is not defined"
$endif

$ifdef isdef
   "isdef is defined"
$else
   "isdef is not defined"
$endif

$ifdef notdef
   "notdef is defined"
$else
   "notdef is not defined"
$endif

# nesting without $else

$ifdef isdef
   (true...)
   $ifndef isdef
       (wrong...)
       $ifdef isdef
	   (yes, but skipped)
       $endif
       (...wrong)
   $endif
   (...true)
$endif

# full nesting, with some nonstandard spacing

$ifdef isdef	# meaningless comment
   (begin true branch)
   $ ifdef isdef
      "isdef is defined"
   $ else	# else
      "isdef is not defined"
   $ endif	# endif
   (end true branch)
  $  else	#isdef not defined
   (begin else branch)
   $ ifdef notdef
      "notdef is defined"
   $ else
      "notdef is not defined"
   $ endif
   (end true branch)
  $ endif	# end test

# test all paths through four nested ifs
$include "tpp4.icn"
$define id4 *4*
$include "tpp4.icn"
$define id3 *3*
$include "tpp4.icn"
$undef id4
$include "tpp4.icn"
$define id2 *2*
$include "tpp4.icn"
$define id4 *4*
$include "tpp4.icn"
$undef id3
$include "tpp4.icn"
$undef id4
$include "tpp4.icn"
$define id1 *1*
$include "tpp4.icn"
$define id4 *4*
$include "tpp4.icn"
$define id3 *3*
$include "tpp4.icn"
$undef id4
$include "tpp4.icn"
$undef id2
$include "tpp4.icn"
$define id4 *4*
$include "tpp4.icn"
$undef id3
$include "tpp4.icn"
$undef id4
$include "tpp4.icn"
$undef id1

# make sure it accepts anything resembling an $if when skipping

$ifdef notdef
   <skipped>
   $bogus	# should be no problem when skipped
   <skipped>
   $ifread "/some/file/that/doesnt/really/exist"
      $include "/some/file/that/doesnt/really/exist"
   $endif  #ifexists
   <should still be skipping>
$endif
<should pass this line>

# test diagnostics for missing args
$ifdef
$endif
$ifndef		# missing here too
$endif

# test diagnostics for extraneous args
$ifdef notdef
$else notdef
$endif notdef
$ifndef notdef
$else notdef
$endif notdef

# test else/endif out of place
$endif			# wrong place -- should get error
$else			# wrong place -- should get error
$include "tpp5.icn"	# includes unterminated $ifdef
$else			# should <not> match $if in tpp5.icn
$endif			# should <not> match $if in tpp5.icn
# now try again when unterminated $if succeeds
$define id5
$include "tpp5.icn"	# includes unterminated $ifdef
$else			# should <not> match $if in tpp5.icn
$endif			# should <not> match $if in tpp5.icn

# test line directives encountered while skipping

$ifdef notdef
...
#line 111 "invented"
...
$endif (& show line)

$ifdef notdef
...
  $   line    222    "invented"
...
$endif (& show line)