diff -r a409905f7f2d -r e2b2ccaa4de6 islands/tests/XmlFeedParserTest.st
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/islands/tests/XmlFeedParserTest.st Wed Oct 08 00:33:44 2014 +0100
@@ -0,0 +1,256 @@
+"{ Package: 'stx:goodies/petitparser/islands/tests' }"
+
+PPCompositeParserTest subclass:#XmlFeedParserTest
+ instanceVariableNames:'debugResult'
+ classVariableNames:''
+ poolDictionaries:''
+ category:'PetitIslands-Examples'
+!
+
+XmlFeedParserTest comment:''
+!
+
+!XmlFeedParserTest methodsFor:'as yet unclassified'!
+
+debug: aString rule: aSymbol
+ | production |
+ production := self parserInstanceFor: aSymbol.
+ debugResult := production end debug: aString.
+ result := debugResult children first result.
+ self
+ deny: result isPetitFailure
+ description: 'Unable to parse ' , aString printString.
+ ^ result
+!
+
+feed01
+^'
+
+ABC Shop
+Here and there 123, 123 45 Somewhere
+-
+ socks
+ 123
+ 1
+
+
+'
+!
+
+feed02
+^'
+
+ABC Shop
+Here and there 123, 123 45 Somewhere
+-
+ socks
+ 123
+ 1
+
+
+
+-
+ shoes
+ 2345
+ 1
+
+
+
+'
+!
+
+feed03
+^'
+
+ABC Shop
+Here and there 123, 123 45 Somewhere
+-
+ socks
+ 123
+ 1
+
+
+
+-
+ shoes
+ 2345
+
+ 1
+
+
+-
+ shoes
+ 3456
+ 0
+
+
+
+
+'
+!
+
+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
+!
+
+parserClass
+ ^ XmlFeedParser
+!
+
+testItem
+ self testItem01.
+ self testItem02.
+ self testItem03.
+
+!
+
+testItem01
+ self debug: '
+ -
+ abc
+
+ ' rule: #item.
+
+ self assert: (result at: #name) = 'abc'.
+
+!
+
+testItem02
+ self debug: '
+ -
+ abc
+ 123
+
+ ' rule: #item.
+
+ self assert: (result at: #name) = 'abc'.
+ self assert: (result at: #price) = '123'.
+
+!
+
+testItem03
+ self debug: '
+ -
+ 123
+ abc
+
+ ' rule: #item.
+
+ self assert: (result at: #name) = 'abc'.
+ self assert: (result at: #price) = '123'.
+
+!
+
+testShoplist
+ self testShoplist01.
+ self testShoplist02.
+ self testShoplist03.
+!
+
+testShoplist01
+ self debug: '
+
+ -
+ abc
+
+
+ ' rule: #shoplist.
+
+ self assert: result size = 1.
+
+!
+
+testShoplist02
+ self debug: '
+
+ xyz
+ -
+ abc
+ 123
+
+
+ ' rule: #shoplist.
+
+ self assert: result size = 1.
+
+!
+
+testShoplist03
+ self debug: '
+
+ xyz
+ -
+ abc
+ 123
+
+ -
+ cde
+ 345
+
+
+ ' rule: #shoplist.
+
+ self assert: result size = 2.
+
+!
+
+testSimpleElement
+ self parse: 'b' rule: #simpleElement to: #('a' 'b').
+ self parse: ' def abc>' rule: #simpleElement to: #('abc' 'def').
+
+ self fail: 'b' rule: #simpleElement.
+
+!
+
+testStringValue
+ self parse: 'abc' rule: #stringValue to: 'abc'.
+ self parse: ' def ' rule: #stringValue to: 'def'.
+
+!
+
+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'.
+
+!
+
+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'.
+
+!
+
+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'.
+
+! !
+