Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-office/blob/main/tests/mkcases.om # omega-office Omega office documents: read and write office files in Omega Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-office / tests / mkcases.om` 422 lines ยท 7432 bytes Raw Blame History 1 om2 2 note tests/mkcases.om: writes the generated test files into the directory named by argument 1 (it must exist). 3 note Build and run from the repository root: 4 note OMC < tests/mkcases.om > build/mkcases && chmod +x build/mkcases && build/mkcases corpus/gen 5 note Every file is a function of this source only (no clock, no randomness), so a rerun gives the same bytes. 6 note rb-name256.xml, rb-name257.xml an element name of 256 (accepted) and 257 bytes (refusal 70) 7 note rb-attr256.xml, rb-attr257.xml 256 (accepted) and 257 attributes on one element (refusal 71) 8 note rb-abytes-ok.xml, rb-abytes.xml attribute bytes of one tag 262144 (accepted) and 262145 (refusal 72) 9 note rb-depth1024.xml, rb-depth1025.xml nesting 1024 (accepted) and 1025 (refusal 73) 10 note rb-ns4095.xml, rb-ns4096.xml 4095 (accepted) and 4096 namespace declarations in scope (refusal 74) 11 note rb-ref32.xml, rb-ref33.xml a character reference of 32 (accepted) and 33 bytes (refusal 75) 12 note sst1048576.xml, sst1048577.xml shared string tables of `1048576` (accepted) and `1048577` items (refusal 85) 13 note rows.csv 5000 rows of six columns (numbers, text, quotes, commas, empty cells) 14 15 global ob uchar 65536 16 global onb ulong 1 17 global wfd ulong 1 18 global path uchar 4096 19 global dl ulong 1 20 21 text tsl "/" 22 text tusage "usage: mkcases DIR [big]\n" 23 text terr "mkcases: cannot write a file\n" 24 text kq "\"/>" 25 text ksst1 "\n" 26 text ksst2 "s" 27 text ksst3 "\n" 28 29 fn die t view uchar * to void 30 r = write 2 t 0 len t 31 exit 1 32 end 33 34 fn wflush to void 35 n = get onb 0 36 o = ulong 0 37 while lt o n bound `1000000` 38 r = write int get wfd 0 ob o sub n o 39 if le r 0 40 die terr 41 end 42 o = add o ulong r 43 end 44 put onb 0 0 45 end 46 47 fn b c ulong to void 48 n = get onb 0 49 put ob n uchar c 50 n = add n 1 51 put onb 0 n 52 if eq n 65536 53 wflush 54 end 55 end 56 57 fn s t view uchar * to void 58 for i ulong len t bound 4096 59 b ulong get t i 60 end 61 end 62 63 fn num v ulong to void 64 d = new uchar 24 0 65 k = ulong 0 66 x = v 67 while true bound 24 68 put d k uchar add rem x 10 48 69 k = add k 1 70 x = div x 10 71 if eq x 0 72 break 73 end 74 end 75 while gt k 0 bound 24 76 k = sub k 1 77 b ulong get d k 78 end 79 end 80 81 fn rep c ulong n ulong to void 82 for i ulong n bound `1000000` 83 b c 84 end 85 end 86 87 note wopen: create DIR/name (truncate) for writing. 88 fn wopen t view uchar * to void 89 n = get dl 0 90 put path n 47 91 for i ulong len t bound 64 92 put path add add n 1 i get t i 93 end 94 fd = fopen path 0 add add n 1 len t 577 420 95 if lt fd 0 96 die terr 97 end 98 put wfd 0 ulong fd 99 put onb 0 0 100 end 101 102 fn wclose to void 103 wflush 104 r = fclose int get wfd 0 105 if lt r 0 106 die terr 107 end 108 end 109 110 text n256 "rb-name256.xml" 111 text n257 "rb-name257.xml" 112 fn gname t view uchar * k ulong to void 113 wopen t 114 b 60 115 rep 97 k 116 b 47 117 b 62 118 wclose 119 end 120 121 text a256 "rb-attr256.xml" 122 text a257 "rb-attr257.xml" 123 fn gattr t view uchar * k ulong to void 124 wopen t 125 b 60 126 b 97 127 for i ulong k bound 1000 128 b 32 129 b 97 130 num i 131 b 61 132 b 34 133 b 49 134 b 34 135 end 136 b 47 137 b 62 138 wclose 139 end 140 141 text ab1 "rb-abytes-ok.xml" 142 text ab2 "rb-abytes.xml" 143 note gabytes: one attribute v whose value has k bytes: the tag holds 1 + k bytes of names and values. 144 fn gabytes t view uchar * k ulong to void 145 wopen t 146 b 60 147 b 97 148 b 32 149 b 118 150 b 61 151 b 34 152 rep 120 k 153 s kq 154 wclose 155 end 156 157 text d1024 "rb-depth1024.xml" 158 text d1025 "rb-depth1025.xml" 159 fn gdepth t view uchar * k ulong to void 160 wopen t 161 for i ulong k bound 2000 162 b 60 163 b 97 164 b 62 165 end 166 for i ulong k bound 2000 167 b 60 168 b 47 169 b 97 170 b 62 171 end 172 wclose 173 end 174 175 text ns4095 "rb-ns4095.xml" 176 text ns4096 "rb-ns4096.xml" 177 note gns: k declarations xmlns:pN="u", at most 256 per element, elements nested so all are in scope. 178 fn gns t view uchar * k ulong to void 179 wopen t 180 e = ulong 0 181 i = ulong 0 182 while lt i k bound 100 183 b 60 184 b 101 185 j = ulong 0 186 while and lt j 256 lt i k bound 257 187 b 32 188 b 120 189 b 109 190 b 108 191 b 110 192 b 115 193 b 58 194 b 112 195 num i 196 b 61 197 b 34 198 b 117 199 b 34 200 i = add i 1 201 j = add j 1 202 end 203 b 62 204 e = add e 1 205 end 206 for x ulong e bound 100 207 b 60 208 b 47 209 b 101 210 b 62 211 end 212 wclose 213 end 214 215 text r32 "rb-ref32.xml" 216 text r33 "rb-ref33.xml" 217 note gref: a character reference with z leading zeros: the body "#" + z zeros + "65" has 3 + z bytes. 218 fn gref t view uchar * z ulong to void 219 wopen t 220 b 60 221 b 114 222 b 62 223 b 38 224 b 35 225 rep 48 z 226 b 54 227 b 53 228 b 59 229 b 60 230 b 47 231 b 114 232 b 62 233 wclose 234 end 235 236 text sst1 "sst1048576.xml" 237 text sst2 "sst1048577.xml" 238 fn gsst t view uchar * k ulong to void 239 wopen t 240 s ksst1 241 for i ulong k bound `1100000` 242 s ksst2 243 end 244 s ksst3 245 wclose 246 end 247 248 note rows.csv: row i (1..5000): i, i*7 mod 1000 / 8 as a decimal, a word, a field that needs quoting every 249 note 7th row, an empty field every 5th row, -i. 250 text trows "rows.csv" 251 text kw1 "alpha" 252 text kw2 "beta" 253 text kw3 "gamma" 254 text kq1 "\"comma, and \"\"quote\"\"\"" 255 fn grow i ulong to void 256 num i 257 b 44 258 v = rem mul i 7 1000 259 num div v 8 260 b 46 261 num rem v 8 262 b 44 263 k = rem i 3 264 if eq k 0 265 s kw1 266 end 267 if eq k 1 268 s kw2 269 end 270 if eq k 2 271 s kw3 272 end 273 b 44 274 if eq rem i 7 0 275 s kq1 276 else 277 b 120 278 num i 279 end 280 b 44 281 if ne rem i 5 0 282 b 121 283 end 284 b 44 285 b 45 286 num i 287 b 10 288 end 289 290 fn grows to void 291 wopen trows 292 for i ulong 5000 293 grow add i 1 294 end 295 wclose 296 end 297 298 note ---- mkcases DIR big: inputs for the throughput measurement only (README "Measured speed"), not committed ---- 299 note big-document.xml: 600000 paragraphs, each two runs (an entity, a tab), about 64 MiB of WordprocessingML. 300 note big-sheet.xml: 400000 rows of five cells (number, shared string, decimal, inline string, boolean); 301 note big-sst.xml: 1000 shared strings. 302 text tbdoc "big-document.xml" 303 text tbsh "big-sheet.xml" 304 text tbsst "big-sst.xml" 305 text kbd1 "\n" 306 text kbp1 "Sentence " 307 text kbp2 " of the throughput document, with & an entity and some more ordinary words.tail\n" 308 text kbd2 "\n" 309 text kbs1 "\n" 310 text kbs2 "\n" 311 text krow1 "" 314 text kc3 "" 316 text kc5 "inline " 319 text kc8 "" 321 text kc10 "\n" 322 text kss1 "shared string " 323 324 fn gbdoc to void 325 wopen tbdoc 326 s kbd1 327 for i ulong 600000 328 s kbp1 329 num i 330 s kbp2 331 end 332 s kbd2 333 wclose 334 end 335 336 fn gbrow r ulong to void 337 s krow1 338 num r 339 s kc1 340 num r 341 s kc2 342 num r 343 s kc3 344 num r 345 s kc4 346 num rem r 1000 347 s kc5 348 num r 349 s kc2 350 num div r 2 351 b 46 352 num mul rem r 2 5 353 s kc6 354 num r 355 s kc7 356 num r 357 s kc8 358 num r 359 s kc9 360 num rem r 2 361 s kc10 362 end 363 364 fn gbsheet to void 365 wopen tbsh 366 s kbs1 367 for i ulong 400000 368 gbrow add i 1 369 end 370 s kbs2 371 wclose 372 wopen tbsst 373 s ksst1 374 for i ulong 1000 375 s kss1 376 num i 377 b 60 378 b 47 379 b 116 380 b 62 381 b 60 382 b 47 383 b 115 384 b 105 385 b 62 386 end 387 s ksst3 388 wclose 389 end 390 391 fn main to int 392 n = argcnt 393 if and ne n 2 ne n 3 394 die tusage 395 end 396 k = argread 1 path 0 4000 397 if or le k 0 gt k 3999 398 die tusage 399 end 400 put dl 0 ulong k 401 if eq n 3 402 gbdoc 403 gbsheet 404 ret 0 405 end 406 gname n256 256 407 gname n257 257 408 gattr a256 256 409 gattr a257 257 410 gabytes ab1 262143 411 gabytes ab2 262144 412 gdepth d1024 1024 413 gdepth d1025 1025 414 gns ns4095 4095 415 gns ns4096 4096 416 gref r32 29 417 gref r33 30 418 gsst sst1 `1048576` 419 gsst sst2 `1048577` 420 grows 421 ret 0 422 end