| 1 |
#include <tads.h> |
| 2 |
#include <strbuf.h> |
| 3 |
|
| 4 |
globals: object |
| 5 |
prop1 = nil |
| 6 |
; |
| 7 |
|
| 8 |
main(args) |
| 9 |
{ |
| 10 |
if (args.length() > 1 && args[2] == '-restore') |
| 11 |
{ |
| 12 |
"Restoring...\n"; |
| 13 |
restoreGame('strbuf.t3v'); |
| 14 |
|
| 15 |
"globals.prop1 = <<globals.prop1>>\n"; |
| 16 |
return; |
| 17 |
} |
| 18 |
|
| 19 |
local s = new StringBuffer(); |
| 20 |
|
| 21 |
s.append('Testing '); |
| 22 |
s.append('one... '); |
| 23 |
s.append('two... '); |
| 24 |
s.append('three... '); |
| 25 |
"[1] s=[<<s>>]\n"; |
| 26 |
|
| 27 |
s.deleteChars(1, 8); |
| 28 |
"[2] s=[<<s>>]\n"; |
| 29 |
|
| 30 |
s.deleteChars(8, 3); |
| 31 |
"[3] s=[<<s>>]\n"; |
| 32 |
|
| 33 |
s.insert(8, 'TWO!!!'); |
| 34 |
"[4] s=[<<s>>]\n"; |
| 35 |
|
| 36 |
s.splice(11, 3, '@@@@@'); |
| 37 |
"[5] s=[<<s>>]\n"; |
| 38 |
|
| 39 |
s[4] = '*'; |
| 40 |
s[5] = 35; |
| 41 |
s[6] = 43; |
| 42 |
s[-1] = '$'; |
| 43 |
"[6] s=[<<s>>]\n"; |
| 44 |
|
| 45 |
for (local i = 1 ; i <= 100 ; ++i) |
| 46 |
{ |
| 47 |
s.append('(i is now '); |
| 48 |
s.append(i); |
| 49 |
s.append('...) '); |
| 50 |
} |
| 51 |
"[7] s=[<<s>>]\n"; |
| 52 |
|
| 53 |
s.deleteChars(s.length(), 1); |
| 54 |
"[8] s=[<<s>>]\n"; |
| 55 |
|
| 56 |
"\b[9] s.substr(8,11) = [<<s.substr(8, 11)>>]\n"; |
| 57 |
"[10] s.substr(s.length()-10) = [<<s.substr(s.length() - 10)>>]\n"; |
| 58 |
"[11] s.substr(-10) = [<<s.substr(-10)>>]\n"; |
| 59 |
"[12] s.substr(-11, 5) = [<<s.substr(-11, 5)>>]\n"; |
| 60 |
|
| 61 |
"[13] s.charAt(1) = <<s.charAt(1)>>\n"; |
| 62 |
"[14] s.charAt(2) = <<s.charAt(2)>>\n"; |
| 63 |
"[15] s.charAt(-1) = <<s.charAt(-1)>>\n"; |
| 64 |
"[16] s.charAt(-2) = <<s.charAt(-2)>>\n"; |
| 65 |
|
| 66 |
"\bUndo tests:\b"; |
| 67 |
|
| 68 |
savepoint(); |
| 69 |
|
| 70 |
s.deleteChars(1); |
| 71 |
"[u1] s=[<<s>>]\n"; |
| 72 |
|
| 73 |
undo(); |
| 74 |
"[u2] s=[<<s>>]\n"; |
| 75 |
|
| 76 |
s.deleteChars(1); |
| 77 |
savepoint(); |
| 78 |
|
| 79 |
s.append('Testing '); |
| 80 |
savepoint(); |
| 81 |
|
| 82 |
s.append('one... '); |
| 83 |
savepoint(); |
| 84 |
|
| 85 |
s.append('two... '); |
| 86 |
savepoint(); |
| 87 |
|
| 88 |
s.append('three... '); |
| 89 |
"[u3] s=[<<s>>]\n"; |
| 90 |
|
| 91 |
undo(); |
| 92 |
"[u4] s=[<<s>>]\n"; |
| 93 |
|
| 94 |
undo(); |
| 95 |
"[u5] s=[<<s>>]\n"; |
| 96 |
|
| 97 |
undo(); |
| 98 |
"[u6] s=[<<s>>]\n"; |
| 99 |
|
| 100 |
undo(); |
| 101 |
"[u7] s=[<<s>>]\n"; |
| 102 |
|
| 103 |
s.append('Testing one... two... three...'); |
| 104 |
savepoint(); |
| 105 |
"[u8] s=[<<s>>]\n"; |
| 106 |
|
| 107 |
s.deleteChars(9, 6); |
| 108 |
"[u9] s=[<<s>>]\n"; |
| 109 |
|
| 110 |
undo(); |
| 111 |
"[u10] s=[<<s>>]\n"; |
| 112 |
|
| 113 |
savepoint(); |
| 114 |
s.splice(9, 6, '{SPLICE HERE!!!}'); |
| 115 |
"[u11] s=[<<s>>]\n"; |
| 116 |
|
| 117 |
undo(); |
| 118 |
"[u12] s=[<<s>>]\n"; |
| 119 |
|
| 120 |
savepoint(); |
| 121 |
s.insert(9, '{INSERT HERE!!!}'); |
| 122 |
"[u13] s=[<<s>>]\n"; |
| 123 |
|
| 124 |
undo(); |
| 125 |
"[u14] s=[<<s>>]\n"; |
| 126 |
|
| 127 |
savepoint(); |
| 128 |
s[12] = '*'; |
| 129 |
s[13] = '+'; |
| 130 |
s[14] = '#'; |
| 131 |
"[u15] s=[<<s>>]\n"; |
| 132 |
|
| 133 |
undo(); |
| 134 |
"[u16] s=[<<s>>]\n"; |
| 135 |
|
| 136 |
savepoint(); |
| 137 |
s.copyChars(13, 'ABCDE'); |
| 138 |
"[u17] s=[<<s>>]\n"; |
| 139 |
undo(); |
| 140 |
"[u18] s=[<<s>>]\n"; |
| 141 |
|
| 142 |
"\bComparison tests\b"; |
| 143 |
|
| 144 |
s.deleteChars(1); |
| 145 |
s.append('Hello '); |
| 146 |
s.append('there!'); |
| 147 |
|
| 148 |
local str = 'Hello'; |
| 149 |
str += ' there!'; |
| 150 |
"[c1] s=[<<s>>]\n |
| 151 |
s == 'Hello there!'? <<yesno(s == 'Hello there!')>>\n |
| 152 |
s == str? <<yesno(s == str)>>\n |
| 153 |
'Hello there!' == s ? <<yesno('Hello there!' == s)>>\n |
| 154 |
str == s? <<yesno(str == s)>>\n |
| 155 |
s > 'Hello there!'? <<yesno(s > 'Hello there!')>>\n |
| 156 |
s < 'Hello there!'? <<yesno(s < 'Hello there!')>>\n |
| 157 |
s > str? <<yesno(s > str)>>\n |
| 158 |
s < str? <<yesno(s < str)>>\n |
| 159 |
'Hello there!' > s? <<yesno('Hello there!' > s)>>\n |
| 160 |
'Hello there!' < s? <<yesno('Hello there!' < s)>>\n |
| 161 |
str > s? <<yesno(str > s)>>\n |
| 162 |
str < s? <<yesno(str < s)>>\b"; |
| 163 |
|
| 164 |
s.deleteChars(1); |
| 165 |
s.append('Hello '); |
| 166 |
s.append('here!'); |
| 167 |
"[c2] s=[<<s>>]\n |
| 168 |
s == 'Hello there!'? <<yesno(s == 'Hello there!')>>\n |
| 169 |
s == str? <<yesno(s == str)>>\n |
| 170 |
'Hello there!' == s ? <<yesno('Hello there!' == s)>>\n |
| 171 |
str == s? <<yesno(str == s)>>\n |
| 172 |
s > 'Hello there!'? <<yesno(s > 'Hello there!')>>\n |
| 173 |
s < 'Hello there!'? <<yesno(s < 'Hello there!')>>\n |
| 174 |
s > str? <<yesno(s > str)>>\n |
| 175 |
s < str? <<yesno(s < str)>>\n |
| 176 |
'Hello there!' > s? <<yesno('Hello there!' > s)>>\n |
| 177 |
'Hello there!' < s? <<yesno('Hello there!' < s)>>\n |
| 178 |
str > s? <<yesno(str > s)>>\n |
| 179 |
str < s? <<yesno(str < s)>>\b"; |
| 180 |
|
| 181 |
s.insert(7, 't'); |
| 182 |
str = new StringBuffer(64, 64); |
| 183 |
str.append('Hello '); |
| 184 |
str.append('there!'); |
| 185 |
"[c4] s=[<<s>>], str=[<<str>>]\n |
| 186 |
s == str? <<yesno(s == str)>>\n |
| 187 |
str == s? <<yesno(str == s)>>\n |
| 188 |
s > str? <<yesno(s > str)>>\n |
| 189 |
s < str? <<yesno(s < str)>>\n |
| 190 |
str > s? <<yesno(str > s)>>\n |
| 191 |
str < s? <<yesno(str < s)>>\b"; |
| 192 |
|
| 193 |
s.deleteChars(7, 1); |
| 194 |
"[c5] s=[<<s>>], str=[<<str>>]\n |
| 195 |
s == str? <<yesno(s == str)>>\n |
| 196 |
str == s? <<yesno(str == s)>>\n |
| 197 |
s > str? <<yesno(s > str)>>\n |
| 198 |
s < str? <<yesno(s < str)>>\n |
| 199 |
str > s? <<yesno(str > s)>>\n |
| 200 |
str < s? <<yesno(str < s)>>\b"; |
| 201 |
|
| 202 |
globals.prop1 = s; |
| 203 |
saveGame('strbuf.t3v'); |
| 204 |
} |
| 205 |
|
| 206 |
yesno(val) { return val ? 'yes' : 'no'; } |
| 207 |
|