tests/PPAbstractParserTest.st
author sr
Wed, 04 Jul 2018 15:30:19 +0200
changeset 611 38338f2de417
parent 564 604d40878f4b
permissions -rw-r--r--
build order was wrong
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
157
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"{ Package: 'stx:goodies/petitparser/tests' }"
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
564
604d40878f4b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 318
diff changeset
     3
"{ NameSpace: Smalltalk }"
604d40878f4b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 318
diff changeset
     4
157
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
TestCase subclass:#PPAbstractParserTest
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
	instanceVariableNames:''
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
	classVariableNames:''
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
	poolDictionaries:''
564
604d40878f4b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 318
diff changeset
     9
	category:'PetitTests-Tests'
157
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
!
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
!PPAbstractParserTest class methodsFor:'accessing'!
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
packageNamesUnderTest
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
	^ #('PetitParser' 'PetitTests')
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
! !
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
!PPAbstractParserTest class methodsFor:'testing'!
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
isAbstract
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	^ self name = #PPAbstractParserTest
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
! !
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
!PPAbstractParserTest methodsFor:'utilities'!
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
assert: aParser fail: aCollection
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
	^ self assert: aParser fail: aCollection end: 0
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
!
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
assert: aParser fail: aCollection end: anInteger
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
	| stream result |
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
	self 
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
		assert: aParser isPetitParser
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
		description: 'Parser invalid'.
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
	stream := aCollection asPetitStream.
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
	result := aParser parse: stream.
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
	self 
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
		assert: result isPetitFailure
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
		description: 'Parser did not fail'.
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
	self
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
		assert: stream position = anInteger
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
		description: 'Parser failed at wrong position'.
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
	^ result
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
!
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
assert: aParser parse: aCollection
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
	^ self assert: aParser parse: aCollection to: nil end: aCollection size 
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
!
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
assert: aParser parse: aCollection end: anInteger
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
	^ self assert: aParser parse: aCollection to: nil end: anInteger
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
!
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
assert: aParser parse: aCollection to: anObject
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
	^ self assert: aParser parse: aCollection to: anObject end: aCollection size 
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
!
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
assert: aParser parse: aCollection to: aTargetObject end: anInteger
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
	| stream result |
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
	self 
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
		assert: aParser isPetitParser
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
		description: 'Parser invalid'.
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
	stream := aCollection asPetitStream.
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
	result := aParser parse: stream.
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
	aTargetObject isNil
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
		ifTrue: [ self deny: result isPetitFailure ]
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
		ifFalse: [ self assert: result = aTargetObject ].
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
	self 
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
		assert: stream position = anInteger
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
		description: 'Parser accepted at wrong position'.
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
	^ result
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
!
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
assert: aParser parse: aCollection toToken: aStartInteger stop: aStopInteger
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
	^ self assert: aParser parse: aCollection toToken: aStartInteger stop: aStopInteger end: aCollection size
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
!
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
assert: aParser parse: aParserObject toToken: aStartInteger stop: aStopInteger end: anEndInteger
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
	| token |
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
	token := self assert: aParser parse: aParserObject to: nil end: anEndInteger.
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
	self assert: (token isKindOf: PPToken).
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
	self assert: (token start = aStartInteger).
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
	self assert: (token stop = aStopInteger).
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
	^ token
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
! !
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
!PPAbstractParserTest class methodsFor:'documentation'!
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
version
564
604d40878f4b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 318
diff changeset
    91
    ^ '$Header$'
157
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
!
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
version_CVS
564
604d40878f4b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 318
diff changeset
    95
    ^ '$Header$'
157
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
! !
46f441ef84a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97