Elegant way to tests an XMLElement's "string"`

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
tty
Reply | Threaded
Open this post in threaded view
|

Elegant way to tests an XMLElement's "string"`

tty
Hi folks,

I am writing SUnit tests for my PEG grammar and I am not fluent in Streams.

I have my first test that checks the structure of an HTML UnorderedList.
The output of the parse run is an XMLElement.

*testListUnordered
               
        <timeout: 10>
        | xmlElement actor ios|

        actor := PEGWikiMediaGeneratorTables new.
        actor transcripton: false.
        xmlElement := parser parse: 'UnorderedList' stream: (self listUnordered)
reading actor: actor.
        ios := ReadWriteStream on:''.
        xmlElement printOn: ios.
        self assert: ((ios contents) = '<ul><li> one</li><ul><li> two</li><ul><li>
three</li><ul><li> four</li><li> four</li><ul><li> five</li><li>
five</li><li> five</li></ul><li> four</li><li> four</li></ul><li>
three</li><li> three</li></ul><li> two</li></ul></ul>') .
*


Is there a simpler way, minus the Stream to get the "contents" of the
XMLElement?

thanks in advance.



--
Sent from: http://forum.world.st/Squeak-Beginners-f107673.html
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Elegant way to tests an XMLElement's "string"`

Christoph Thiede

Not actually sure what your problem is, but are you aware of String class >> #streamContents:? :-)


io := String streamContents: [:ios |

    xmlElement printOn: ios].


Provided that XMLElement follows the usual conventions, you should also be able to simply say

io := xmlElement printString.

Hope that helps :-)

Best,
Christoph



Von: Beginners <[hidden email]> im Auftrag von tty <[hidden email]>
Gesendet: Mittwoch, 8. April 2020 17:01 Uhr
An: [hidden email]
Betreff: [Newbies] Elegant way to tests an XMLElement's "string"`
 
Hi folks,

I am writing SUnit tests for my PEG grammar and I am not fluent in Streams.

I have my first test that checks the structure of an HTML UnorderedList.
The output of the parse run is an XMLElement.

*testListUnordered
               
        <timeout: 10>
        | xmlElement actor ios|

        actor := PEGWikiMediaGeneratorTables new.
        actor transcripton: false.
        xmlElement := parser parse: 'UnorderedList' stream: (self listUnordered)
reading actor: actor.
        ios := ReadWriteStream on:''.
        xmlElement printOn: ios.
        self assert: ((ios contents) = '<ul><li> one</li><ul><li> two</li><ul><li>
three</li><ul><li> four</li><li> four</li><ul><li> five</li><li>
five</li><li> five</li></ul><li> four</li><li> four</li></ul><li>
three</li><li> three</li></ul><li> two</li></ul></ul>') .
*      


Is there a simpler way, minus the Stream to get the "contents" of the
XMLElement?

thanks in advance.



--
Sent from: http://forum.world.st/Squeak-Beginners-f107673.html
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Carpe Squeak!
Reply | Threaded
Open this post in threaded view
|

Re: Elegant way to tests an XMLElement's "string"`

marcel.taeumel
Yes, looks like #printOn: in XMLElement has everything in place for this scenario:

self
   assert: '<ul><li> one</li><ul><li> two</li><ul><li> three</li><ul><li> four</li><li> four</li><ul><li> five</li><li> five</li><li> five</li></ul><li> four</li><li> four</li></ul><li> three</li><li> three</li></ul><li> two</li></ul></ul>
   equals: xmlElement printString.

Best,
Marcel

Am 18.04.2020 15:10:45 schrieb Thiede, Christoph <[hidden email]>:

Not actually sure what your problem is, but are you aware of String class >> #streamContents:? :-)


io := String streamContents: [:ios |

    xmlElement printOn: ios].


Provided that XMLElement follows the usual conventions, you should also be able to simply say

io := xmlElement printString.

Hope that helps :-)

Best,
Christoph



Von: Beginners <[hidden email]> im Auftrag von tty <[hidden email]>
Gesendet: Mittwoch, 8. April 2020 17:01 Uhr
An: [hidden email]
Betreff: [Newbies] Elegant way to tests an XMLElement's "string"`
 
Hi folks,

I am writing SUnit tests for my PEG grammar and I am not fluent in Streams.

I have my first test that checks the structure of an HTML UnorderedList.
The output of the parse run is an XMLElement.

*testListUnordered
               
        <timeout: 10>
        | xmlElement actor ios|

        actor := PEGWikiMediaGeneratorTables new.
        actor transcripton: false.
        xmlElement := parser parse: 'UnorderedList' stream: (self listUnordered)
reading actor: actor.
        ios := ReadWriteStream on:''.
        xmlElement printOn: ios.
        self assert: ((ios contents) = '<ul><li> one</li><ul><li> two</li><ul><li>
three</li><ul><li> four</li><li> four</li><ul><li> five</li><li>
five</li><li> five</li></ul><li> four</li><li> four</li></ul><li>
three</li><li> three</li></ul><li> two</li></ul></ul>') .
*      


Is there a simpler way, minus the Stream to get the "contents" of the
XMLElement?

thanks in advance.



--
Sent from: http://forum.world.st/Squeak-Beginners-f107673.html
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
tty
Reply | Threaded
Open this post in threaded view
|

Re: Elegant way to tests an XMLElement's "string"`

tty
In reply to this post by Christoph Thiede
Christoph and Marcel

Thank you very much. Just what I was looking for.

cheers,

t



--
Sent from: http://forum.world.st/Squeak-Beginners-f107673.html
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners