| 1 |
#include <tads.h> |
| 2 |
|
| 3 |
main(args) |
| 4 |
{ |
| 5 |
test('<nocase>%<[a-z]+%>(?<!%<a+%>)', 'a aaa aaaaa aaba aa aaaa'); |
| 6 |
test('s(?!<space>)', 'this is a test string'); |
| 7 |
test('(?<!<space|i>)s', 'this is a silly test string'); |
| 8 |
test('(?<!\\)"', |
| 9 |
'A string with \\"slashed\\" quotes and one-"-non-slashed'); |
| 10 |
test('<nocase>[a-z]+<space>+(?<!test<space>+)word', |
| 11 |
'this is a test word, another test word, a non-test regular word'); |
| 12 |
test('<nocase>[a-z]+<space>+(?<!a test<space>+)word', |
| 13 |
'this is a test word, another test word, a non-test regular word'); |
| 14 |
test('(?<=^|[.!?]<space>+)%<%w+%>', 'This is our test. It\'s very nice.'); |
| 15 |
test('(?<=[.!?]<space>+)%<%w+%>', 'This is our test. It\'s very nice.'); |
| 16 |
|
| 17 |
// These are to test loop detection. Assertions don't consume any |
| 18 |
// input, so applying * to an assertion or group of assertion basically |
| 19 |
// renders the assertion meaningless; and applying + means we should |
| 20 |
// just execute the assertion once. |
| 21 |
test('(?=x)*.*', 'asdf'); // * makes the assertion irrelevant |
| 22 |
test('((?=x))*.*', 'asdf'); // * makes the assertion irrelevant |
| 23 |
test('(?=x)+.*', 'asdf'); // + keeps the assertion |
| 24 |
test('((?=x))+.*', 'asdf'); // + keeps the assertion |
| 25 |
test('(?=x)+.*', 'xyz'); // + keeps the assertion |
| 26 |
test('((?=x))+.*', 'xyz'); // + keeps the assertion |
| 27 |
test('(((?=x)(?=x)(?=x))*)+.*', 'asdf'); // * drops the assertion |
| 28 |
test('(((?=x)(?=x)(?=x))+)*.*', 'asdf'); // * drops the assertion |
| 29 |
test('(((?=x)(?=x)(?=x))+)+.*', 'asdf'); // + keeps it |
| 30 |
test('(((?=x)(?=x)(?=x))+)+.*', 'xyz'); // + keeps it |
| 31 |
} |
| 32 |
|
| 33 |
test(pat, str) |
| 34 |
{ |
| 35 |
"<<pat.htmlify()>><br><<str>><br>"; |
| 36 |
local match = rexSearch(pat, str); |
| 37 |
if (match) |
| 38 |
{ |
| 39 |
"<<makeString('\ ', match[1]-1)>><<makeString('^', match[2])>><br>"; |
| 40 |
"index=<<match[1]>>, length=<<match[2]>>, match=<<match[3]>><br>"; |
| 41 |
} |
| 42 |
else |
| 43 |
"nil<br>"; |
| 44 |
"<br>"; |
| 45 |
} |
| 46 |
|