PPMappingTest.st
changeset 375 e2b2f08d054e
parent 374 1ba87229ee7e
child 376 a2656b27cace
equal deleted inserted replaced
374:1ba87229ee7e 375:e2b2f08d054e
     1 "{ Package: 'stx:goodies/petitparser' }"
       
     2 
       
     3 PPAbstractParseTest subclass:#PPMappingTest
       
     4 	instanceVariableNames:''
       
     5 	classVariableNames:''
       
     6 	poolDictionaries:''
       
     7 	category:'PetitTests-Tests'
       
     8 !
       
     9 
       
    10 
       
    11 !PPMappingTest methodsFor:'testing'!
       
    12 
       
    13 testFoldLeft2
       
    14 	| parser |
       
    15 	parser := #any asParser star 
       
    16 		foldLeft: [ :a :b | Array with: a with: b ].
       
    17 
       
    18 	self assert: parser parse: #(a) to: #a.
       
    19 	self assert: parser parse: #(a b) to: #(a b).
       
    20 	self assert: parser parse: #(a b c) to: #((a b) c).
       
    21 	self assert: parser parse: #(a b c d) to: #(((a b) c) d).
       
    22 	self assert: parser parse: #(a b c d e) to: #((((a b) c) d) e)
       
    23 !
       
    24 
       
    25 testFoldLeft3
       
    26 	| parser |
       
    27 	parser := #any asParser star 
       
    28 		foldLeft: [ :a :b :c | Array with: a with: b with: c ].
       
    29 
       
    30 	self assert: parser parse: #(a) to: #a.
       
    31 	self assert: parser parse: #(a b c) to: #(a b c).
       
    32 	self assert: parser parse: #(a b c d e) to: #((a b c) d e)
       
    33 !
       
    34 
       
    35 testFoldRight2
       
    36 	| parser |
       
    37 	parser := #any asParser star 
       
    38 		foldRight: [ :a :b | Array with: a with: b ].
       
    39 
       
    40 	self assert: parser parse: #(a) to: #a.
       
    41 	self assert: parser parse: #(a b) to: #(a b).
       
    42 	self assert: parser parse: #(a b c) to: #(a (b c)).
       
    43 	self assert: parser parse: #(a b c d) to: #(a (b (c d))).
       
    44 	self assert: parser parse: #(a b c d e) to: #(a (b (c (d e))))
       
    45 !
       
    46 
       
    47 testFoldRight3
       
    48 	| parser |
       
    49 	parser := #any asParser star 
       
    50 		foldRight: [ :a :b :c | Array with: a with: b with: c ].
       
    51 
       
    52 	self assert: parser parse: #(a) to: #a.
       
    53 	self assert: parser parse: #(a b c) to: #(a b c).
       
    54 	self assert: parser parse: #(a b c d e) to: #(a b (c d e))
       
    55 !
       
    56 
       
    57 testMap1
       
    58 	| parser |
       
    59 	parser := #any asParser 
       
    60 		map: [ :a | Array with: a ].
       
    61 
       
    62 	self assert: parser parse: #(a) to: #(a)
       
    63 !
       
    64 
       
    65 testMap2
       
    66 	| parser |
       
    67 	parser := (#any asParser , #any asParser) 
       
    68 		map: [ :a :b | Array with: b with: a ].
       
    69 
       
    70 	self assert: parser parse: #(a b) to: #(b a)
       
    71 !
       
    72 
       
    73 testMap3
       
    74 	| parser |
       
    75 	parser := (#any asParser , #any asParser , #any asParser)
       
    76 		map: [ :a :b :c | Array with: c with: b with: a ].
       
    77 
       
    78 	self assert: parser parse: #(a b c) to: #(c b a)
       
    79 ! !
       
    80 
       
    81 !PPMappingTest class methodsFor:'documentation'!
       
    82 
       
    83 version
       
    84     ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPMappingTest.st,v 1.3 2012-05-04 22:03:40 vrany Exp $'
       
    85 !
       
    86 
       
    87 version_CVS
       
    88     ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPMappingTest.st,v 1.3 2012-05-04 22:03:40 vrany Exp $'
       
    89 !
       
    90 
       
    91 version_SVN
       
    92     ^ '§Id: PPMappingTest.st 4 2010-12-18 17:02:23Z kursjan §'
       
    93 ! !