~mcfletch/simpleparse/pure-python

« back to all changes in this revision

Viewing changes to tests/test_simpleparsegrammar.py

  • Committer: Mike C. Fletcher
  • Date: 2011-09-06 20:51:03 UTC
  • Revision ID: mcfletch@vrplumber.com-20110906205103-h4h8jxu79yyed48c
Make simpleparse-pure test suite pass with no errors or warnings on Python 2.6, 2.7 and 3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
            <something> := [ab]''',
22
22
            's',
23
23
            'mmmab',
24
 
            (1,[],3)
 
24
            (True,[],3)
25
25
        )
26
26
    def testGenNegRange2( self ):
27
27
        self.doBasicTest(
29
29
            <something> := [ab]''',
30
30
            's',
31
31
            'mmmab',
32
 
            (1,[],1)
 
32
            (True,[],1)
33
33
        )
34
34
    def testGenNegLit1( self ):
35
35
        self.doBasicTest(
37
37
            <something> := "a"''',
38
38
            's',
39
39
            'mmmab',
40
 
            (1,[],3)
 
40
            (True,[],3)
41
41
        )
42
42
    def testGenPosReptOpt1( self ):
43
43
        self.doBasicTest(
45
45
            something := "a" ''',
46
46
            's',
47
47
            'aammmab',
48
 
            (1,[("something",0,1,NullResult),("something",1,2,NullResult)],2)
 
48
            (True,[("something",0,1,NullResult),("something",1,2,NullResult)],2)
49
49
        )
50
50
    def testGenPosReptOpt2( self ):
51
51
        self.doBasicTest(
53
53
            something := "a" ''',
54
54
            's',
55
55
            'mmmab',
56
 
            (1,[],0)
 
56
            (True,[],0)
57
57
        )
58
58
    def testGenPosRept1( self ):
59
59
        self.doBasicTest(
70
70
            ''',
71
71
            's',
72
72
            'bbbba',
73
 
            (1,[
 
73
            (True,[
74
74
            ],0)
75
75
        )
76
76
    def testLookaheadNeg( self ):
88
88
            ''',
89
89
            's',
90
90
            'bbbba',
91
 
            (1,[
 
91
            (True,[
92
92
            ],0)
93
93
        )
94
94
    def testLookaheadNeg3( self ):
97
97
            ''',
98
98
            's',
99
99
            'bbbba',
100
 
            (1,[
 
100
            (True,[
101
101
            ],1)
102
102
        )
103
103
    def testLookaheadNeg4( self ):
106
106
            ''',
107
107
            's',
108
108
            'bba',
109
 
            (1,[
 
109
            (True,[
110
110
            ],3)
111
111
        )
112
112
    def testLookaheadNeg5( self ):
116
116
            ''',
117
117
            's',
118
118
            'bac',
119
 
            (1,[
 
119
            (True,[
120
120
            ],2)
121
121
        )
122
122
    def testLookaheadNeg6( self ):
137
137
            ''',
138
138
            's',
139
139
            'bbbba',
140
 
            (1,[
 
140
            (True,[
141
141
                ("something",0,1,NullResult),
142
142
                ("something",1,2,NullResult),
143
143
                ("something",2,3,NullResult),
151
151
            ''',
152
152
            's',
153
153
            'badba',
154
 
            (1,[
 
154
            (True,[
155
155
                ("trailer",0,3,NullResult),
156
156
            ],0)
157
157
        )
162
162
            ''',
163
163
            's',
164
164
            'badba',
165
 
            (1,[
 
165
            (True,[
166
166
            ],0)
167
167
        )
168
168
 
173
173
            ''',
174
174
            's',
175
175
            'babba',
176
 
            (1,[
 
176
            (True,[
177
177
            ],2)
178
178
        )
179
179
    def testLookahead6( self ):
201
201
            something := "a" ''',
202
202
            's',
203
203
            'ammmab',
204
 
            (1,[('something',0,1,NullResult),],1)
 
204
            (True,[('something',0,1,NullResult),],1)
205
205
        )
206
206
 
207
207
    def testOptionalGroupHitEOF( self ):
211
211
            something := ("a"/"b") ''',
212
212
            's',
213
213
            'aa',
214
 
            (1,[
 
214
            (True,[
215
215
                ('something',0,1,NullResult),
216
216
                ('something',1,2,NullResult),
217
217
            ],2)
227
227
            ) ''',
228
228
            's',
229
229
            'aa',
230
 
            (1,[
 
230
            (True,[
231
231
                ('something',0,1,NullResult),
232
232
                ('something',1,2,NullResult),
233
233
            ],2)
243
243
##                      ''',
244
244
##                      "file",
245
245
##                      "\\*\\test sdf ff f f sdfff\\",
246
 
##                      (1, [
 
246
##                      (True, [
247
247
##                              ("controlword", 0,7,[]),
248
248
##                              ("contents",7,24),
249
249
##                      ],24),
254
254
            '''s := c"this"''',
255
255
            's',
256
256
            'this',
257
 
            (1,[],4)
 
257
            (True,[],4)
258
258
        )
259
259
    def testGenCILiteral2( self ):
260
260
        self.doBasicTest(
261
261
            '''s := c"this"''',
262
262
            's',
263
263
            'This',
264
 
            (1,[],4)
 
264
            (True,[],4)
265
265
        )
266
266
    def testGenCILiteral3( self ):
267
267
        self.doBasicTest(
268
268
            '''s := c"this"''',
269
269
            's',
270
270
            'THIS',
271
 
            (1,[],4)
 
271
            (True,[],4)
272
272
        )
273
273
    def testGenCILiteral4( self ):
274
274
        self.doBasicTest(
275
275
            '''s := -c"this"''',
276
276
            's',
277
277
            ' THIS',
278
 
            (1,[],1)
 
278
            (True,[],1)
279
279
        )
280
280
    def testGenCILiteral5( self ):
281
281
        self.doBasicTest(
282
282
            '''s := -c"this"''',
283
283
            's',
284
284
            ' thi',
285
 
            (1,[],1)
 
285
            (True,[],1)
286
286
        )
287
287
    def testGenCILiteral6( self ):
288
288
        self.doBasicTest(
289
289
            '''s := -c"this"*''',
290
290
            's',
291
291
            ' thi',
292
 
            (1,[],4)
 
292
            (True,[],4)
293
293
        )
294
294
 
295
295
class NameTests(unittest.TestCase):
302
302
            something := "a" ''',
303
303
            's',
304
304
            'ammmab',
305
 
            (1,[('something',0,1,NullResult),],1)
 
305
            (True,[('something',0,1,NullResult),],1)
306
306
        )
307
307
    def test_po( self ):
308
308
        self.doBasicTest(
310
310
            something := "a" ''',
311
311
            's',
312
312
            'ammmab',
313
 
            (1,[('something',0,1,NullResult),],1)
 
313
            (True,[('something',0,1,NullResult),],1)
314
314
        )
315
315
    def test_por( self ):
316
316
        self.doBasicTest(
318
318
            something := "a" ''',
319
319
            's',
320
320
            'ammmab',
321
 
            (1,[('something',0,1,NullResult),],1)
 
321
            (True,[('something',0,1,NullResult),],1)
322
322
        )
323
323
    def test_pr( self ):
324
324
        self.doBasicTest(
326
326
            something := "a" ''',
327
327
            's',
328
328
            'ammmab',
329
 
            (1,[('something',0,1,NullResult),],1)
 
329
            (True,[('something',0,1,NullResult),],1)
330
330
        )
331
331
 
332
332
    def test_n( self ):
335
335
            <something> := [ab]''',
336
336
            's',
337
337
            'mmmab',
338
 
            (1,[],1)
 
338
            (True,[],1)
339
339
        )
340
340
    def test_no( self ):
341
341
        self.doBasicTest(
343
343
            <something> := [ab]''',
344
344
            's',
345
345
            'mmmab',
346
 
            (1,[],1)
 
346
            (True,[],1)
347
347
        )
348
348
    def test_nor( self ):
349
349
        self.doBasicTest(
351
351
            <something> := [ab]''',
352
352
            's',
353
353
            'mmmab',
354
 
            (1,[],3)
 
354
            (True,[],3)
355
355
        )
356
356
    def test_nr( self ):
357
357
        self.doBasicTest(
359
359
            <something> := [ab]''',
360
360
            's',
361
361
            'mmmab',
362
 
            (1,[],3)
 
362
            (True,[],3)
363
363
        )
364
364
    def test_n_f( self ):
365
365
        self.doBasicTest(
375
375
            <something> := [ab]''',
376
376
            's',
377
377
            'ammmab',
378
 
            (1,[],0)
 
378
            (True,[],0)
379
379
        )
380
380
    def test_nor_f( self ):
381
381
        self.doBasicTest(
383
383
            <something> := [ab]''',
384
384
            's',
385
385
            'ammmab',
386
 
            (1,[],0)
 
386
            (True,[],0)
387
387
        )
388
388
    def test_nr_f( self ):
389
389
        self.doBasicTest(
404
404
##                      something := "a" ''',
405
405
##                      's',
406
406
##                      'a'*1000000,
407
 
##                      (1,[
 
407
##                      (True,[
408
408
##                      ],1000000)
409
409
##              )
410
410
 
425
425
            ''',
426
426
            's',
427
427
            'abammmab',
428
 
            (1,[
 
428
            (True,[
429
429
                ('r',0,1, NullResult),
430
430
                ('r',1,2, NullResult),
431
431
                ('r',2,3, NullResult),
445
445
            r := [ab]''',
446
446
            'something',
447
447
            'abammmab',
448
 
            (1,[
 
448
            (True,[
449
449
                ('r',0,1, NullResult),
450
450
            ],1)
451
451
        )
489
489
#            x := c*
490
490
#            c := 'c'
491
491
#        """, 'x', 'ccc', source)
492
 
#        assert result == (1,[
 
492
#        assert result == (True,[
493
493
#            'c','c','c',
494
494
#        ],3), """Result was %s"""%( result, )
495
495
#        
500
500
#            x := d*
501
501
#            d := 'd'
502
502
#        """, 'x', 'ddd', source)
503
 
#        assert result == (1,[
 
503
#        assert result == (True,[
504
504
#            "hello world","hello world","hello world",
505
505
#        ],3)
506
506
#