PPMappingTest.st
changeset 4 90de244a7fa2
parent 0 739fe9b7253e
child 32 25e88bf6d8f1
equal deleted inserted replaced
3:e1b11f74e142 4:90de244a7fa2
     1 "{ Package: 'squeak:petitparser' }"
     1 "{ Package: 'stx:goodies/petitparser' }"
     2 
     2 
     3 PPAbstractParseTest subclass:#PPMappingTest
     3 PPAbstractParseTest subclass:#PPMappingTest
     4 	instanceVariableNames:''
     4 	instanceVariableNames:''
     5 	classVariableNames:''
     5 	classVariableNames:''
     6 	poolDictionaries:''
     6 	poolDictionaries:''
    10 
    10 
    11 !PPMappingTest methodsFor:'testing'!
    11 !PPMappingTest methodsFor:'testing'!
    12 
    12 
    13 testFoldLeft2
    13 testFoldLeft2
    14 	| parser |
    14 	| parser |
    15 	parser := #any asParser star 
    15 	parser := #any asParser star
    16 		foldLeft: [ :a :b | Array with: a with: b ].
    16 		foldLeft: [ :a :b | Array with: a with: b ].
    17 
    17 
    18 	self assert: parser parse: #(a) to: #a.
    18 	self assert: parser parse: #(a) to: #a.
    19 	self assert: parser parse: #(a b) to: #(a b).
    19 	self assert: parser parse: #(a b) to: #(a b).
    20 	self assert: parser parse: #(a b c) to: #((a b) c).
    20 	self assert: parser parse: #(a b c) to: #((a b) c).
    22 	self assert: parser parse: #(a b c d e) to: #((((a b) c) d) e)
    22 	self assert: parser parse: #(a b c d e) to: #((((a b) c) d) e)
    23 !
    23 !
    24 
    24 
    25 testFoldLeft3
    25 testFoldLeft3
    26 	| parser |
    26 	| parser |
    27 	parser := #any asParser star 
    27 	parser := #any asParser star
    28 		foldLeft: [ :a :b :c | Array with: a with: b with: c ].
    28 		foldLeft: [ :a :b :c | Array with: a with: b with: c ].
    29 
    29 
    30 	self assert: parser parse: #(a) to: #a.
    30 	self assert: parser parse: #(a) to: #a.
    31 	self assert: parser parse: #(a b c) to: #(a b c).
    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)
    32 	self assert: parser parse: #(a b c d e) to: #((a b c) d e)
    33 !
    33 !
    34 
    34 
    35 testFoldRight2
    35 testFoldRight2
    36 	| parser |
    36 	| parser |
    37 	parser := #any asParser star 
    37 	parser := #any asParser star
    38 		foldRight: [ :a :b | Array with: a with: b ].
    38 		foldRight: [ :a :b | Array with: a with: b ].
    39 
    39 
    40 	self assert: parser parse: #(a) to: #a.
    40 	self assert: parser parse: #(a) to: #a.
    41 	self assert: parser parse: #(a b) to: #(a b).
    41 	self assert: parser parse: #(a b) to: #(a b).
    42 	self assert: parser parse: #(a b c) to: #(a (b c)).
    42 	self assert: parser parse: #(a b c) to: #(a (b c)).
    44 	self assert: parser parse: #(a b c d e) to: #(a (b (c (d e))))
    44 	self assert: parser parse: #(a b c d e) to: #(a (b (c (d e))))
    45 !
    45 !
    46 
    46 
    47 testFoldRight3
    47 testFoldRight3
    48 	| parser |
    48 	| parser |
    49 	parser := #any asParser star 
    49 	parser := #any asParser star
    50 		foldRight: [ :a :b :c | Array with: a with: b with: c ].
    50 		foldRight: [ :a :b :c | Array with: a with: b with: c ].
    51 
    51 
    52 	self assert: parser parse: #(a) to: #a.
    52 	self assert: parser parse: #(a) to: #a.
    53 	self assert: parser parse: #(a b c) to: #(a b c).
    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))
    54 	self assert: parser parse: #(a b c d e) to: #(a b (c d e))
    55 !
    55 !
    56 
    56 
    57 testMap1
    57 testMap1
    58 	| parser |
    58 	| parser |
    59 	parser := #any asParser 
    59 	parser := #any asParser
    60 		map: [ :a | Array with: a ].
    60 		map: [ :a | Array with: a ].
    61 
    61 
    62 	self assert: parser parse: #(a) to: #(a)
    62 	self assert: parser parse: #(a) to: #(a)
    63 !
    63 !
    64 
    64 
    65 testMap2
    65 testMap2
    66 	| parser |
    66 	| parser |
    67 	parser := (#any asParser , #any asParser) 
    67 	parser := (#any asParser , #any asParser)
    68 		map: [ :a :b | Array with: b with: a ].
    68 		map: [ :a :b | Array with: b with: a ].
    69 
    69 
    70 	self assert: parser parse: #(a b) to: #(b a)
    70 	self assert: parser parse: #(a b) to: #(b a)
    71 !
    71 !
    72 
    72 
    79 ! !
    79 ! !
    80 
    80 
    81 !PPMappingTest class methodsFor:'documentation'!
    81 !PPMappingTest class methodsFor:'documentation'!
    82 
    82 
    83 version_SVN
    83 version_SVN
    84     ^ '$Id: PPMappingTest.st,v 1.1 2011-08-18 18:56:17 cg Exp $'
    84     ^ '$Id: PPMappingTest.st,v 1.2 2012-01-13 11:22:50 cg Exp $'
    85 ! !
    85 ! !