| 1 |
#include <tads.h> |
| 2 |
|
| 3 |
main(args) |
| 4 |
{ |
| 5 |
test('one,two,three', ','); |
| 6 |
test('one,two,three', ',', 1); |
| 7 |
test('one,two,three', ',', 3); |
| 8 |
test('one,two,three', ',', 10); |
| 9 |
test('one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,' |
| 10 |
+ 'thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,' |
| 11 |
+ 'nineteen,twenty,twenty-one,twenty-two,twenty-three', ','); |
| 12 |
test('one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,' |
| 13 |
+ 'thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,' |
| 14 |
+ 'nineteen,twenty,twenty-one,twenty-two,twenty-three', ',', 5); |
| 15 |
test('one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,' |
| 16 |
+ 'thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,' |
| 17 |
+ 'nineteen,twenty,twenty-one,twenty-two,twenty-three', ',', 16); |
| 18 |
test('one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,' |
| 19 |
+ 'thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,' |
| 20 |
+ 'nineteen,twenty,twenty-one,twenty-two,twenty-three', ',', 30); |
| 21 |
|
| 22 |
testi('abcdefghi'); |
| 23 |
testi('abcdefghi', 2); |
| 24 |
testi('abcdefghi', 3); |
| 25 |
testi('abcdefghi', 3, 2); |
| 26 |
testi('abcdefghi', 3, 3); |
| 27 |
testi('abcdefghi', 22); |
| 28 |
|
| 29 |
testp('one,two, three, four', ',<space>*'); |
| 30 |
testp('one,two, three, four, five, six', ',<space>*', 3); |
| 31 |
testp('one,two, three, four, five, six', ',<space>*', 5); |
| 32 |
} |
| 33 |
|
| 34 |
testi(str, delim?, limit?) |
| 35 |
{ |
| 36 |
"'<<str.htmlify()>>'.split(<<delim>>, <<limit>>) -> << |
| 37 |
sayList(str.split(delim, limit))>>\b"; |
| 38 |
} |
| 39 |
|
| 40 |
test(str, delim?, limit?) |
| 41 |
{ |
| 42 |
local delimStr = (delim.ofKind(RexPattern) |
| 43 |
? '/<<delim.getPatternString()>>/' : delim); |
| 44 |
"'<<str.htmlify()>>'.split('<<delimStr.htmlify()>>', <<limit>>) -> << |
| 45 |
sayList(str.split(delim, limit))>>\b"; |
| 46 |
} |
| 47 |
|
| 48 |
testp(str, delim, limit?) |
| 49 |
{ |
| 50 |
test(str, new RexPattern(delim), limit); |
| 51 |
} |
| 52 |
|
| 53 |
sayList(lst) |
| 54 |
{ |
| 55 |
"["; |
| 56 |
for (local i = 1, local len = lst.length() ; i <= len ; ++i) |
| 57 |
{ |
| 58 |
if (i > 1) |
| 59 |
", "; |
| 60 |
"'<<lst[i]>>'"; |
| 61 |
} |
| 62 |
"]"; |
| 63 |
} |
| 64 |
|