tests/PPParserTest.st
author sr
Thu, 05 Jul 2018 09:23:34 +0200
changeset 628 379fc127ba99
parent 570 e4265d48b39c
permissions -rw-r--r--
order
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
570
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"{ Package: 'stx:goodies/petitparser/tests' }"
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"{ NameSpace: Smalltalk }"
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
PPAbstractParserTest subclass:#PPParserTest
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
	instanceVariableNames:''
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
	classVariableNames:''
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
	poolDictionaries:''
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
	category:'PetitTests-Tests'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
!PPParserTest methodsFor:'testing'!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
testAnd
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	parser := 'foo' asParser flatten , 'bar' asParser flatten and.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	self assert: parser parse: 'foobar' to: #('foo' 'bar') end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	self assert: parser fail: 'foobaz'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	parser := 'foo' asParser and.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
	self assert: parser and = parser
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
testBlock
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
	parser := [ :s | s next ] asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
	self assert: parser parse: 'ab' to: $a end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
	self assert: parser parse: 'b' to: $b.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
	self assert: parser parse: '' to: nil
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
testChoice
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
	parser := $a asParser / $b asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
	self assert: parser parse: 'a' to: $a.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
	self assert: parser parse: 'b' to: $b.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
	self assert: parser parse: 'ab' to: $a end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
	self assert: parser parse: 'ba' to: $b end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
	self assert: parser fail: 'c'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
	self assert: parser fail: 'ca'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
testDelimitedBy
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
	parser := $a asParser delimitedBy: $b asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
	self assert: parser parse: 'a' to: #($a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
	self assert: parser parse: 'aba' to: #($a $b $a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
	self assert: parser parse: 'ababa' to: #($a $b $a $b $a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
	self assert: parser parse: 'ab' to: #($a $b).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
	self assert: parser parse: 'abab' to: #($a $b $a $b).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
	self assert: parser parse: 'ababab' to: #($a $b $a $b $a $b).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
	self assert: parser parse: 'ac' to: #($a) end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
	self assert: parser parse: 'abc' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
	self assert: parser parse: 'abac' to: #($a $b $a) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
	self assert: parser parse: 'ababc' to: #($a $b $a $b) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
	self assert: parser fail: 'b'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
	self assert: parser fail: 'c'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
testDelimitedByWithoutSeparators
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
	parser := ($a asParser delimitedBy: $b asParser)
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
		withoutSeparators.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
	self assert: parser parse: 'a' to: #($a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
	self assert: parser parse: 'aba' to: #($a $a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
	self assert: parser parse: 'ababa' to: #($a $a $a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
	self assert: parser parse: 'ab' to: #($a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
	self assert: parser parse: 'abab' to: #($a $a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
	self assert: parser parse: 'ababab' to: #($a $a $a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
	self assert: parser parse: 'ac' to: #($a) end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
	self assert: parser parse: 'abc' to: #($a) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
	self assert: parser parse: 'abac' to: #($a $a) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
	self assert: parser parse: 'ababc' to: #($a $a) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
	self assert: parser fail: 'b'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
	self assert: parser fail: 'c'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
testEndOfInput
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
	parser := PPEndOfInputParser on: $a asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
	self assert: parser end = parser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
	self assert: parser parse: 'a' to: $a.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
	self assert: parser fail: 'aa'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
testEndOfInputAfterMatch
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
	parser := 'stuff' asParser end.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
	self assert: parser parse: 'stuff' to: 'stuff'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
	self assert: parser fail: 'stufff'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
	self assert: parser fail: 'fluff'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
testEpsilon
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
	parser := nil asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
	self assert: parser parse: '' to: nil.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
	self assert: parser parse: 'a' to: nil end: 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
	self assert: parser parse: 'ab' to: nil end: 0
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
testFailing
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
	| parser result |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
	parser := PPFailingParser message: 'Plonk'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
	self assert: parser message = 'Plonk'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
	self assert: parser fail: 'a'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
	self assert: parser fail: 'aa'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
	result := parser parse: 'a'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
	self assert: result message = 'Plonk'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
	self assert: result printString = 'Plonk at 0'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
testLiteralObject
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
	parser := PPLiteralObjectParser 
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
		on: $a
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
		message: 'letter "a" expected'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
	self assert: parser literal = $a.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
	self assert: parser message = 'letter "a" expected'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
	self assert: parser parse: 'a' to: $a.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
	self assert: parser fail: 'b'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
testLiteralObjectCaseInsensitive
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
	parser := $a asParser caseInsensitive.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
	self assert: parser parse: 'a' to: $a.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
	self assert: parser parse: 'A' to: $A.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
	self assert: parser fail: 'b'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
	self assert: parser fail: 'B'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
testLiteralSequence
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
	parser := PPLiteralSequenceParser 
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
		on: 'abc'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
		message: 'sequence "abc" expected'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
	self assert: parser size = 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
	self assert: parser literal = 'abc'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
	self assert: parser message = 'sequence "abc" expected'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
	self assert: parser parse: 'abc' to: 'abc'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
	self assert: parser fail: 'ab'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
	self assert: parser fail: 'abd'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
testLiteralSequenceCaseInsensitive
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
	parser := 'abc' asParser caseInsensitive.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
	self assert: parser parse: 'abc' to: 'abc'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
	self assert: parser parse: 'ABC' to: 'ABC'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
	self assert: parser parse: 'abC' to: 'abC'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
	self assert: parser parse: 'AbC' to: 'AbC'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
	self assert: parser fail: 'ab'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
	self assert: parser fail: 'abd'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
testMax
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
	parser := $a asParser max: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
	self assert: parser min = 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
	self assert: parser max = 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
	self assert: parser parse: '' to: #().
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
	self assert: parser parse: 'a' to: #($a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
	self assert: parser parse: 'aa' to: #($a $a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
	self assert: parser parse: 'aaa' to: #($a $a) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
	self assert: parser parse: 'aaaa' to: #($a $a) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
	self assert: (parser printString endsWith: '[0, 2]')
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
testMaxGreedy
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
	parser := #word asParser max: 2 greedy: #digit asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
	self assert: parser fail: 'abc'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
	self assert: parser parse: '1' to: #() end: 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
	self assert: parser parse: 'a1' to: #($a) end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
	self assert: parser parse: 'ab1' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
	self assert: parser fail: 'abc1'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
	self assert: parser parse: '12' to: #($1) end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
	self assert: parser parse: 'a12' to: #($a $1) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
	self assert: parser parse: 'ab12' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
	self assert: parser fail: 'abc12'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
	self assert: parser parse: '123' to: #($1 $2) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
	self assert: parser parse: 'a123' to: #($a $1) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
	self assert: parser parse: 'ab123' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
	self assert: parser fail: 'abc123'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
testMaxLazy
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
	parser := #word asParser max: 2 lazy: #digit asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
	self assert: parser fail: 'abc'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
	self assert: parser parse: '1' to: #() end: 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
	self assert: parser parse: 'a1' to: #($a) end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
	self assert: parser parse: 'ab1' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
	self assert: parser fail: 'abc1'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
	self assert: parser parse: '12' to: #() end: 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
	self assert: parser parse: 'a12' to: #($a) end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
	self assert: parser parse: 'ab12' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
	self assert: parser fail: 'abc12'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
	self assert: parser parse: '123' to: #() end: 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
	self assert: parser parse: 'a123' to: #($a) end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
	self assert: parser parse: 'ab123' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
	self assert: parser fail: 'abc123'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
testMemoized
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
	| count parser twice |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
	count := 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
	parser := [ :s | count := count + 1. s next ] asParser memoized.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
	twice := parser and , parser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
	count := 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
	self assert: parser parse: 'a' to: $a.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
	self assert: count = 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
	count := 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
	self assert: twice parse: 'a' to: #($a $a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
	self assert: count = 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
	self assert: parser memoized = parser
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   266
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
testMin
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   269
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   270
	parser := $a asParser min: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   271
	self assert: parser min = 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   272
	self assert: parser max > parser min.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   273
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   274
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   275
	self assert: parser fail: 'a'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   276
	self assert: parser parse: 'aa' to: #($a $a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   277
	self assert: parser parse: 'aaa' to: #($a $a $a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   278
	self assert: parser parse: 'aaaa' to: #($a $a $a $a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   279
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   280
	self assert: (parser printString endsWith: '[2, *]')
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   281
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   282
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   283
testMinGreedy
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   284
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   285
	parser := #word asParser min: 2 greedy: #digit asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   286
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   287
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   288
	self assert: parser fail: 'abcde'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   289
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   290
	self assert: parser fail: '1'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   291
	self assert: parser fail: 'a1'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   292
	self assert: parser parse: 'ab1' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   293
	self assert: parser parse: 'abc1' to: #($a $b $c) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   294
	self assert: parser parse: 'abcd1' to: #($a $b $c $d) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   295
	self assert: parser parse: 'abcde1' to: #($a $b $c $d $e) end: 5.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   296
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   297
	self assert: parser fail: '12'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   298
	self assert: parser parse: 'a12' to: #($a $1) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   299
	self assert: parser parse: 'ab12' to: #($a $b $1) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   300
	self assert: parser parse: 'abc12' to: #($a $b $c $1) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   301
	self assert: parser parse: 'abcd12' to: #($a $b $c $d $1) end: 5.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   302
	self assert: parser parse: 'abcde12' to: #($a $b $c $d $e $1) end: 6.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   303
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   304
	self assert: parser parse: '123' to: #($1 $2) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   305
	self assert: parser parse: 'a123' to: #($a $1 $2) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   306
	self assert: parser parse: 'ab123' to: #($a $b $1 $2) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   307
	self assert: parser parse: 'abc123' to: #($a $b $c $1 $2) end: 5.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   308
	self assert: parser parse: 'abcd123' to: #($a $b $c $d $1 $2) end: 6.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   309
	self assert: parser parse: 'abcde123' to: #($a $b $c $d $e $1 $2) end: 7.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   310
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   311
	self assert: parser parse: '1234' to: #($1 $2 $3) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   312
	self assert: parser parse: 'a1234' to: #($a $1 $2 $3) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   313
	self assert: parser parse: 'ab1234' to: #($a $b $1 $2 $3) end: 5.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   314
	self assert: parser parse: 'abc1234' to: #($a $b $c $1 $2 $3) end: 6.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   315
	self assert: parser parse: 'abcd1234' to: #($a $b $c $d $1 $2 $3) end: 7.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   316
	self assert: parser parse: 'abcde1234' to: #($a $b $c $d $e $1 $2 $3) end: 8
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   317
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   318
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   319
testMinLazy
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   320
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   321
	parser := #word asParser min: 2 lazy: #digit asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   322
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   323
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   324
	self assert: parser fail: 'abcde'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   325
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   326
	self assert: parser fail: '1'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   327
	self assert: parser fail: 'a1'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   328
	self assert: parser parse: 'ab1' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   329
	self assert: parser parse: 'abc1' to: #($a $b $c) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   330
	self assert: parser parse: 'abcd1' to: #($a $b $c $d) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   331
	self assert: parser parse: 'abcde1' to: #($a $b $c $d $e) end: 5.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   332
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
	self assert: parser fail: '12'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   334
	self assert: parser parse: 'a12' to: #($a $1) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   335
	self assert: parser parse: 'ab12' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   336
	self assert: parser parse: 'abc12' to: #($a $b $c) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   337
	self assert: parser parse: 'abcd12' to: #($a $b $c $d) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   338
	self assert: parser parse: 'abcde12' to: #($a $b $c $d $e) end: 5.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   339
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   340
	self assert: parser parse: '123' to: #($1 $2) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   341
	self assert: parser parse: 'a123' to: #($a $1) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   342
	self assert: parser parse: 'ab123' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   343
	self assert: parser parse: 'abc123' to: #($a $b $c) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   344
	self assert: parser parse: 'abcd123' to: #($a $b $c $d) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   345
	self assert: parser parse: 'abcde123' to: #($a $b $c $d $e) end: 5.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   346
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   347
	self assert: parser parse: '1234' to: #($1 $2) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   348
	self assert: parser parse: 'a1234' to: #($a $1) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   349
	self assert: parser parse: 'ab1234' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   350
	self assert: parser parse: 'abc1234' to: #($a $b $c) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   351
	self assert: parser parse: 'abcd1234' to: #($a $b $c $d) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   352
	self assert: parser parse: 'abcde1234' to: #($a $b $c $d $e) end: 5
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   353
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   354
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   355
testMinMax
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   356
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   357
	parser := $a asParser min: 2 max: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   358
	self assert: parser min = 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   359
	self assert: parser max = 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   360
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   361
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   362
	self assert: parser fail: 'a'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   363
	self assert: parser parse: 'aa' to: #($a $a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   364
	self assert: parser parse: 'aaa' to: #($a $a $a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   365
	self assert: parser parse: 'aaaa' to: #($a $a $a $a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   366
	self assert: parser parse: 'aaaaa' to: #($a $a $a $a) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   367
	self assert: parser parse: 'aaaaaa' to: #($a $a $a $a) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   368
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   369
	self assert: (parser printString endsWith: '[2, 4]')
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   370
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   371
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   372
testMinMaxGreedy
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   373
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   374
	parser := #word asParser min: 2 max: 4 greedy: #digit asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   375
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   376
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   377
	self assert: parser fail: 'abcde'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   378
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   379
	self assert: parser fail: '1'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   380
	self assert: parser fail: 'a1'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   381
	self assert: parser parse: 'ab1' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   382
	self assert: parser parse: 'abc1' to: #($a $b $c) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   383
	self assert: parser parse: 'abcd1' to: #($a $b $c $d) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   384
	self assert: parser fail: 'abcde1'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   385
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   386
	self assert: parser fail: '12'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   387
	self assert: parser parse: 'a12' to: #($a $1) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   388
	self assert: parser parse: 'ab12' to: #($a $b $1) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   389
	self assert: parser parse: 'abc12' to: #($a $b $c $1) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   390
	self assert: parser parse: 'abcd12' to: #($a $b $c $d) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   391
	self assert: parser fail: 'abcde12'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   392
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   393
	self assert: parser parse: '123' to: #($1 $2) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   394
	self assert: parser parse: 'a123' to: #($a $1 $2) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   395
	self assert: parser parse: 'ab123' to: #($a $b $1 $2) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   396
	self assert: parser parse: 'abc123' to: #($a $b $c $1) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   397
	self assert: parser parse: 'abcd123' to: #($a $b $c $d) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   398
	self assert: parser fail: 'abcde123'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   399
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   400
	self assert: parser parse: '1234' to: #($1 $2 $3) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   401
	self assert: parser parse: 'a1234' to: #($a $1 $2 $3) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   402
	self assert: parser parse: 'ab1234' to: #($a $b $1 $2) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   403
	self assert: parser parse: 'abc1234' to: #($a $b $c $1) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   404
	self assert: parser parse: 'abcd1234' to: #($a $b $c $d) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   405
	self assert: parser fail: 'abcde1234'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   406
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   407
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   408
testMinMaxLazy
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   409
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   410
	parser := #word asParser min: 2 max: 4 lazy: #digit asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   411
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   412
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   413
	self assert: parser fail: 'abcde'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   414
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   415
	self assert: parser fail: '1'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   416
	self assert: parser fail: 'a1'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   417
	self assert: parser parse: 'ab1' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   418
	self assert: parser parse: 'abc1' to: #($a $b $c) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   419
	self assert: parser parse: 'abcd1' to: #($a $b $c $d) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   420
	self assert: parser fail: 'abcde1'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   421
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   422
	self assert: parser fail: '12'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   423
	self assert: parser parse: 'a12' to: #($a $1) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   424
	self assert: parser parse: 'ab12' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   425
	self assert: parser parse: 'abc12' to: #($a $b $c) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   426
	self assert: parser parse: 'abcd12' to: #($a $b $c $d) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   427
	self assert: parser fail: 'abcde12'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   428
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   429
	self assert: parser parse: '123' to: #($1 $2) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   430
	self assert: parser parse: 'a123' to: #($a $1) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   431
	self assert: parser parse: 'ab123' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   432
	self assert: parser parse: 'abc123' to: #($a $b $c) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   433
	self assert: parser parse: 'abcd123' to: #($a $b $c $d) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   434
	self assert: parser fail: 'abcde123'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   435
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   436
	self assert: parser parse: '1234' to: #($1 $2) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   437
	self assert: parser parse: 'a1234' to: #($a $1) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   438
	self assert: parser parse: 'ab1234' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   439
	self assert: parser parse: 'abc1234' to: #($a $b $c) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   440
	self assert: parser parse: 'abcd1234' to: #($a $b $c $d) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   441
	self assert: parser fail: 'abcde1234'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   442
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   443
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   444
testNegate
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   445
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   446
	parser := 'foo' asParser negate.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   447
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   448
	self assert: parser parse: 'f' to: $f end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   449
	self assert: parser parse: 'fo' to: $f end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   450
	self assert: parser parse: 'fob' to: $f end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   451
	self assert: parser parse: 'ffoo' to: $f end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   452
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   453
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   454
	self assert: parser fail: 'foo'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   455
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   456
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   457
testNot
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   458
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   459
	parser := 'foo' asParser flatten , 'bar' asParser flatten not.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   460
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   461
	self assert: parser parse: 'foobaz' to: #('foo' nil) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   462
	self assert: parser fail: 'foobar'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   463
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   464
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   465
testOptional
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   466
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   467
	parser := $a asParser optional.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   468
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   469
	self assert: parser parse: '' to: nil.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   470
	self assert: parser parse: 'a' to: $a.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   471
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   472
	self assert: parser parse: 'aa' to: $a end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   473
	self assert: parser parse: 'ab' to: $a end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   474
	self assert: parser parse: 'b' to: nil end: 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   475
	self assert: parser parse: 'bb' to: nil end: 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   476
	self assert: parser parse: 'ba' to: nil end: 0
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   477
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   478
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   479
testPluggable
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   480
	| block parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   481
	block := [ :stream | stream position ].
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   482
	parser := block asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   483
	self assert: parser block = block
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   484
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   485
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   486
testPlus
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   487
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   488
	parser := $a asParser plus.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   489
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   490
	self assert: parser min = 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   491
	self assert: parser max > parser min.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   492
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   493
	self assert: parser parse: 'a' to: #($a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   494
	self assert: parser parse: 'aa' to: #($a $a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   495
	self assert: parser parse: 'aaa' to: #($a $a $a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   496
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   497
	self assert: parser parse: 'ab' to: #($a) end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   498
	self assert: parser parse: 'aab' to: #($a $a) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   499
	self assert: parser parse: 'aaab' to: #($a $a $a) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   500
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   501
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   502
	self assert: parser fail: 'b'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   503
	self assert: parser fail: 'ba'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   504
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   505
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   506
testPlusGreedy
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   507
	| limit parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   508
	limit := #digit asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   509
	parser := #word asParser plusGreedy: limit.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   510
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   511
	self assert: parser min = 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   512
	self assert: parser max > parser min.	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   513
	self assert: parser limit = limit.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   514
	self assert: parser children size = 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   515
	self assert: parser children last = limit.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   516
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   517
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   518
	self assert: parser fail: '1'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   519
	self assert: parser fail: 'a'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   520
	self assert: parser fail: 'ab'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   521
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   522
	self assert: parser parse: 'a1' to: #($a) end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   523
	self assert: parser parse: 'ab1' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   524
	self assert: parser parse: 'abc1' to: #($a $b $c) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   525
	self assert: parser parse: 'a12' to: #($a $1) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   526
	self assert: parser parse: 'ab12' to: #($a $b $1) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   527
	self assert: parser parse: 'abc12' to: #($a $b $c $1) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   528
	self assert: parser parse: 'a123' to: #($a $1 $2) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   529
	self assert: parser parse: 'ab123' to: #($a $b $1 $2) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   530
	self assert: parser parse: 'abc123' to: #($a $b $c $1 $2) end: 5.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   531
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   532
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   533
testPlusLazy
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   534
	| limit parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   535
	limit := #digit asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   536
	parser := #word asParser plusLazy: limit.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   537
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   538
	self assert: parser min = 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   539
	self assert: parser max > parser min.	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   540
	self assert: parser limit = limit.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   541
	self assert: parser children size = 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   542
	self assert: parser children last = limit.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   543
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   544
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   545
	self assert: parser fail: '1'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   546
	self assert: parser fail: 'a'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   547
	self assert: parser fail: 'ab'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   548
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   549
	self assert: parser parse: 'a1' to: #($a) end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   550
	self assert: parser parse: 'ab1' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   551
	self assert: parser parse: 'abc1' to: #($a $b $c) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   552
	self assert: parser parse: 'a12' to: #($a) end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   553
	self assert: parser parse: 'ab12' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   554
	self assert: parser parse: 'abc12' to: #($a $b $c) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   555
	self assert: parser parse: 'a123' to: #($a) end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   556
	self assert: parser parse: 'ab123' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   557
	self assert: parser parse: 'abc123' to: #($a $b $c) end: 3
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   558
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   559
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   560
testSeparatedBy
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   561
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   562
	parser := $a asParser separatedBy: $b asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   563
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   564
	self assert: parser parse: 'a' to: #($a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   565
	self assert: parser parse: 'aba' to: #($a $b $a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   566
	self assert: parser parse: 'ababa' to: #($a $b $a $b $a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   567
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   568
	self assert: parser parse: 'ab' to: #($a) end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   569
	self assert: parser parse: 'abab' to: #($a $b $a) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   570
	self assert: parser parse: 'ac' to: #($a) end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   571
	self assert: parser parse: 'abac' to: #($a $b $a) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   572
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   573
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   574
	self assert: parser fail: 'c'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   575
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   576
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   577
testSeparatedByWithoutSeparators
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   578
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   579
	parser := ($a asParser separatedBy: $b asParser)
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   580
		withoutSeparators.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   581
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   582
	self assert: parser parse: 'a' to: #($a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   583
	self assert: parser parse: 'aba' to: #($a $a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   584
	self assert: parser parse: 'ababa' to: #($a $a $a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   585
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   586
	self assert: parser parse: 'ab' to: #($a) end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   587
	self assert: parser parse: 'abab' to: #($a $a) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   588
	self assert: parser parse: 'ac' to: #($a) end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   589
	self assert: parser parse: 'abac' to: #($a $a) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   590
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   591
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   592
	self assert: parser fail: 'c'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   593
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   594
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   595
testSequence
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   596
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   597
	parser := $a asParser , $b asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   598
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   599
	self assert: parser parse: 'ab' to: #($a $b).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   600
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   601
	self assert: parser parse: 'aba' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   602
	self assert: parser parse: 'abb' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   603
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   604
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   605
	self assert: parser fail: 'a'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   606
	self assert: parser fail: 'aa'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   607
	self assert: parser fail: 'ba'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   608
	self assert: parser fail: 'bab'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   609
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   610
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   611
testStar
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   612
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   613
	parser := $a asParser star.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   614
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   615
	self assert: parser min = 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   616
	self assert: parser max > parser min.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   617
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   618
	self assert: parser parse: '' to: #().
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   619
	self assert: parser parse: 'a' to: #($a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   620
	self assert: parser parse: 'aa' to: #($a $a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   621
	self assert: parser parse: 'aaa' to: #($a $a $a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   622
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   623
	self assert: parser parse: 'b' to: #() end: 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   624
	self assert: parser parse: 'ab' to: #($a) end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   625
	self assert: parser parse: 'aab' to: #($a $a) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   626
	self assert: parser parse: 'aaab' to: #($a $a $a) end: 3
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   627
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   628
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   629
testStarGreedy
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   630
	| limit parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   631
	limit := #digit asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   632
	parser := #word asParser starGreedy: limit.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   633
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   634
	self assert: parser min = 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   635
	self assert: parser max > parser min.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   636
	self assert: parser limit = limit.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   637
	self assert: parser children size = 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   638
	self assert: parser children last = limit.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   639
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   640
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   641
	self assert: parser fail: 'a'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   642
	self assert: parser fail: 'ab'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   643
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   644
	self assert: parser parse: '1' to: #() end: 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   645
	self assert: parser parse: 'a1' to: #($a) end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   646
	self assert: parser parse: 'ab1' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   647
	self assert: parser parse: 'abc1' to: #($a $b $c) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   648
	self assert: parser parse: '12' to: #($1) end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   649
	self assert: parser parse: 'a12' to: #($a $1) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   650
	self assert: parser parse: 'ab12' to: #($a $b $1) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   651
	self assert: parser parse: 'abc12' to: #($a $b $c $1) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   652
	self assert: parser parse: '123' to: #($1 $2) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   653
	self assert: parser parse: 'a123' to: #($a $1 $2) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   654
	self assert: parser parse: 'ab123' to: #($a $b $1 $2) end: 4.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   655
	self assert: parser parse: 'abc123' to: #($a $b $c $1 $2) end: 5
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   656
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   657
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   658
testStarLazy
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   659
	| limit parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   660
	limit := #digit asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   661
	parser := #word asParser starLazy: limit.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   662
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   663
	self assert: parser min = 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   664
	self assert: parser max > parser min.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   665
	self assert: parser limit = limit.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   666
	self assert: parser children size = 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   667
	self assert: parser children last = limit.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   668
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   669
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   670
	self assert: parser fail: 'a'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   671
	self assert: parser fail: 'ab'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   672
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   673
	self assert: parser parse: '1' to: #() end: 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   674
	self assert: parser parse: 'a1' to: #($a) end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   675
	self assert: parser parse: 'ab1' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   676
	self assert: parser parse: 'abc1' to: #($a $b $c) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   677
	self assert: parser parse: '12' to: #() end: 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   678
	self assert: parser parse: 'a12' to: #($a) end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   679
	self assert: parser parse: 'ab12' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   680
	self assert: parser parse: 'abc12' to: #($a $b $c) end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   681
	self assert: parser parse: '123' to: #() end: 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   682
	self assert: parser parse: 'a123' to: #($a) end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   683
	self assert: parser parse: 'ab123' to: #($a $b) end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   684
	self assert: parser parse: 'abc123' to: #($a $b $c) end: 3
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   685
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   686
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   687
testTimes
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   688
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   689
	parser := $a asParser times: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   690
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   691
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   692
	self assert: parser fail: 'a'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   693
	self assert: parser parse: 'aa' to: #($a $a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   694
	self assert: parser parse: 'aaa' to: #($a $a) end: 2
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   695
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   696
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   697
testUnresolved
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   698
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   699
	parser := PPUnresolvedParser new.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   700
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   701
	self assert: parser isUnresolved.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   702
	self should: [ parser parse: '' ] raise: Error.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   703
	self should: [ parser parse: 'a' ] raise: Error.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   704
	self should: [ parser parse: 'ab' ] raise: Error.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   705
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   706
	parser := nil asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   707
	self deny: parser isUnresolved
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   708
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   709
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   710
testWrapped
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   711
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   712
	parser := $a asParser wrapped.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   713
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   714
	self assert: parser parse: 'a' to: $a.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   715
	self assert: parser fail: 'b'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   716
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   717
	parser := (($a asParser , $b asParser ) wrapped , $c asParser).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   718
	self assert: parser parse: 'abc' to: #(#($a $b) $c)
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   719
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   720
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   721
testXor
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   722
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   723
	parser := ($a asParser / $b asParser)
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   724
			|  ($b asParser / $c asParser).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   725
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   726
	self assert: parser parse: 'a' to: $a.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   727
	self assert: parser parse: 'c' to: $c.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   728
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   729
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   730
	self assert: parser fail: 'b'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   731
	self assert: parser fail: 'd'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   732
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   733
	" truly symmetric "
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   734
	parser := ($b asParser / $c asParser)
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   735
			|  ($a asParser / $b asParser).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   736
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   737
	self assert: parser parse: 'a' to: $a.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   738
	self assert: parser parse: 'c' to: $c.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   739
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   740
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   741
	self assert: parser fail: 'b'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   742
	self assert: parser fail: 'd'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   743
! !
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   744
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   745
!PPParserTest methodsFor:'testing-accessing'!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   746
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   747
testNamed
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   748
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   749
	parser := PPSequenceParser new.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   750
	self assert: parser name isNil.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   751
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   752
	parser := PPChoiceParser named: 'choice'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   753
	self assert: parser name = 'choice'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   754
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   755
	parser := $* asParser name: 'star'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   756
	self assert: parser name = 'star'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   757
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   758
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   759
testPrint
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   760
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   761
	parser := PPParser new.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   762
	self assert: (parser printString findString: 'PPParser') > 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   763
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   764
	parser := PPParser named: 'choice'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   765
	self assert: (parser printString findString: 'PPParser(choice') > 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   766
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   767
	parser := PPLiteralObjectParser on: $a.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   768
	self assert: (parser printString findString: '$a') > 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   769
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   770
	parser := PPFailingParser message: 'error'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   771
	self assert: (parser printString findString: 'error') > 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   772
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   773
	parser := PPPredicateObjectParser on: [ :c | true ] message: 'error'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   774
	self assert: (parser printString findString: 'error') > 0
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   775
! !
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   776
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   777
!PPParserTest methodsFor:'testing-fixtures'!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   778
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   779
testSideEffectChoice
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   780
	"Adding another element to a choice should create a copy, otherwise we get unwanted side-effects."
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   781
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   782
	| p1 p2 p3 |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   783
	p1 := $a asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   784
	p2 := p1 / $b asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   785
	p3 := p1 / $c asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   786
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   787
	self assert: p1 parse: 'a'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   788
	self assert: p1 fail: 'b'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   789
	self assert: p1 fail: 'c'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   790
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   791
	self assert: p2 parse: 'a'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   792
	self assert: p2 parse: 'b'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   793
	self assert: p2 fail: 'c'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   794
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   795
	self assert: p3 parse: 'a'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   796
	self assert: p3 fail: 'b'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   797
	self assert: p3 parse: 'c'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   798
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   799
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   800
testSideEffectListCopy
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   801
	| old new |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   802
	old := $a asParser , $b asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   803
	new := old copy.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   804
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   805
	self deny: old == new.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   806
	self deny: old children == new children.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   807
	self assert: old children first == new children first.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   808
	self assert: old children last == new children last
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   809
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   810
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   811
testSideEffectSequence
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   812
	"Adding another element to a sequence should create a copy, otherwise we get unwanted side-effects."
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   813
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   814
	| p1 p2 p3 |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   815
	p1 := $a asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   816
	p2 := p1 , $b asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   817
	p3 := p1 , $c asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   818
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   819
	self assert: p1 parse: 'a'.	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   820
	self assert: p1 parse: 'ab' end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   821
	self assert: p1 parse: 'ac' end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   822
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   823
	self assert: p2 fail: 'a'.	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   824
	self assert: p2 parse: 'ab'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   825
	self assert: p2 fail: 'ac'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   826
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   827
	self assert: p3 fail: 'a'.	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   828
	self assert: p3 fail: 'ab'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   829
	self assert: p3 parse: 'ac'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   830
! !
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   831
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   832
!PPParserTest methodsFor:'testing-mapping'!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   833
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   834
testAction
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   835
	| block parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   836
	block := [ :char | char asUppercase ].
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   837
	parser := #any asParser ==> block.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   838
	self assert: parser block = block.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   839
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   840
	self assert: parser parse: 'a' to: $A.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   841
	self assert: parser parse: 'b' to: $B
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   842
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   843
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   844
testAnswer
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   845
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   846
	parser := $a asParser answer: $b.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   847
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   848
	self assert: parser parse: 'a' to: $b.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   849
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   850
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   851
	self assert: parser fail: 'b'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   852
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   853
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   854
testFlatten
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   855
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   856
	parser := $a asParser flatten.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   857
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   858
	self assert: parser parse: 'a' to: 'a'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   859
	self assert: parser parse: #($a) to: #($a).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   860
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   861
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   862
	self assert: parser fail: 'b'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   863
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   864
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   865
testFoldLeft2
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   866
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   867
	parser := #any asParser star 
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   868
		foldLeft: [ :a :b | Array with: a with: b ].
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   869
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   870
	self assert: parser parse: #(a) to: #a.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   871
	self assert: parser parse: #(a b) to: #(a b).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   872
	self assert: parser parse: #(a b c) to: #((a b) c).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   873
	self assert: parser parse: #(a b c d) to: #(((a b) c) d).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   874
	self assert: parser parse: #(a b c d e) to: #((((a b) c) d) e)
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   875
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   876
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   877
testFoldLeft3
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   878
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   879
	parser := #any asParser star 
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   880
		foldLeft: [ :a :b :c | Array with: a with: b with: c ].
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   881
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   882
	self assert: parser parse: #(a) to: #a.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   883
	self assert: parser parse: #(a b c) to: #(a b c).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   884
	self assert: parser parse: #(a b c d e) to: #((a b c) d e)
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   885
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   886
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   887
testFoldRight2
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   888
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   889
	parser := #any asParser star 
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   890
		foldRight: [ :a :b | Array with: a with: b ].
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   891
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   892
	self assert: parser parse: #(a) to: #a.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   893
	self assert: parser parse: #(a b) to: #(a b).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   894
	self assert: parser parse: #(a b c) to: #(a (b c)).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   895
	self assert: parser parse: #(a b c d) to: #(a (b (c d))).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   896
	self assert: parser parse: #(a b c d e) to: #(a (b (c (d e))))
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   897
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   898
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   899
testFoldRight3
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   900
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   901
	parser := #any asParser star 
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   902
		foldRight: [ :a :b :c | Array with: a with: b with: c ].
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   903
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   904
	self assert: parser parse: #(a) to: #a.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   905
	self assert: parser parse: #(a b c) to: #(a b c).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   906
	self assert: parser parse: #(a b c d e) to: #(a b (c d e))
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   907
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   908
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   909
testMap1
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   910
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   911
	parser := #any asParser 
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   912
		map: [ :a | Array with: a ].
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   913
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   914
	self assert: parser parse: #(a) to: #(a)
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   915
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   916
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   917
testMap2
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   918
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   919
	parser := (#any asParser , #any asParser) 
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   920
		map: [ :a :b | Array with: b with: a ].
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   921
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   922
	self assert: parser parse: #(a b) to: #(b a)
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   923
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   924
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   925
testMap3
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   926
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   927
	parser := (#any asParser , #any asParser , #any asParser)
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   928
		map: [ :a :b :c | Array with: c with: b with: a ].
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   929
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   930
	self assert: parser parse: #(a b c) to: #(c b a)
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   931
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   932
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   933
testMapFail1
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   934
	self
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   935
		should: [ #any asParser map: [  ] ]
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   936
		raise: Error.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   937
	self
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   938
		should: [ #any asParser map: [ :a :b | ] ]
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   939
		raise: Error
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   940
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   941
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   942
testMapFail2
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   943
	self
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   944
		should: [ (#any asParser , #any asParser) map: [ :a | ] ]
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   945
		raise: Error.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   946
	self
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   947
		should: [ (#any asParser , #any asParser) map: [ :a :b :c | ] ]
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   948
		raise: Error
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   949
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   950
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   951
testPermutation
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   952
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   953
	parser := #any asParser , #any asParser , #any asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   954
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   955
	self assert: (parser permutation: #()) parse: '123' to: #().
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   956
	self assert: (parser permutation: #(1)) parse: '123' to: #($1).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   957
	self assert: (parser permutation: #(1 3)) parse: '123' to: #($1 $3).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   958
	self assert: (parser permutation: #(3 1)) parse: '123' to: #($3 $1).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   959
	self assert: (parser permutation: #(2 2)) parse: '123' to: #($2 $2).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   960
	self assert: (parser permutation: #(3 2 1)) parse: '123' to: #($3 $2 $1).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   961
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   962
	self should: [ parser permutation: #(0) ] raise: Error.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   963
	self should: [ parser permutation: #(4) ] raise: Error.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   964
	self should: [ parser permutation: #($2) ] raise: Error
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   965
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   966
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   967
testToken
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   968
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   969
	parser := $a asParser token.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   970
	self assert: parser tokenClass = PPToken.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   971
	self assert: parser parse: 'a' toToken: 1 stop: 1.	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   972
	self assert: parser fail: 'b'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   973
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   974
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   975
	parser := $a asParser token: PPToken.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   976
	self assert: parser tokenClass = PPToken.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   977
	self assert: parser parse: 'a' toToken: 1 stop: 1.	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   978
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   979
	self assert: parser fail: 'b'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   980
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   981
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   982
testTrim
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   983
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   984
	parser := $a asParser token trim.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   985
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   986
	self assert: parser parse: 'a' toToken: 1 stop: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   987
	self assert: parser parse: 'a ' toToken: 1 stop: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   988
	self assert: parser parse: 'a	' toToken: 1 stop: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   989
	self assert: parser parse: 'a  ' toToken: 1 stop: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   990
	self assert: parser parse: 'a 
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   991
	 ' toToken: 1 stop: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   992
		
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   993
	self assert: parser parse: 'a' toToken: 1 stop: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   994
	self assert: parser parse: ' a' toToken: 2 stop: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   995
	self assert: parser parse: '	a' toToken: 2 stop: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   996
	self assert: parser parse: '    a' toToken: 5 stop: 5.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   997
	self assert: parser parse: '   
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   998
a' toToken: 5 stop: 5.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   999
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1000
	self assert: parser parse: 'aa' toToken: 1 stop: 1 end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1001
	self assert: parser parse: 'a	a' toToken: 1 stop: 1 end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1002
	self assert: parser parse: 'a  a' toToken: 1 stop: 1 end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1003
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1004
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1005
	self assert: parser fail: 'b'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1006
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1007
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1008
testTrimBlanks
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1009
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1010
	parser := $a asParser token trimBlanks.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1011
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1012
	self assert: parser parse: 'a' toToken: 1 stop: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1013
	self assert: parser parse: 'a ' toToken: 1 stop: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1014
	self assert: parser parse: 'a	' toToken: 1 stop: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1015
	self assert: parser parse: 'a  ' toToken: 1 stop: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1016
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1017
	self assert: parser parse: 'a' toToken: 1 stop: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1018
	self assert: parser parse: ' a' toToken: 2 stop: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1019
	self assert: parser parse: '	a' toToken: 2 stop: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1020
	self assert: parser parse: '    a' toToken: 5 stop: 5.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1021
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1022
	self assert: parser parse: 'aa' toToken: 1 stop: 1 end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1023
	self assert: parser parse: 'a	a' toToken: 1 stop: 1 end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1024
	self assert: parser parse: 'a  a' toToken: 1 stop: 1 end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1025
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1026
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1027
	self assert: parser fail: '
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1028
'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1029
	self assert: parser fail: '
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1030
a'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1031
	self assert: parser fail: 'b'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1032
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1033
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1034
testTrimCustom
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1035
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1036
	parser := $a asParser token trim: $b asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1037
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1038
	self assert: parser parse: 'a' toToken: 1 stop: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1039
	self assert: parser parse: 'ab' toToken: 1 stop: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1040
	self assert: parser parse: 'abb' toToken: 1 stop: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1041
		
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1042
	self assert: parser parse: 'a' toToken: 1 stop: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1043
	self assert: parser parse: 'ba' toToken: 2 stop: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1044
	self assert: parser parse: 'bba' toToken: 3 stop: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1045
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1046
	self assert: parser parse: 'aa' toToken: 1 stop: 1 end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1047
	self assert: parser parse: 'ab' toToken: 1 stop: 1 end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1048
	self assert: parser parse: 'abba' toToken: 1 stop: 1 end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1049
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1050
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1051
	self assert: parser fail: 'b'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1052
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1053
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1054
testTrimSpaces
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1055
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1056
	parser := $a asParser token trimSpaces.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1057
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1058
	self assert: parser parse: 'a' toToken: 1 stop: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1059
	self assert: parser parse: 'a ' toToken: 1 stop: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1060
	self assert: parser parse: 'a	' toToken: 1 stop: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1061
	self assert: parser parse: 'a  ' toToken: 1 stop: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1062
	self assert: parser parse: 'a 
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1063
	 ' toToken: 1 stop: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1064
		
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1065
	self assert: parser parse: 'a' toToken: 1 stop: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1066
	self assert: parser parse: ' a' toToken: 2 stop: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1067
	self assert: parser parse: '	a' toToken: 2 stop: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1068
	self assert: parser parse: '    a' toToken: 5 stop: 5.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1069
	self assert: parser parse: '   
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1070
a' toToken: 5 stop: 5.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1071
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1072
	self assert: parser parse: 'aa' toToken: 1 stop: 1 end: 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1073
	self assert: parser parse: 'a	a' toToken: 1 stop: 1 end: 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1074
	self assert: parser parse: 'a  a' toToken: 1 stop: 1 end: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1075
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1076
	self assert: parser fail: ''.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1077
	self assert: parser fail: 'b'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1078
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1079
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1080
testWrapping
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1081
	| parser result |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1082
	parser := #digit asParser plus >=> [ :stream :cc | 
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1083
		Array 
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1084
			with: stream position 
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1085
			with: cc value 
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1086
			with: stream position ].
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1087
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1088
	self assert: parser parse: '1' to: #(0 ($1) 1).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1089
	self assert: parser parse: '12' to: #(0 ($1 $2) 2).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1090
	self assert: parser parse: '123' to: #(0 ($1 $2 $3) 3).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1091
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1092
	result := parser parse: 'a'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1093
	self assert: result first = 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1094
	self assert: result second isPetitFailure.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1095
	self assert: result last = 0
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1096
! !
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1097
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1098
!PPParserTest methodsFor:'testing-properties'!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1099
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1100
testHasProperty
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1101
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1102
	parser := PPParser new.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1103
	self deny: (parser hasProperty: #foo).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1104
	parser propertyAt: #foo put: 123.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1105
	self assert: (parser hasProperty: #foo)
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1106
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1107
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1108
testPostCopy
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1109
	| parser copy |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1110
	parser := PPParser new.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1111
	parser propertyAt: #foo put: true.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1112
	copy := parser copy.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1113
	copy propertyAt: #foo put: false.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1114
	self assert: (parser propertyAt: #foo).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1115
	self deny: (copy propertyAt: #foo)
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1116
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1117
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1118
testPropertyAt
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1119
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1120
	parser := PPParser new.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1121
	self should: [ parser propertyAt: #foo ] raise: Error.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1122
	parser propertyAt: #foo put: true.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1123
	self assert: (parser propertyAt: #foo)
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1124
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1125
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1126
testPropertyAtIfAbsent
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1127
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1128
	parser := PPParser new.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1129
	self assert: (parser propertyAt: #foo ifAbsent: [ true ]).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1130
	parser propertyAt: #foo put: true.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1131
	self assert: (parser propertyAt: #foo ifAbsent: [ false ])
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1132
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1133
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1134
testPropertyAtIfAbsentPut
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1135
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1136
	parser := PPParser new.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1137
	self assert: (parser propertyAt: #foo ifAbsentPut: [ true ]).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1138
	self assert: (parser propertyAt: #foo ifAbsentPut: [ false ])
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1139
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1140
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1141
testRemoveProperty
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1142
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1143
	parser := PPParser new.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1144
	self should: [ parser removeProperty: #foo ] raise: Error.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1145
	parser propertyAt: #foo put: true.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1146
	self assert: (parser removeProperty: #foo)
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1147
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1148
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1149
testRemovePropertyIfAbsent
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1150
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1151
	parser := PPParser new.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1152
	self assert: (parser removeProperty: #foo ifAbsent: [ true ]).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1153
	parser propertyAt: #foo put: true.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1154
	self assert: (parser removeProperty: #foo ifAbsent: [ false ])
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1155
! !
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1156
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1157
!PPParserTest methodsFor:'testing-utilities'!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1158
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1159
testChildren
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1160
	| p1 p2 p3 |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1161
	p1 := #lowercase asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1162
	p2 := p1 ==> #asUppercase.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1163
	p3 := PPUnresolvedParser new.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1164
	p3 def: p2 / p3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1165
	self assert: p1 children isEmpty.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1166
	self assert: p2 children size = 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1167
	self assert: p3 children size = 2
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1168
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1169
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1170
testFailure
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1171
	| failure |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1172
	failure := PPFailure message: 'Error' at: 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1173
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1174
	self assert: failure message = 'Error'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1175
	self assert: failure position = 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1176
	self assert: failure isPetitFailure.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1177
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1178
	self deny: 4 isPetitFailure.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1179
	self deny: 'foo' isPetitFailure
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1180
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1181
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1182
testListConstructor
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1183
	| p1 p2 p3 |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1184
	p1 := PPChoiceParser with: $a asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1185
	p2 := PPChoiceParser with: $a asParser with: $b asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1186
	p3 := PPChoiceParser withAll: (Array with: $a asParser with: $b asParser with: $c asParser).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1187
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1188
	self assert: p1 children size = 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1189
	self assert: p2 children size = 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1190
	self assert: p3 children size = 3
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1191
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1192
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1193
testMatches
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1194
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1195
	parser := $a asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1196
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1197
	self assert: (parser matches: 'a').
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1198
	self deny: (parser matches: 'b').
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1199
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1200
	self assert: (parser matches: 'a' readStream).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1201
	self deny: (parser matches: 'b' readStream)
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1202
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1203
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1204
testMatchesIn
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1205
	| parser result |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1206
	parser := $a asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1207
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1208
	result := parser matchesIn: 'abba'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1209
	self assert: result size = 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1210
	self assert: result first = $a.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1211
	self assert: result last = $a.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1212
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1213
	result := parser matchesIn: 'baaah'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1214
	self assert: result size = 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1215
	self assert: result first = $a.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1216
	self assert: result last = $a
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1217
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1218
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1219
testMatchesInEmpty
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1220
	"Empty matches should properly advance and match at each position and at the end."
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1221
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1222
	| parser result |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1223
	parser := [ :stream | stream position ] asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1224
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1225
	result := parser matchesIn: '123'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1226
	self assert: result asArray = #(0 1 2 3)
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1227
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1228
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1229
testMatchesInOverlapping
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1230
	"Matches that overlap should be properly reported."
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1231
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1232
	| parser result |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1233
	parser := #digit asParser , #digit asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1234
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1235
	result := parser matchesIn: 'a123b'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1236
	self assert: result size = 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1237
	self assert: result first = #($1 $2).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1238
	self assert: result last = #($2 $3)
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1239
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1240
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1241
testMatchesSkipIn
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1242
	| parser result |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1243
	parser := $a asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1244
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1245
	result := parser matchesSkipIn: 'abba'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1246
	self assert: result size = 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1247
	self assert: result first = $a.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1248
	self assert: result last = $a.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1249
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1250
	result := parser matchesSkipIn: 'baaah'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1251
	self assert: result size = 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1252
	self assert: result first = $a.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1253
	self assert: result last = $a
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1254
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1255
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1256
testMatchesSkipInOverlapping
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1257
	"Matches that overlap should be properly reported."
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1258
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1259
	| parser result |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1260
	parser := #digit asParser , #digit asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1261
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1262
	result := parser matchesSkipIn: 'a123b'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1263
	self assert: result size = 1.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1264
	self assert: result first = #($1 $2)
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1265
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1266
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1267
testMatchingRangesIn
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1268
	| input parser result |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1269
	input := 'a12b3'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1270
	parser := #digit asParser plus.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1271
	result := parser matchingRangesIn: input.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1272
	result := result collect: [ :each | input copyFrom: each first to: each last ].
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1273
	self assert: result size = 3.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1274
	self assert: result first = '12'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1275
	self assert: result second = '2'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1276
	self assert: result last = '3'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1277
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1278
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1279
testMatchingSkipRangesIn
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1280
	| input parser result |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1281
	input := 'a12b3'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1282
	parser := #digit asParser plus.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1283
	result := parser matchingSkipRangesIn: input.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1284
	result := result collect: [ :each | input copyFrom: each first to: each last ].
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1285
	self assert: result size = 2.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1286
	self assert: result first = '12'.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1287
	self assert: result last = '3'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1288
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1289
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1290
testParse
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1291
	| parser result |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1292
	parser := $a asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1293
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1294
	self assert: (parser parse: 'a') = $a.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1295
	self assert: (result := parser parse: 'b') isPetitFailure.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1296
	self assert: (result message findString: '$a') > 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1297
	self assert: (result message findString: 'expected') > 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1298
	self assert: (result position = 0).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1299
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1300
	self assert: (parser parse: 'a' readStream) = $a.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1301
	self assert: (result := parser parse: 'b' readStream) isPetitFailure.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1302
	self assert: (result message findString: '$a') > 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1303
	self assert: (result message findString: 'expected') > 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1304
	self assert: (result position = 0)
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1305
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1306
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1307
testParseOnError0
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1308
	| parser result seen |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1309
	parser := $a asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1310
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1311
	result := parser parse: 'a' onError: [ self signalFailure: 'Not supposed to report an error' ].
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1312
	self assert: result = $a.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1313
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1314
	result := parser parse: 'b' onError: [ seen := true ].
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1315
	self assert: result.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1316
	self assert: seen
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1317
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1318
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1319
testParseOnError1
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1320
	| parser result seen |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1321
	parser := $a asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1322
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1323
	result := parser parse: 'a' onError: [ self signalFailure: 'Not supposed to report an error' ].
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1324
	self assert: result = $a.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1325
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1326
	result := parser parse: 'b' onError: [ :failure | 
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1327
		self assert: (failure position = 0).
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1328
		self assert: (failure message findString: '$a') > 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1329
		self assert: (failure message findString: 'expected') > 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1330
		seen := true ].
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1331
	self assert: result.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1332
	self assert: seen
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1333
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1334
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1335
testParseOnError2
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1336
	| parser result seen |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1337
	parser := $a asParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1338
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1339
	result := parser parse: 'a' onError: [ self signalFailure: 'Not supposed to report an error' ].
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1340
	self assert: result = $a.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1341
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1342
	result := parser parse: 'b' onError: [ :msg :pos | 
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1343
		self assert: (msg findString: '$a') > 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1344
		self assert: (msg findString: 'expected') > 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1345
		self assert: pos = 0.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1346
		seen := true ].
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1347
	self assert: result.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1348
	self assert: seen
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1349
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1350
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1351
testParser
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1352
	| parser |
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1353
	parser := PPParser new.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1354
	
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1355
	self assert: parser isPetitParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1356
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1357
	self deny: 4 isPetitParser.
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1358
	self deny: 'foo' isPetitParser
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1359
! !
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1360
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1361
!PPParserTest class methodsFor:'documentation'!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1362
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1363
version
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1364
    ^ '$Header$'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1365
!
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1366
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1367
version_CVS
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1368
    ^ '$Header$'
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1369
! !
e4265d48b39c initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1370