Class {
#name : 'PPXmlFeedParserTest',
#superclass : 'PPCompositeParserTest',
#category : 'PetitIslands-Examples'
}
{ #category : 'as yet unclassified' }
PPXmlFeedParserTest >> feed01 [
^'
ABC Shop
Here and there 123, 123 45 Somewhere
-
socks
123
1
'
]
{ #category : 'as yet unclassified' }
PPXmlFeedParserTest >> feed02 [
^'
ABC Shop
Here and there 123, 123 45 Somewhere
-
socks
123
1
-
shoes
2345
1
'
]
{ #category : 'as yet unclassified' }
PPXmlFeedParserTest >> feed03 [
^'
ABC Shop
Here and there 123, 123 45 Somewhere
-
socks
123
1
-
shoes
2345
1
-
shoes
3456
0
'
]
{ #category : 'as yet unclassified' }
PPXmlFeedParserTest >> parse: aString rule: aSymbol to: anObject [
| production |
production := self parserInstanceFor: aSymbol.
result := production end parse: aString.
self
deny: result isPetitFailure
description: 'Unable to parse ' , aString printString.
self assert: result = anObject.
^ result
]
{ #category : 'as yet unclassified' }
PPXmlFeedParserTest >> parserClass [
^ PPXmlFeedParser
]
{ #category : 'as yet unclassified' }
PPXmlFeedParserTest >> testItem01 [
self parse: '
-
abc
' rule: #item.
self assert: (result at: #name) = 'abc'.
]
{ #category : 'as yet unclassified' }
PPXmlFeedParserTest >> testItem02 [
self parse: '
-
abc
123
' rule: #item.
self assert: (result at: #name) = 'abc'.
self assert: (result at: #price) = '123'.
]
{ #category : 'as yet unclassified' }
PPXmlFeedParserTest >> testItem03 [
self parse: '
-
123
abc
' rule: #item.
self assert: (result at: #name) = 'abc'.
self assert: (result at: #price) = '123'.
]
{ #category : 'as yet unclassified' }
PPXmlFeedParserTest >> testShoplist [
self testShoplist01.
self testShoplist02.
self testShoplist03.
]
{ #category : 'as yet unclassified' }
PPXmlFeedParserTest >> testShoplist01 [
self parse: '
-
abc
' rule: #shoplist.
self assert: result size = 1.
]
{ #category : 'as yet unclassified' }
PPXmlFeedParserTest >> testShoplist02 [
self parse: '
xyz
-
abc
123
' rule: #shoplist.
self assert: result size = 1.
]
{ #category : 'as yet unclassified' }
PPXmlFeedParserTest >> testShoplist03 [
self parse: '
xyz
-
abc
123
-
cde
345
' rule: #shoplist.
self assert: result size = 2.
]
{ #category : 'as yet unclassified' }
PPXmlFeedParserTest >> testSimpleElement [
self parse: 'b' rule: #simpleElement to: #('a' 'b').
self parse: ' def abc>' rule: #simpleElement to: #('abc' 'def').
self fail: 'b' rule: #simpleElement.
]
{ #category : 'as yet unclassified' }
PPXmlFeedParserTest >> testStringValue [
self parse: 'abc' rule: #stringValue to: 'abc'.
self parse: ' def ' rule: #stringValue to: 'def'.
]
{ #category : 'as yet unclassified' }
PPXmlFeedParserTest >> testXmlFeed01 [
self parse: self feed01.
self assert: result size = 1.
self assert: (result first at:#name) = 'socks'.
self assert: (result first at:#price) = '123'.
self assert: (result first at:#availability) = '1'.
]
{ #category : 'as yet unclassified' }
PPXmlFeedParserTest >> testXmlFeed02 [
self parse: self feed02.
self assert: result size = 2.
self assert: (result first at:#name) = 'socks'.
self assert: (result first at:#price) = '123'.
self assert: (result first at:#availability) = '1'.
self assert: (result second at:#name) = 'shoes'.
self assert: (result second at:#price) = '2345'.
self assert: (result second at:#availability) = '1'.
]
{ #category : 'as yet unclassified' }
PPXmlFeedParserTest >> testXmlFeed03 [
self parse: self feed03.
self assert: result size = 2.
self assert: (result first at:#name) = 'socks'.
self assert: (result first at:#price) = '123'.
self assert: (result first at:#availability) = '1'.
self assert: (result second at:#name) = 'shoes'.
self assert: (result second at:#price) = '3456'.
self assert: (result second at:#availability) = '0'.
]