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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
|
"""
Test parsing single Fortran lines.
-----
Permission to use, modify, and distribute this software is given under the
terms of the NumPy License. See http://scipy.org.
NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
Author: Pearu Peterson <pearu@cens.ioc.ee>
Created: May 2006
-----
"""
from numpy.testing import *
from block_statements import *
from readfortran import Line, FortranStringReader
def parse(cls, line, label='',
isfree=True, isstrict=False):
if label:
line = label + ' : ' + line
reader = FortranStringReader(line, isfree, isstrict)
item = reader.next()
if not cls.match(item.get_line()):
raise ValueError, '%r does not match %s pattern' % (line, cls.__name__)
stmt = cls(item, item)
if stmt.isvalid:
r = str(stmt)
if not isstrict:
r1 = parse(cls, r, isstrict=True)
if r != r1:
raise ValueError, 'Failed to parse %r with %s pattern in pyf mode, got %r' % (r, cls.__name__, r1)
return r
raise ValueError, 'parsing %r with %s pattern failed' % (line, cls.__name__)
class TestStatements(TestCase):
def test_assignment(self):
assert_equal(parse(Assignment,'a=b'), 'a = b')
assert_equal(parse(PointerAssignment,'a=>b'), 'a => b')
assert_equal(parse(Assignment,'a (2)=b(n,m)'), 'a(2) = b(n,m)')
assert_equal(parse(Assignment,'a % 2(2,4)=b(a(i))'), 'a%2(2,4) = b(a(i))')
def test_assign(self):
assert_equal(parse(Assign,'assign 10 to a'),'ASSIGN 10 TO a')
def test_call(self):
assert_equal(parse(Call,'call a'),'CALL a')
assert_equal(parse(Call,'call a()'),'CALL a')
assert_equal(parse(Call,'call a(1)'),'CALL a(1)')
assert_equal(parse(Call,'call a(1,2)'),'CALL a(1, 2)')
assert_equal(parse(Call,'call a % 2 ( n , a+1 )'),'CALL a % 2(n, a+1)')
def test_goto(self):
assert_equal(parse(Goto,'go to 19'),'GO TO 19')
assert_equal(parse(Goto,'goto 19'),'GO TO 19')
assert_equal(parse(ComputedGoto,'goto (1, 2 ,3) a+b(2)'),
'GO TO (1, 2, 3) a+b(2)')
assert_equal(parse(ComputedGoto,'goto (1, 2 ,3) , a+b(2)'),
'GO TO (1, 2, 3) a+b(2)')
assert_equal(parse(AssignedGoto,'goto a'),'GO TO a')
assert_equal(parse(AssignedGoto,'goto a ( 1 )'),'GO TO a (1)')
assert_equal(parse(AssignedGoto,'goto a ( 1 ,2)'),'GO TO a (1, 2)')
def test_continue(self):
assert_equal(parse(Continue,'continue'),'CONTINUE')
def test_return(self):
assert_equal(parse(Return,'return'),'RETURN')
assert_equal(parse(Return,'return a'),'RETURN a')
assert_equal(parse(Return,'return a+1'),'RETURN a+1')
assert_equal(parse(Return,'return a(c, a)'),'RETURN a(c, a)')
def test_stop(self):
assert_equal(parse(Stop,'stop'),'STOP')
assert_equal(parse(Stop,'stop 1'),'STOP 1')
assert_equal(parse(Stop,'stop "a"'),'STOP "a"')
assert_equal(parse(Stop,'stop "a b"'),'STOP "a b"')
def test_print(self):
assert_equal(parse(Print, 'print*'),'PRINT *')
assert_equal(parse(Print, 'print "a b( c )"'),'PRINT "a b( c )"')
assert_equal(parse(Print, 'print 12, a'),'PRINT 12, a')
assert_equal(parse(Print, 'print 12, a , b'),'PRINT 12, a, b')
assert_equal(parse(Print, 'print 12, a(c,1) , b'),'PRINT 12, a(c,1), b')
def test_read(self):
assert_equal(parse(Read, 'read ( 10 )'),'READ (10)')
assert_equal(parse(Read, 'read ( 10 ) a '),'READ (10) a')
assert_equal(parse(Read, 'read ( 10 ) a , b'),'READ (10) a, b')
assert_equal(parse(Read, 'read *'),'READ *')
assert_equal(parse(Read, 'read 12'),'READ 12')
assert_equal(parse(Read, 'read "a b"'),'READ "a b"')
assert_equal(parse(Read, 'read "a b",a'),'READ "a b", a')
assert_equal(parse(Read, 'read * , a'),'READ *, a')
assert_equal(parse(Read, 'read "hey a" , a'),'READ "hey a", a')
assert_equal(parse(Read, 'read * , a , b'),'READ *, a, b')
assert_equal(parse(Read, 'read ( unit =10 )'),'READ (UNIT = 10)')
def test_write(self):
assert_equal(parse(Write, 'write ( 10 )'),'WRITE (10)')
assert_equal(parse(Write, 'write ( 10 , a )'),'WRITE (10, a)')
assert_equal(parse(Write, 'write ( 10 ) b'),'WRITE (10) b')
assert_equal(parse(Write, 'write ( 10 ) a(1) , b+2'),'WRITE (10) a(1), b+2')
assert_equal(parse(Write, 'write ( unit=10 )'),'WRITE (UNIT = 10)')
def test_flush(self):
assert_equal(parse(Flush, 'flush 10'),'FLUSH (10)')
assert_equal(parse(Flush, 'flush (10)'),'FLUSH (10)')
assert_equal(parse(Flush, 'flush (UNIT = 10)'),'FLUSH (UNIT = 10)')
assert_equal(parse(Flush, 'flush (10, err= 23)'),'FLUSH (10, ERR = 23)')
def test_wait(self):
assert_equal(parse(Wait, 'wait(10)'),'WAIT (10)')
assert_equal(parse(Wait, 'wait(10,err=129)'),'WAIT (10, ERR = 129)')
def test_contains(self):
assert_equal(parse(Contains, 'contains'),'CONTAINS')
def test_allocate(self):
assert_equal(parse(Allocate, 'allocate (a)'), 'ALLOCATE (a)')
assert_equal(parse(Allocate, \
'allocate (a, stat=b)'), 'ALLOCATE (a, STAT = b)')
assert_equal(parse(Allocate, 'allocate (a,b(:1))'), 'ALLOCATE (a, b(:1))')
assert_equal(parse(Allocate, \
'allocate (real(8)::a)'), 'ALLOCATE (REAL(KIND=8) :: a)')
def test_deallocate(self):
assert_equal(parse(Deallocate, 'deallocate (a)'), 'DEALLOCATE (a)')
assert_equal(parse(Deallocate, 'deallocate (a, stat=b)'), 'DEALLOCATE (a, STAT = b)')
def test_moduleprocedure(self):
assert_equal(parse(ModuleProcedure,\
'ModuleProcedure a'), 'MODULE PROCEDURE a')
assert_equal(parse(ModuleProcedure,\
'module procedure a , b'), 'MODULE PROCEDURE a, b')
def test_access(self):
assert_equal(parse(Public,'Public'),'PUBLIC')
assert_equal(parse(Public,'public a'),'PUBLIC a')
assert_equal(parse(Public,'public :: a'),'PUBLIC a')
assert_equal(parse(Public,'public a,b,c'),'PUBLIC a, b, c')
assert_equal(parse(Public,'public :: a(:,:)'),'PUBLIC a(:,:)')
assert_equal(parse(Private,'private'),'PRIVATE')
assert_equal(parse(Private,'private :: a'),'PRIVATE a')
def test_close(self):
assert_equal(parse(Close,'close (12)'),'CLOSE (12)')
assert_equal(parse(Close,'close (12, err=99)'),'CLOSE (12, ERR = 99)')
assert_equal(parse(Close,'close (12, status = a(1,2))'),'CLOSE (12, STATUS = a(1,2))')
def test_cycle(self):
assert_equal(parse(Cycle,'cycle'),'CYCLE')
assert_equal(parse(Cycle,'cycle ab'),'CYCLE ab')
def test_rewind(self):
assert_equal(parse(Rewind,'rewind 1'),'REWIND (1)')
assert_equal(parse(Rewind,'rewind (1)'),'REWIND (1)')
assert_equal(parse(Rewind,'rewind (1, err = 123)'),'REWIND (1, ERR = 123)')
def test_backspace(self):
assert_equal(parse(Backspace,'backspace 1'),'BACKSPACE (1)')
assert_equal(parse(Backspace,'backspace (1)'),'BACKSPACE (1)')
assert_equal(parse(Backspace,'backspace (1, err = 123)'),'BACKSPACE (1, ERR = 123)')
def test_endfile(self):
assert_equal(parse(Endfile,'endfile 1'),'ENDFILE (1)')
assert_equal(parse(Endfile,'endfile (1)'),'ENDFILE (1)')
assert_equal(parse(Endfile,'endfile (1, err = 123)'),'ENDFILE (1, ERR = 123)')
def test_open(self):
assert_equal(parse(Open,'open (1)'),'OPEN (1)')
assert_equal(parse(Open,'open (1, err = 123)'),'OPEN (1, ERR = 123)')
def test_format(self):
assert_equal(parse(Format,'1: format ()'),'1: FORMAT ()')
assert_equal(parse(Format,'199 format (1)'),'199: FORMAT (1)')
assert_equal(parse(Format,'2 format (1 , SS)'),'2: FORMAT (1, ss)')
def test_save(self):
assert_equal(parse(Save,'save'), 'SAVE')
assert_equal(parse(Save,'save :: a'), 'SAVE a')
assert_equal(parse(Save,'save a,b'), 'SAVE a, b')
def test_data(self):
assert_equal(parse(Data,'data a /b/'), 'DATA a / b /')
assert_equal(parse(Data,'data a , c /b/'), 'DATA a, c / b /')
assert_equal(parse(Data,'data a /b ,c/'), 'DATA a / b, c /')
assert_equal(parse(Data,'data a /b/ c,e /d/'), 'DATA a / b / c, e / d /')
assert_equal(parse(Data,'data a(1,2) /b/'), 'DATA a(1,2) / b /')
assert_equal(parse(Data,'data a /b, c(1)/'), 'DATA a / b, c(1) /')
def test_nullify(self):
assert_equal(parse(Nullify,'nullify(a)'),'NULLIFY (a)')
assert_equal(parse(Nullify,'nullify(a ,b)'),'NULLIFY (a, b)')
def test_use(self):
assert_equal(parse(Use, 'use a'), 'USE a')
assert_equal(parse(Use, 'use :: a'), 'USE a')
assert_equal(parse(Use, 'use, intrinsic:: a'), 'USE INTRINSIC :: a')
assert_equal(parse(Use, 'use :: a ,only: b'), 'USE a, ONLY: b')
assert_equal(parse(Use, 'use :: a , only: b=>c'), 'USE a, ONLY: b=>c')
assert_equal(parse(Use, 'use :: a , b=>c'), 'USE a, b=>c')
assert_equal(parse(Use,\
'use :: a , only: operator(+) , b'),\
'USE a, ONLY: operator(+), b')
def test_exit(self):
assert_equal(parse(Exit,'exit'),'EXIT')
assert_equal(parse(Exit,'exit ab'),'EXIT ab')
def test_parameter(self):
assert_equal(parse(Parameter,'parameter (a = b(1,2))'),
'PARAMETER (a = b(1,2))')
assert_equal(parse(Parameter,'parameter (a = b(1,2) , b=1)'),
'PARAMETER (a = b(1,2), b=1)')
def test_equivalence(self):
assert_equal(parse(Equivalence,'equivalence (a , b)'),'EQUIVALENCE (a, b)')
assert_equal(parse(Equivalence,'equivalence (a , b) , ( c, d(1) , g )'),
'EQUIVALENCE (a, b), (c, d(1), g)')
def test_dimension(self):
assert_equal(parse(Dimension,'dimension a(b)'),'DIMENSION a(b)')
assert_equal(parse(Dimension,'dimension::a(b)'),'DIMENSION a(b)')
assert_equal(parse(Dimension,'dimension a(b) , c(d)'),'DIMENSION a(b), c(d)')
assert_equal(parse(Dimension,'dimension a(b,c)'),'DIMENSION a(b,c)')
def test_target(self):
assert_equal(parse(Target,'target a(b)'),'TARGET a(b)')
assert_equal(parse(Target,'target::a(b)'),'TARGET a(b)')
assert_equal(parse(Target,'target a(b) , c(d)'),'TARGET a(b), c(d)')
assert_equal(parse(Target,'target a(b,c)'),'TARGET a(b,c)')
def test_pointer(self):
assert_equal(parse(Pointer,'pointer a=b'),'POINTER a=b')
assert_equal(parse(Pointer,'pointer :: a=b'),'POINTER a=b')
assert_equal(parse(Pointer,'pointer a=b, c=d(1,2)'),'POINTER a=b, c=d(1,2)')
def test_protected(self):
assert_equal(parse(Protected,'protected a'),'PROTECTED a')
assert_equal(parse(Protected,'protected::a'),'PROTECTED a')
assert_equal(parse(Protected,'protected a , b'),'PROTECTED a, b')
def test_volatile(self):
assert_equal(parse(Volatile,'volatile a'),'VOLATILE a')
assert_equal(parse(Volatile,'volatile::a'),'VOLATILE a')
assert_equal(parse(Volatile,'volatile a , b'),'VOLATILE a, b')
def test_value(self):
assert_equal(parse(Value,'value a'),'VALUE a')
assert_equal(parse(Value,'value::a'),'VALUE a')
assert_equal(parse(Value,'value a , b'),'VALUE a, b')
def test_arithmeticif(self):
assert_equal(parse(ArithmeticIf,'if (a) 1,2,3'),'IF (a) 1, 2, 3')
assert_equal(parse(ArithmeticIf,'if (a(1)) 1,2,3'),'IF (a(1)) 1, 2, 3')
assert_equal(parse(ArithmeticIf,'if (a(1,2)) 1,2,3'),'IF (a(1,2)) 1, 2, 3')
def test_intrinsic(self):
assert_equal(parse(Intrinsic,'intrinsic a'),'INTRINSIC a')
assert_equal(parse(Intrinsic,'intrinsic::a'),'INTRINSIC a')
assert_equal(parse(Intrinsic,'intrinsic a , b'),'INTRINSIC a, b')
def test_inquire(self):
assert_equal(parse(Inquire, 'inquire (1)'),'INQUIRE (1)')
assert_equal(parse(Inquire, 'inquire (1, err=123)'),'INQUIRE (1, ERR = 123)')
assert_equal(parse(Inquire, 'inquire (iolength=a) b'),'INQUIRE (IOLENGTH = a) b')
assert_equal(parse(Inquire, 'inquire (iolength=a) b ,c(1,2)'),
'INQUIRE (IOLENGTH = a) b, c(1,2)')
def test_sequence(self):
assert_equal(parse(Sequence, 'sequence'),'SEQUENCE')
def test_external(self):
assert_equal(parse(External,'external a'),'EXTERNAL a')
assert_equal(parse(External,'external::a'),'EXTERNAL a')
assert_equal(parse(External,'external a , b'),'EXTERNAL a, b')
def test_common(self):
assert_equal(parse(Common, 'common a'),'COMMON a')
assert_equal(parse(Common, 'common a , b'),'COMMON a, b')
assert_equal(parse(Common, 'common a , b(1,2)'),'COMMON a, b(1,2)')
assert_equal(parse(Common, 'common // a'),'COMMON a')
assert_equal(parse(Common, 'common / name/ a'),'COMMON / name / a')
assert_equal(parse(Common, 'common / name/ a , c'),'COMMON / name / a, c')
assert_equal(parse(Common, 'common / name/ a /foo/ c(1) ,d'),
'COMMON / name / a / foo / c(1), d')
assert_equal(parse(Common, 'common / name/ a, /foo/ c(1) ,d'),
'COMMON / name / a / foo / c(1), d')
def test_optional(self):
assert_equal(parse(Optional,'optional a'),'OPTIONAL a')
assert_equal(parse(Optional,'optional::a'),'OPTIONAL a')
assert_equal(parse(Optional,'optional a , b'),'OPTIONAL a, b')
def test_intent(self):
assert_equal(parse(Intent,'intent (in) a'),'INTENT (IN) a')
assert_equal(parse(Intent,'intent(in)::a'),'INTENT (IN) a')
assert_equal(parse(Intent,'intent(in) a , b'),'INTENT (IN) a, b')
assert_equal(parse(Intent,'intent (in, out) a'),'INTENT (IN, OUT) a')
def test_entry(self):
assert_equal(parse(Entry,'entry a'), 'ENTRY a')
assert_equal(parse(Entry,'entry a()'), 'ENTRY a')
assert_equal(parse(Entry,'entry a(b)'), 'ENTRY a (b)')
assert_equal(parse(Entry,'entry a(b,*)'), 'ENTRY a (b, *)')
assert_equal(parse(Entry,'entry a bind(c , name="a b")'),
'ENTRY a BIND (C, NAME = "a b")')
assert_equal(parse(Entry,'entry a result (b)'), 'ENTRY a RESULT (b)')
assert_equal(parse(Entry,'entry a bind(d) result (b)'),
'ENTRY a RESULT (b) BIND (D)')
assert_equal(parse(Entry,'entry a result (b) bind( c )'),
'ENTRY a RESULT (b) BIND (C)')
assert_equal(parse(Entry,'entry a(b,*) result (g)'),
'ENTRY a (b, *) RESULT (g)')
def test_import(self):
assert_equal(parse(Import,'import'),'IMPORT')
assert_equal(parse(Import,'import a'),'IMPORT a')
assert_equal(parse(Import,'import::a'),'IMPORT a')
assert_equal(parse(Import,'import a , b'),'IMPORT a, b')
def test_forall(self):
assert_equal(parse(ForallStmt,'forall (i = 1:n(k,:) : 2) a(i) = i*i*b(i)'),
'FORALL (i = 1 : n(k,:) : 2) a(i) = i*i*b(i)')
assert_equal(parse(ForallStmt,'forall (i=1:n,j=2:3) a(i) = b(i,i)'),
'FORALL (i = 1 : n, j = 2 : 3) a(i) = b(i,i)')
assert_equal(parse(ForallStmt,'forall (i=1:n,j=2:3, 1+a(1,2)) a(i) = b(i,i)'),
'FORALL (i = 1 : n, j = 2 : 3, 1+a(1,2)) a(i) = b(i,i)')
def test_specificbinding(self):
assert_equal(parse(SpecificBinding,'procedure a'),'PROCEDURE a')
assert_equal(parse(SpecificBinding,'procedure :: a'),'PROCEDURE a')
assert_equal(parse(SpecificBinding,'procedure , NOPASS :: a'),'PROCEDURE , NOPASS :: a')
assert_equal(parse(SpecificBinding,'procedure , public, pass(x ) :: a'),'PROCEDURE , PUBLIC, PASS (x) :: a')
assert_equal(parse(SpecificBinding,'procedure(n) a'),'PROCEDURE (n) a')
assert_equal(parse(SpecificBinding,'procedure(n),pass :: a'),
'PROCEDURE (n) , PASS :: a')
assert_equal(parse(SpecificBinding,'procedure(n) :: a'),
'PROCEDURE (n) a')
assert_equal(parse(SpecificBinding,'procedure a= >b'),'PROCEDURE a => b')
assert_equal(parse(SpecificBinding,'procedure(n),pass :: a =>c'),
'PROCEDURE (n) , PASS :: a => c')
def test_genericbinding(self):
assert_equal(parse(GenericBinding,'generic :: a=>b'),'GENERIC :: a => b')
assert_equal(parse(GenericBinding,'generic, public :: a=>b'),'GENERIC, PUBLIC :: a => b')
assert_equal(parse(GenericBinding,'generic, public :: a(1,2)=>b ,c'),
'GENERIC, PUBLIC :: a(1,2) => b, c')
def test_finalbinding(self):
assert_equal(parse(FinalBinding,'final a'),'FINAL a')
assert_equal(parse(FinalBinding,'final::a'),'FINAL a')
assert_equal(parse(FinalBinding,'final a , b'),'FINAL a, b')
def test_allocatable(self):
assert_equal(parse(Allocatable,'allocatable a'),'ALLOCATABLE a')
assert_equal(parse(Allocatable,'allocatable :: a'),'ALLOCATABLE a')
assert_equal(parse(Allocatable,'allocatable a (1,2)'),'ALLOCATABLE a (1,2)')
assert_equal(parse(Allocatable,'allocatable a (1,2) ,b'),'ALLOCATABLE a (1,2), b')
def test_asynchronous(self):
assert_equal(parse(Asynchronous,'asynchronous a'),'ASYNCHRONOUS a')
assert_equal(parse(Asynchronous,'asynchronous::a'),'ASYNCHRONOUS a')
assert_equal(parse(Asynchronous,'asynchronous a , b'),'ASYNCHRONOUS a, b')
def test_bind(self):
assert_equal(parse(Bind,'bind(c) a'),'BIND (C) a')
assert_equal(parse(Bind,'bind(c) :: a'),'BIND (C) a')
assert_equal(parse(Bind,'bind(c) a ,b'),'BIND (C) a, b')
assert_equal(parse(Bind,'bind(c) /a/'),'BIND (C) / a /')
assert_equal(parse(Bind,'bind(c) /a/ ,b'),'BIND (C) / a /, b')
assert_equal(parse(Bind,'bind(c,name="hey") a'),'BIND (C, NAME = "hey") a')
def test_else(self):
assert_equal(parse(Else,'else'),'ELSE')
assert_equal(parse(ElseIf,'else if (a) then'),'ELSE IF (a) THEN')
assert_equal(parse(ElseIf,'else if (a.eq.b(1,2)) then'),
'ELSE IF (a.eq.b(1,2)) THEN')
def test_case(self):
assert_equal(parse(Case,'case (1)'),'CASE ( 1 )')
assert_equal(parse(Case,'case (1:)'),'CASE ( 1 : )')
assert_equal(parse(Case,'case (:1)'),'CASE ( : 1 )')
assert_equal(parse(Case,'case (1:2)'),'CASE ( 1 : 2 )')
assert_equal(parse(Case,'case (a(1,2))'),'CASE ( a(1,2) )')
assert_equal(parse(Case,'case ("ab")'),'CASE ( "ab" )')
assert_equal(parse(Case,'case default'),'CASE DEFAULT')
assert_equal(parse(Case,'case (1:2 ,3:4)'),'CASE ( 1 : 2, 3 : 4 )')
assert_equal(parse(Case,'case (a(1,:):)'),'CASE ( a(1,:) : )')
assert_equal(parse(Case,'case default'),'CASE DEFAULT')
def test_where(self):
assert_equal(parse(WhereStmt,'where (1) a=1'),'WHERE ( 1 ) a = 1')
assert_equal(parse(WhereStmt,'where (a(1,2)) a=1'),'WHERE ( a(1,2) ) a = 1')
def test_elsewhere(self):
assert_equal(parse(ElseWhere,'else where'),'ELSE WHERE')
assert_equal(parse(ElseWhere,'elsewhere (1)'),'ELSE WHERE ( 1 )')
assert_equal(parse(ElseWhere,'elsewhere(a(1,2))'),'ELSE WHERE ( a(1,2) )')
def test_enumerator(self):
assert_equal(parse(Enumerator,'enumerator a'), 'ENUMERATOR a')
assert_equal(parse(Enumerator,'enumerator:: a'), 'ENUMERATOR a')
assert_equal(parse(Enumerator,'enumerator a,b'), 'ENUMERATOR a, b')
assert_equal(parse(Enumerator,'enumerator a=1'), 'ENUMERATOR a=1')
assert_equal(parse(Enumerator,'enumerator a=1 , b=c(1,2)'), 'ENUMERATOR a=1, b=c(1,2)')
def test_fortranname(self):
assert_equal(parse(FortranName,'fortranname a'),'FORTRANNAME a')
def test_threadsafe(self):
assert_equal(parse(Threadsafe,'threadsafe'),'THREADSAFE')
def test_depend(self):
assert_equal(parse(Depend,'depend( a) b'), 'DEPEND ( a ) b')
assert_equal(parse(Depend,'depend( a) ::b'), 'DEPEND ( a ) b')
assert_equal(parse(Depend,'depend( a,c) b,e'), 'DEPEND ( a, c ) b, e')
def test_check(self):
assert_equal(parse(Check,'check(1) a'), 'CHECK ( 1 ) a')
assert_equal(parse(Check,'check(1) :: a'), 'CHECK ( 1 ) a')
assert_equal(parse(Check,'check(b(1,2)) a'), 'CHECK ( b(1,2) ) a')
assert_equal(parse(Check,'check(a>1) :: a'), 'CHECK ( a>1 ) a')
def test_callstatement(self):
assert_equal(parse(CallStatement,'callstatement (*func)()',isstrict=1),
'CALLSTATEMENT (*func)()')
assert_equal(parse(CallStatement,'callstatement i=1;(*func)()',isstrict=1),
'CALLSTATEMENT i=1;(*func)()')
def test_callprotoargument(self):
assert_equal(parse(CallProtoArgument,'callprotoargument int(*), double'),
'CALLPROTOARGUMENT int(*), double')
def test_pause(self):
assert_equal(parse(Pause,'pause'),'PAUSE')
assert_equal(parse(Pause,'pause 1'),'PAUSE 1')
assert_equal(parse(Pause,'pause "hey"'),'PAUSE "hey"')
assert_equal(parse(Pause,'pause "hey pa"'),'PAUSE "hey pa"')
def test_integer(self):
assert_equal(parse(Integer,'integer'),'INTEGER')
assert_equal(parse(Integer,'integer*4'),'INTEGER*4')
assert_equal(parse(Integer,'integer*4 a'),'INTEGER*4 a')
assert_equal(parse(Integer,'integer*4, a'),'INTEGER*4 a')
assert_equal(parse(Integer,'integer*4 a ,b'),'INTEGER*4 a, b')
assert_equal(parse(Integer,'integer*4 :: a ,b'),'INTEGER*4 a, b')
assert_equal(parse(Integer,'integer*4 a(1,2)'),'INTEGER*4 a(1,2)')
assert_equal(parse(Integer,'integer*4 :: a(1,2),b'),'INTEGER*4 a(1,2), b')
assert_equal(parse(Integer,'integer*4 external :: a'),
'INTEGER*4, external :: a')
assert_equal(parse(Integer,'integer*4, external :: a'),
'INTEGER*4, external :: a')
assert_equal(parse(Integer,'integer*4 external , intent(in) :: a'),
'INTEGER*4, external, intent(in) :: a')
assert_equal(parse(Integer,'integer(kind=4)'),'INTEGER(KIND=4)')
assert_equal(parse(Integer,'integer ( kind = 4)'),'INTEGER(KIND=4)')
assert_equal(parse(Integer,'integer(kind=2+2)'),'INTEGER(KIND=2+2)')
assert_equal(parse(Integer,'integer(kind=f(4,5))'),'INTEGER(KIND=f(4,5))')
def test_character(self):
assert_equal(parse(Character,'character'),'CHARACTER')
assert_equal(parse(Character,'character*2'),'CHARACTER(LEN=2)')
assert_equal(parse(Character,'character**'),'CHARACTER(LEN=*)')
assert_equal(parse(Character,'character*(2)'),'CHARACTER(LEN=2)')
assert_equal(parse(Character,'character*(len =2)'),'CHARACTER(LEN=2)')
assert_equal(parse(Character,'character*(len =2),'),'CHARACTER(LEN=2)')
assert_equal(parse(Character,'character*(len =:)'),'CHARACTER(LEN=:)')
assert_equal(parse(Character,'character(len =2)'),'CHARACTER(LEN=2)')
assert_equal(parse(Character,'character(2)'),'CHARACTER(LEN=2)')
assert_equal(parse(Character,'character(kind=2)'),'CHARACTER(KIND=2)')
assert_equal(parse(Character,'character(kind=2,len=3)'),
'CHARACTER(LEN=3, KIND=2)')
assert_equal(parse(Character,'character(lEN=3,kind=2)'),
'CHARACTER(LEN=3, KIND=2)')
assert_equal(parse(Character,'character(len=3,kind=2)', isstrict=True),
'CHARACTER(LEN=3, KIND=2)')
assert_equal(parse(Character,'chaRACTER(len=3,kind=fA(1,2))', isstrict=True),
'CHARACTER(LEN=3, KIND=fA(1,2))')
assert_equal(parse(Character,'character(len=3,kind=fA(1,2))'),
'CHARACTER(LEN=3, KIND=fa(1,2))')
def test_implicit(self):
assert_equal(parse(Implicit,'implicit none'),'IMPLICIT NONE')
assert_equal(parse(Implicit,'implicit'),'IMPLICIT NONE')
assert_equal(parse(Implicit,'implicit integer (i-m)'),
'IMPLICIT INTEGER ( i-m )')
assert_equal(parse(Implicit,'implicit integer (i-m,p,q-r)'),
'IMPLICIT INTEGER ( i-m, p, q-r )')
assert_equal(parse(Implicit,'implicit integer (i-m), real (z)'),
'IMPLICIT INTEGER ( i-m ), REAL ( z )')
if __name__ == "__main__":
nose.run(argv=['', __file__])
|