Testing page for the non-greedy operators
test 1: Non-greedy optional ??
As such the non-greedy optional is not that interesting, but it is needed
as a part of the non-greedy repeating optional, and was the first to be coded,
so its tests come first.
test 1.1
Test if the non-greedy optional finds what it should. Behaves the same with '?' and '??'
A $title [ /1.1/ ]: B ?? $author : BR
Title 1.1a author 1.1
Title 1.1b
test 1.2
Test that the non-greedy optional prefers to skip the pattern.
This should get the $author, and not the $skipped. With a single '?', will get the $skipped as well as 'Another Author'.
A $title [ /1.2/ ] : B ?? $skipped : B $author
Title 1.2
author 1.2
Another Author 1.2
And one more author 1.2
test 2: Non-greedy repeat +?
test 2.1
Test that the non-greedy repeat catches repeating elements where needed. Matching the
BR at the end forces all B's to be matched. All authors should match. Behaves the same with '+' and '+?'.
A $title [ /2.1/ ] : B +? $author : BR
Title 2.1 author
Title 2.1 author second
Title 2.1 author second third
test 2.2
Test that the non-greedy repeat takes the minimal number of hits. It should only get the
first author, and $foo should get the second, not the third, with '+?'. With a simple '+', matches the 'third' as well.
A $title [ /2.2/ ] : B +? $author : B $foo
Title 2.2 first second third
test 3: Non-greedy optional repeat *?
test 3.1
Test that the *? handles missing elements right. $foo should always get the 'endmarker'. Should behave the same with a regular '*', since the endmarker fixes it.
A $title [ /3.1/ ] : B*? $author : I $foo
Title 3.1 endmarker
Title 3.1 author endmarker
Title 3.1 author secondendmarker
Title 3.1 author second third endmarker
test 3.2
Tests that the *? does not match more than necessary. Should match only the first author with '*?', but all of them with a regular '*'
A $title [ /3.2/ ] : B*? $author
Title 3.2 endmarker
Title 3.2 author endmarker
Title 3.2 author secondendmarker
Title 3.2 author second third endmarker
test 3.3
Test that ANY *? works - that is the most likely use case for *?. $foo should always get the endmarker, both with '*?. The regular '*' will only produce one match, with 'First title' and 'last endmarker'. And it will perform worse, although that is hard to see.
A $title [ /3.3/ ] : ANY *? : I $foo
First Title 3.3 endmarker
Title 3.3 author endmarker
Title 3.3 author secondendmarker
Title 3.3 author second third last endmarker