PPTokenTest.st
changeset 4 90de244a7fa2
parent 0 739fe9b7253e
child 38 1e678b5f1423
equal deleted inserted replaced
3:e1b11f74e142 4:90de244a7fa2
     1 "{ Package: 'squeak:petitparser' }"
     1 "{ Package: 'stx:goodies/petitparser' }"
     2 
     2 
     3 PPAbstractParseTest subclass:#PPTokenTest
     3 PPAbstractParseTest subclass:#PPTokenTest
     4 	instanceVariableNames:''
     4 	instanceVariableNames:''
     5 	classVariableNames:''
     5 	classVariableNames:''
     6 	poolDictionaries:''
     6 	poolDictionaries:''
    17 !PPTokenTest methodsFor:'testing'!
    17 !PPTokenTest methodsFor:'testing'!
    18 
    18 
    19 testCollection
    19 testCollection
    20 	| input result |
    20 	| input result |
    21 	input := 'foo    '.
    21 	input := 'foo    '.
    22 	result := self 
    22 	result := self
    23 		parse: input
    23 		parse: input
    24 		using: self identifier.
    24 		using: self identifier.
    25 	self assert: (result collection = input).
    25 	self assert: (result collection = input).
    26 	self assert: (result collection == input)
    26 	self assert: (result collection == input)
    27 !
    27 !
    28 
    28 
    29 testNew
    29 testNew
    30 	self should: [ PPToken new ] raise: Error.
    30 	self should: [ PPToken new ] raise: Error.
    31 	
    31 
    32 !
    32 !
    33 
    33 
    34 testPrinting
    34 testPrinting
    35 	| result |
    35 	| result |
    36 	result := PPToken on: 'var'.
    36 	result := PPToken on: 'var'.
    37 	self assert: (result printString includesSubString: 'PPToken(var)')
    37 	self assert: (result printString includesSubString: 'PPToken(var)')
    38 !
    38 !
    39 
    39 
    40 testSize
    40 testSize
    41 	| result |
    41 	| result |
    42 	result := self 
    42 	result := self
    43 		parse: 'foo'
    43 		parse: 'foo'
    44 		using: self identifier.
    44 		using: self identifier.
    45 	self assert: result size = 3
    45 	self assert: result size = 3
    46 !
    46 !
    47 
    47 
    48 testStart
    48 testStart
    49 	| result |
    49 	| result |
    50 	result := self 
    50 	result := self
    51 		parse: 'foo'
    51 		parse: 'foo'
    52 		using: self identifier.
    52 		using: self identifier.
    53 	self assert: result start = 1
    53 	self assert: result start = 1
    54 !
    54 !
    55 
    55 
    56 testStop
    56 testStop
    57 	| result |
    57 	| result |
    58 	result := self 
    58 	result := self
    59 		parse: 'foo'
    59 		parse: 'foo'
    60 		using: self identifier.
    60 		using: self identifier.
    61 	self assert: result stop = 3
    61 	self assert: result stop = 3
    62 !
    62 !
    63 
    63 
    64 testValue
    64 testValue
    65 	| input result |
    65 	| input result |
    66 	input := 'foo'.
    66 	input := 'foo'.
    67 	result := self 
    67 	result := self
    68 		parse: input
    68 		parse: input
    69 		using: self identifier.
    69 		using: self identifier.
    70 	self assert: result value = input.
    70 	self assert: result value = input.
    71 	self deny: result value == input
    71 	self deny: result value == input
    72 ! !
    72 ! !
    86 
    86 
    87 testCopyFromTo
    87 testCopyFromTo
    88 	| result other |
    88 	| result other |
    89 	result := PPToken on: 'abc'.
    89 	result := PPToken on: 'abc'.
    90 	other := result copyFrom: 2 to: 2.
    90 	other := result copyFrom: 2 to: 2.
    91 	
    91 
    92 	self assert: other size = 1.
    92 	self assert: other size = 1.
    93 	self assert: other start = 2.
    93 	self assert: other start = 2.
    94 	self assert: other stop = 2.
    94 	self assert: other stop = 2.
    95 	self assert: other collection = result collection
    95 	self assert: other collection = result collection
    96 ! !
    96 ! !
   100 testColumn
   100 testColumn
   101 	| input parser result |
   101 	| input parser result |
   102 	input := '1' , (String with: Character cr) , '12' , (String with: Character cr with: Character lf) , '123' , (String with: Character lf) , '1234'.
   102 	input := '1' , (String with: Character cr) , '12' , (String with: Character cr with: Character lf) , '123' , (String with: Character lf) , '1234'.
   103 	parser := #any asParser token star.
   103 	parser := #any asParser token star.
   104 	result := parser parse: input.
   104 	result := parser parse: input.
   105 	result 
   105 	result
   106 		with:  #(1 2 1 2 3 4 1 2 3 4 1 2 3 4)
   106 		with:  #(1 2 1 2 3 4 1 2 3 4 1 2 3 4)
   107 		do: [ :token :line | self assert: token column = line ]
   107 		do: [ :token :line | self assert: token column = line ]
   108 !
   108 !
   109 
   109 
   110 testLine
   110 testLine
   111 	| input parser result |
   111 	| input parser result |
   112 	input := '1' , (String with: Character cr) , '12' , (String with: Character cr with: Character lf) , '123' , (String with: Character lf) , '1234'.
   112 	input := '1' , (String with: Character cr) , '12' , (String with: Character cr with: Character lf) , '123' , (String with: Character lf) , '1234'.
   113 	parser := #any asParser token star.
   113 	parser := #any asParser token star.
   114 	result := parser parse: input.
   114 	result := parser parse: input.
   115 	result 
   115 	result
   116 		with: #(1 1 2 2 2 2 3 3 3 3 4 4 4 4) 
   116 		with: #(1 1 2 2 2 2 3 3 3 3 4 4 4 4)
   117 		do: [ :token :line | self assert: token line = line ]
   117 		do: [ :token :line | self assert: token line = line ]
   118 ! !
   118 ! !
   119 
   119 
   120 !PPTokenTest methodsFor:'utilities'!
   120 !PPTokenTest methodsFor:'utilities'!
   121 
   121 
   124 ! !
   124 ! !
   125 
   125 
   126 !PPTokenTest class methodsFor:'documentation'!
   126 !PPTokenTest class methodsFor:'documentation'!
   127 
   127 
   128 version_SVN
   128 version_SVN
   129     ^ '$Id: PPTokenTest.st,v 1.1 2011-08-18 18:56:17 cg Exp $'
   129     ^ '$Id: PPTokenTest.st,v 1.2 2012-01-13 11:22:50 cg Exp $'
   130 ! !
   130 ! !