kursjan / petitparser2

A high-performance top-down parser
MIT License
41 stars 19 forks source link

Test case as an island in a sea? #15

Closed lukego closed 7 years ago

lukego commented 7 years ago

Is there an easy way to test a production such that it is an island in a sea?

That is, I would like to test like this:

self parse: self x rule: #x

except that I want to allow for self x to contain extra text and so to really test the production x islandInSea.

Trick is that I don't want to define a whole new production for the island version (there are too many) and I don't know how to specify the islandInSea because the rule is expected to be a symbol rather than a parser.

The workaround I am using is to prune all the leading/trailing text from my test cases but I feel like leaving it there and making it irrelevant would be more in the spirit of parsing with islands and seas?

kursjan commented 7 years ago

Hi, is this what are you looking for?

Open the PP2SmalltalkGrammarTest and add your own test method:

testIdentifierSea
    | id |
    id := self parserInstanceFor: #identifier.

    self assert: id parse: 'foo'.
    self assert: id fail: '...bar...'.
    self assert: id islandInSea parse: '...bar...'
kursjan commented 7 years ago

BTW, feel free to post relevant questions to stackoverflow with the petitparser2 tag, if you think it is more appropriate.

lukego commented 7 years ago

Thanks! That looks like exactly what I want.

I'm happy using Github but can switch to stackoverflow on request. Personally I feel like mailing lists are too old fashioned, Discourse is too new-fangled, and stuff in between is mostly okay ;-).

kursjan commented 7 years ago

Whatever works for you,... stackoverflow was an idea... sounds a bit more community-friendly to me (but it is just personal opinion)