1 1.1 christos /*- 2 1.3 christos * Copyright (c) 2012-2017 Dag-Erling Smrgrav 3 1.1 christos * All rights reserved. 4 1.1 christos * 5 1.1 christos * Redistribution and use in source and binary forms, with or without 6 1.1 christos * modification, are permitted provided that the following conditions 7 1.1 christos * are met: 8 1.1 christos * 1. Redistributions of source code must retain the above copyright 9 1.2 christos * notice, this list of conditions and the following disclaimer. 10 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright 11 1.1 christos * notice, this list of conditions and the following disclaimer in the 12 1.1 christos * documentation and/or other materials provided with the distribution. 13 1.1 christos * 3. The name of the author may not be used to endorse or promote 14 1.1 christos * products derived from this software without specific prior written 15 1.1 christos * permission. 16 1.1 christos * 17 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 1.1 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 1.1 christos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 1.1 christos * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 1.1 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 1.1 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 1.1 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 1.1 christos * SUCH DAMAGE. 28 1.1 christos */ 29 1.1 christos 30 1.1 christos #ifdef HAVE_CONFIG_H 31 1.1 christos # include "config.h" 32 1.1 christos #endif 33 1.1 christos 34 1.1 christos #include <err.h> 35 1.3 christos #include <stdint.h> 36 1.1 christos #include <stdio.h> 37 1.1 christos #include <stdlib.h> 38 1.1 christos #include <string.h> 39 1.1 christos #include <unistd.h> 40 1.1 christos 41 1.3 christos #include <cryb/test.h> 42 1.3 christos 43 1.1 christos #include <security/pam_appl.h> 44 1.1 christos #include <security/openpam.h> 45 1.1 christos 46 1.3 christos #define T_FUNC(n, d) \ 47 1.3 christos static const char *t_ ## n ## _desc = d; \ 48 1.3 christos static int t_ ## n ## _func(OPENPAM_UNUSED(char **desc), \ 49 1.3 christos OPENPAM_UNUSED(void *arg)) 50 1.3 christos 51 1.3 christos #define T(n) \ 52 1.3 christos t_add_test(&t_ ## n ## _func, NULL, "%s", t_ ## n ## _desc) 53 1.1 christos 54 1.1 christos /* 55 1.1 christos * Read a word from the temp file and verify that the result matches our 56 1.1 christos * expectations: whether a word was read at all, how many lines were read 57 1.1 christos * (in case of quoted or escaped newlines), whether we reached the end of 58 1.1 christos * the file and whether we reached the end of the line. 59 1.1 christos */ 60 1.1 christos static int 61 1.2 christos orw_expect(struct t_file *tf, const char *expected, int lines, int eof, int eol) 62 1.1 christos { 63 1.1 christos int ch, lineno = 0; 64 1.1 christos char *got; 65 1.1 christos size_t len; 66 1.3 christos int ret; 67 1.1 christos 68 1.2 christos got = openpam_readword(tf->file, &lineno, &len); 69 1.3 christos ret = 1; 70 1.2 christos if (t_ferror(tf)) 71 1.2 christos err(1, "%s(): %s", __func__, tf->name); 72 1.1 christos if (expected != NULL && got == NULL) { 73 1.3 christos t_printv("expected <<%s>>, got nothing\n", expected); 74 1.3 christos ret = 0; 75 1.3 christos } else if (expected == NULL && got != NULL) { 76 1.3 christos t_printv("expected nothing, got <<%s>>\n", got); 77 1.3 christos ret = 0; 78 1.3 christos } else if (expected != NULL && got != NULL && strcmp(expected, got) != 0) { 79 1.3 christos t_printv("expected <<%s>>, got <<%s>>\n", expected, got); 80 1.3 christos ret = 0; 81 1.1 christos } 82 1.3 christos free(got); 83 1.1 christos if (lineno != lines) { 84 1.3 christos t_printv("expected to advance %d lines, advanced %d lines\n", 85 1.1 christos lines, lineno); 86 1.3 christos ret = 0; 87 1.1 christos } 88 1.2 christos if (eof && !t_feof(tf)) { 89 1.3 christos t_printv("expected EOF, but didn't get it\n"); 90 1.3 christos ret = 0; 91 1.1 christos } 92 1.2 christos if (!eof && t_feof(tf)) { 93 1.3 christos t_printv("didn't expect EOF, but got it anyway\n"); 94 1.3 christos ret = 0; 95 1.1 christos } 96 1.2 christos ch = fgetc(tf->file); 97 1.2 christos if (t_ferror(tf)) 98 1.2 christos err(1, "%s(): %s", __func__, tf->name); 99 1.1 christos if (eol && ch != '\n') { 100 1.3 christos t_printv("expected EOL, but didn't get it\n"); 101 1.3 christos ret = 0; 102 1.3 christos } else if (!eol && ch == '\n') { 103 1.3 christos t_printv("didn't expect EOL, but got it anyway\n"); 104 1.3 christos ret = 0; 105 1.1 christos } 106 1.1 christos if (ch != EOF) 107 1.2 christos ungetc(ch, tf->file); 108 1.3 christos return (ret); 109 1.1 christos } 110 1.1 christos 111 1.1 christos 112 1.1 christos /*************************************************************************** 114 1.1 christos * Lines without words 115 1.1 christos */ 116 1.1 christos 117 1.1 christos T_FUNC(empty_input, "empty input") 118 1.2 christos { 119 1.1 christos struct t_file *tf; 120 1.1 christos int ret; 121 1.2 christos 122 1.2 christos tf = t_fopen(NULL); 123 1.2 christos ret = orw_expect(tf, NULL, 0 /*lines*/, 1 /*eof*/, 0 /*eol*/); 124 1.1 christos t_fclose(tf); 125 1.1 christos return (ret); 126 1.1 christos } 127 1.1 christos 128 1.1 christos T_FUNC(empty_line, "empty line") 129 1.2 christos { 130 1.1 christos struct t_file *tf; 131 1.1 christos int ret; 132 1.2 christos 133 1.2 christos tf = t_fopen(NULL); 134 1.2 christos t_fprintf(tf, "\n"); 135 1.2 christos t_frewind(tf); 136 1.2 christos ret = orw_expect(tf, NULL, 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 137 1.1 christos t_fclose(tf); 138 1.1 christos return (ret); 139 1.1 christos } 140 1.1 christos 141 1.1 christos T_FUNC(unterminated_line, "unterminated line") 142 1.2 christos { 143 1.1 christos struct t_file *tf; 144 1.1 christos int ret; 145 1.2 christos 146 1.2 christos tf = t_fopen(NULL); 147 1.2 christos t_fprintf(tf, " "); 148 1.2 christos t_frewind(tf); 149 1.2 christos ret = orw_expect(tf, NULL, 0 /*lines*/, 1 /*eof*/, 0 /*eol*/); 150 1.1 christos t_fclose(tf); 151 1.1 christos return (ret); 152 1.1 christos } 153 1.1 christos 154 1.1 christos T_FUNC(single_whitespace, "single whitespace") 155 1.2 christos { 156 1.1 christos struct t_file *tf; 157 1.1 christos int ret; 158 1.2 christos 159 1.2 christos tf = t_fopen(NULL); 160 1.2 christos t_fprintf(tf, " \n"); 161 1.2 christos t_frewind(tf); 162 1.2 christos ret = orw_expect(tf, NULL, 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 163 1.1 christos t_fclose(tf); 164 1.1 christos return (ret); 165 1.1 christos } 166 1.1 christos 167 1.1 christos T_FUNC(multiple_whitespace, "multiple whitespace") 168 1.2 christos { 169 1.2 christos struct t_file *tf; 170 1.2 christos int ret; 171 1.2 christos 172 1.2 christos tf = t_fopen(NULL); 173 1.2 christos t_fprintf(tf, " \t\r\n"); 174 1.2 christos t_frewind(tf); 175 1.2 christos ret = orw_expect(tf, NULL, 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 176 1.2 christos t_fclose(tf); 177 1.2 christos return (ret); 178 1.2 christos } 179 1.2 christos 180 1.2 christos T_FUNC(line_continuation_in_whitespace, "line continuation in whitespace") 181 1.2 christos { 182 1.1 christos struct t_file *tf; 183 1.1 christos int ret; 184 1.2 christos 185 1.2 christos tf = t_fopen(NULL); 186 1.2 christos t_fprintf(tf, " \\\n \n"); 187 1.2 christos t_frewind(tf); 188 1.2 christos ret = orw_expect(tf, NULL, 1 /*lines*/, 0 /*eof*/, 1 /*eol*/); 189 1.1 christos t_fclose(tf); 190 1.1 christos return (ret); 191 1.1 christos } 192 1.1 christos 193 1.1 christos T_FUNC(comment, "comment") 194 1.2 christos { 195 1.1 christos struct t_file *tf; 196 1.1 christos int ret; 197 1.2 christos 198 1.2 christos tf = t_fopen(NULL); 199 1.2 christos t_fprintf(tf, "# comment\n"); 200 1.2 christos t_frewind(tf); 201 1.2 christos ret = orw_expect(tf, NULL, 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 202 1.1 christos t_fclose(tf); 203 1.1 christos return (ret); 204 1.1 christos } 205 1.1 christos 206 1.1 christos T_FUNC(whitespace_before_comment, "whitespace before comment") 207 1.2 christos { 208 1.2 christos struct t_file *tf; 209 1.2 christos int ret; 210 1.2 christos 211 1.2 christos tf = t_fopen(NULL); 212 1.2 christos t_fprintf(tf, " # comment\n"); 213 1.2 christos t_frewind(tf); 214 1.2 christos ret = orw_expect(tf, NULL, 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 215 1.2 christos t_fclose(tf); 216 1.2 christos return (ret); 217 1.2 christos } 218 1.2 christos 219 1.2 christos T_FUNC(single_quoted_comment, "single-quoted comment") 220 1.2 christos { 221 1.1 christos struct t_file *tf; 222 1.1 christos int ret; 223 1.2 christos 224 1.2 christos tf = t_fopen(NULL); 225 1.2 christos t_fprintf(tf, " '# comment'\n"); 226 1.2 christos t_frewind(tf); 227 1.2 christos ret = orw_expect(tf, "# comment", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 228 1.2 christos t_fclose(tf); 229 1.2 christos return (ret); 230 1.2 christos } 231 1.2 christos 232 1.2 christos T_FUNC(double_quoted_comment, "double-quoted comment") 233 1.2 christos { 234 1.2 christos struct t_file *tf; 235 1.2 christos int ret; 236 1.2 christos 237 1.2 christos tf = t_fopen(NULL); 238 1.2 christos t_fprintf(tf, " \"# comment\"\n"); 239 1.2 christos t_frewind(tf); 240 1.2 christos ret = orw_expect(tf, "# comment", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 241 1.2 christos t_fclose(tf); 242 1.2 christos return (ret); 243 1.2 christos } 244 1.2 christos 245 1.2 christos T_FUNC(comment_at_eof, "comment at end of file") 246 1.2 christos { 247 1.2 christos struct t_file *tf; 248 1.2 christos int ret; 249 1.2 christos 250 1.2 christos tf = t_fopen(NULL); 251 1.2 christos t_fprintf(tf, "# comment"); 252 1.2 christos t_frewind(tf); 253 1.2 christos ret = orw_expect(tf, NULL, 0 /*lines*/, 1 /*eof*/, 0 /*eol*/); 254 1.1 christos t_fclose(tf); 255 1.1 christos return (ret); 256 1.1 christos } 257 1.1 christos 258 1.1 christos 259 1.1 christos /*************************************************************************** 261 1.1 christos * Simple cases - no quotes or escapes 262 1.1 christos */ 263 1.1 christos 264 1.1 christos T_FUNC(single_word, "single word") 265 1.2 christos { 266 1.1 christos const char *word = "hello"; 267 1.1 christos struct t_file *tf; 268 1.2 christos int ret; 269 1.2 christos 270 1.2 christos tf = t_fopen(NULL); 271 1.2 christos t_fprintf(tf, "%s\n", word); 272 1.2 christos t_frewind(tf); 273 1.1 christos ret = orw_expect(tf, word, 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 274 1.1 christos t_fclose(tf); 275 1.1 christos return (ret); 276 1.1 christos } 277 1.1 christos 278 1.1 christos T_FUNC(single_whitespace_before_word, "single whitespace before word") 279 1.2 christos { 280 1.1 christos const char *word = "hello"; 281 1.1 christos struct t_file *tf; 282 1.2 christos int ret; 283 1.2 christos 284 1.2 christos tf = t_fopen(NULL); 285 1.2 christos t_fprintf(tf, " %s\n", word); 286 1.2 christos t_frewind(tf); 287 1.1 christos ret = orw_expect(tf, word, 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 288 1.1 christos t_fclose(tf); 289 1.1 christos return (ret); 290 1.1 christos } 291 1.1 christos 292 1.1 christos T_FUNC(double_whitespace_before_word, "double whitespace before word") 293 1.2 christos { 294 1.1 christos const char *word = "hello"; 295 1.1 christos struct t_file *tf; 296 1.2 christos int ret; 297 1.2 christos 298 1.2 christos tf = t_fopen(NULL); 299 1.2 christos t_fprintf(tf, " %s\n", word); 300 1.2 christos t_frewind(tf); 301 1.1 christos ret = orw_expect(tf, word, 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 302 1.1 christos t_fclose(tf); 303 1.1 christos return (ret); 304 1.1 christos } 305 1.1 christos 306 1.1 christos T_FUNC(single_whitespace_after_word, "single whitespace after word") 307 1.2 christos { 308 1.1 christos const char *word = "hello"; 309 1.1 christos struct t_file *tf; 310 1.2 christos int ret; 311 1.2 christos 312 1.2 christos tf = t_fopen(NULL); 313 1.2 christos t_fprintf(tf, "%s \n", word); 314 1.2 christos t_frewind(tf); 315 1.1 christos ret = orw_expect(tf, word, 0 /*lines*/, 0 /*eof*/, 0 /*eol*/); 316 1.1 christos t_fclose(tf); 317 1.1 christos return (ret); 318 1.1 christos } 319 1.1 christos 320 1.1 christos T_FUNC(double_whitespace_after_word, "double whitespace after word") 321 1.2 christos { 322 1.1 christos const char *word = "hello"; 323 1.1 christos struct t_file *tf; 324 1.2 christos int ret; 325 1.2 christos 326 1.2 christos tf = t_fopen(NULL); 327 1.2 christos t_fprintf(tf, "%s \n", word); 328 1.2 christos t_frewind(tf); 329 1.1 christos ret = orw_expect(tf, word, 0 /*lines*/, 0 /*eof*/, 0 /*eol*/); 330 1.1 christos t_fclose(tf); 331 1.1 christos return (ret); 332 1.1 christos } 333 1.1 christos 334 1.1 christos T_FUNC(comment_after_word, "comment after word") 335 1.2 christos { 336 1.1 christos const char *word = "hello"; 337 1.1 christos struct t_file *tf; 338 1.2 christos int ret; 339 1.2 christos 340 1.2 christos tf = t_fopen(NULL); 341 1.2 christos t_fprintf(tf, "%s # comment\n", word); 342 1.2 christos t_frewind(tf); 343 1.2 christos ret = orw_expect(tf, word, 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 344 1.1 christos orw_expect(tf, NULL, 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 345 1.1 christos t_fclose(tf); 346 1.1 christos return (ret); 347 1.1 christos } 348 1.1 christos 349 1.1 christos T_FUNC(word_containing_hash, "word containing hash") 350 1.2 christos { 351 1.1 christos const char *word = "hello#world"; 352 1.1 christos struct t_file *tf; 353 1.2 christos int ret; 354 1.2 christos 355 1.2 christos tf = t_fopen(NULL); 356 1.2 christos t_fprintf(tf, "%s\n", word); 357 1.2 christos t_frewind(tf); 358 1.1 christos ret = orw_expect(tf, word, 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 359 1.1 christos t_fclose(tf); 360 1.1 christos return (ret); 361 1.1 christos } 362 1.1 christos 363 1.1 christos T_FUNC(two_words, "two words") 364 1.2 christos { 365 1.1 christos const char *word[] = { "hello", "world" }; 366 1.1 christos struct t_file *tf; 367 1.2 christos int ret; 368 1.2 christos 369 1.2 christos tf = t_fopen(NULL); 370 1.2 christos t_fprintf(tf, "%s %s\n", word[0], word[1]); 371 1.2 christos t_frewind(tf); 372 1.2 christos ret = orw_expect(tf, word[0], 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 373 1.1 christos orw_expect(tf, word[1], 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 374 1.1 christos t_fclose(tf); 375 1.1 christos return (ret); 376 1.1 christos } 377 1.1 christos 378 1.1 christos 379 1.1 christos /*************************************************************************** 381 1.1 christos * Escapes 382 1.1 christos */ 383 1.2 christos 384 1.1 christos T_FUNC(naked_escape, "naked escape") 385 1.1 christos { 386 1.2 christos struct t_file *tf; 387 1.2 christos int ret; 388 1.2 christos 389 1.2 christos tf = t_fopen(NULL); 390 1.2 christos t_fprintf(tf, "\\"); 391 1.1 christos t_frewind(tf); 392 1.1 christos ret = orw_expect(tf, NULL, 0 /*lines*/, 1 /*eof*/, 0 /*eol*/); 393 1.1 christos t_fclose(tf); 394 1.1 christos return (ret); 395 1.1 christos } 396 1.2 christos 397 1.1 christos T_FUNC(escaped_escape, "escaped escape") 398 1.1 christos { 399 1.2 christos struct t_file *tf; 400 1.2 christos int ret; 401 1.2 christos 402 1.2 christos tf = t_fopen(NULL); 403 1.2 christos t_fprintf(tf, "\\\\\n"); 404 1.1 christos t_frewind(tf); 405 1.1 christos ret = orw_expect(tf, "\\", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 406 1.1 christos t_fclose(tf); 407 1.1 christos return (ret); 408 1.1 christos } 409 1.2 christos 410 1.1 christos T_FUNC(escaped_whitespace, "escaped whitespace") 411 1.1 christos { 412 1.2 christos struct t_file *tf; 413 1.2 christos int ret; 414 1.2 christos 415 1.2 christos tf = t_fopen(NULL); 416 1.2 christos t_fprintf(tf, "\\ \\\t \\\r \\\n\n"); 417 1.2 christos t_frewind(tf); 418 1.1 christos ret = orw_expect(tf, " ", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 419 1.2 christos orw_expect(tf, "\t", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 420 1.2 christos orw_expect(tf, "\r", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 421 1.1 christos /* this last one is a line continuation */ 422 1.1 christos orw_expect(tf, NULL, 1 /*lines*/, 0 /*eof*/, 1 /*eol*/); 423 1.1 christos t_fclose(tf); 424 1.1 christos return (ret); 425 1.1 christos } 426 1.2 christos 427 1.1 christos T_FUNC(escaped_newline_before_word, "escaped newline before word") 428 1.1 christos { 429 1.2 christos struct t_file *tf; 430 1.2 christos int ret; 431 1.2 christos 432 1.2 christos tf = t_fopen(NULL); 433 1.2 christos t_fprintf(tf, "\\\nhello world\n"); 434 1.1 christos t_frewind(tf); 435 1.1 christos ret = orw_expect(tf, "hello", 1 /*lines*/, 0 /*eof*/, 0 /*eol*/); 436 1.1 christos t_fclose(tf); 437 1.1 christos return (ret); 438 1.1 christos } 439 1.2 christos 440 1.1 christos T_FUNC(escaped_newline_within_word, "escaped newline within word") 441 1.1 christos { 442 1.2 christos struct t_file *tf; 443 1.2 christos int ret; 444 1.2 christos 445 1.2 christos tf = t_fopen(NULL); 446 1.2 christos t_fprintf(tf, "hello\\\nworld\n"); 447 1.1 christos t_frewind(tf); 448 1.1 christos ret = orw_expect(tf, "helloworld", 1 /*lines*/, 0 /*eof*/, 1 /*eol*/); 449 1.1 christos t_fclose(tf); 450 1.1 christos return (ret); 451 1.1 christos } 452 1.2 christos 453 1.1 christos T_FUNC(escaped_newline_after_word, "escaped newline after word") 454 1.1 christos { 455 1.2 christos struct t_file *tf; 456 1.2 christos int ret; 457 1.2 christos 458 1.2 christos tf = t_fopen(NULL); 459 1.2 christos t_fprintf(tf, "hello\\\n world\n"); 460 1.1 christos t_frewind(tf); 461 1.1 christos ret = orw_expect(tf, "hello", 1 /*lines*/, 0 /*eof*/, 0 /*eol*/); 462 1.1 christos t_fclose(tf); 463 1.1 christos return (ret); 464 1.1 christos } 465 1.2 christos 466 1.1 christos T_FUNC(escaped_letter, "escaped letter") 467 1.1 christos { 468 1.2 christos struct t_file *tf; 469 1.2 christos int ret; 470 1.2 christos 471 1.2 christos tf = t_fopen(NULL); 472 1.2 christos t_fprintf(tf, "\\z\n"); 473 1.1 christos t_frewind(tf); 474 1.1 christos ret = orw_expect(tf, "z", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 475 1.1 christos t_fclose(tf); 476 1.3 christos return (ret); 477 1.3 christos } 478 1.3 christos 479 1.3 christos T_FUNC(escaped_comment, "escaped comment") 480 1.3 christos { 481 1.3 christos struct t_file *tf; 482 1.3 christos int ret; 483 1.3 christos 484 1.3 christos tf = t_fopen(NULL); 485 1.3 christos t_fprintf(tf, " \\# comment\n"); 486 1.3 christos t_frewind(tf); 487 1.3 christos ret = orw_expect(tf, "#", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 488 1.3 christos orw_expect(tf, "comment", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 489 1.3 christos t_fclose(tf); 490 1.3 christos return (ret); 491 1.3 christos } 492 1.3 christos 493 1.3 christos T_FUNC(escape_at_eof, "escape at end of file") 494 1.3 christos { 495 1.3 christos struct t_file *tf; 496 1.3 christos int ret; 497 1.3 christos 498 1.3 christos tf = t_fopen(NULL); 499 1.3 christos t_fprintf(tf, "z\\"); 500 1.3 christos t_frewind(tf); 501 1.3 christos ret = orw_expect(tf, NULL, 0 /*lines*/, 1 /*eof*/, 0 /*eol*/); 502 1.3 christos t_fclose(tf); 503 1.1 christos return (ret); 504 1.1 christos } 505 1.2 christos 506 1.2 christos 507 1.2 christos /*************************************************************************** 509 1.2 christos T_FUNC(escaped_comment, "escaped comment") 510 1.2 christos { 511 1.2 christos struct t_file *tf; 512 1.2 christos int ret; 513 1.2 christos 514 1.2 christos tf = t_fopen(NULL); 515 1.2 christos t_fprintf(tf, " \\# comment\n"); 516 1.2 christos t_frewind(tf); 517 1.2 christos ret = orw_expect(tf, "#", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 518 1.2 christos orw_expect(tf, "comment", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 519 1.2 christos t_fclose(tf); 520 1.2 christos return (ret); 521 1.2 christos } 522 1.2 christos 523 1.2 christos T_FUNC(escape_at_eof, "escape at end of file") 524 1.2 christos { 525 1.2 christos struct t_file *tf; 526 1.2 christos int ret; 527 1.2 christos 528 1.2 christos tf = t_fopen(NULL); 529 1.2 christos t_fprintf(tf, "z\\"); 530 1.2 christos t_frewind(tf); 531 1.2 christos ret = orw_expect(tf, NULL, 0 /*lines*/, 1 /*eof*/, 0 /*eol*/); 532 1.1 christos t_fclose(tf); 533 1.1 christos return (ret); 534 1.1 christos } 535 1.1 christos 536 1.1 christos * Quotes 537 1.2 christos */ 538 1.1 christos 539 1.1 christos T_FUNC(naked_single_quote, "naked single quote") 540 1.2 christos { 541 1.2 christos struct t_file *tf; 542 1.2 christos int ret; 543 1.2 christos 544 1.2 christos tf = t_fopen(NULL); 545 1.1 christos t_fprintf(tf, "'"); 546 1.1 christos t_frewind(tf); 547 1.1 christos ret = orw_expect(tf, NULL, 0 /*lines*/, 1 /*eof*/, 0 /*eol*/); 548 1.1 christos t_fclose(tf); 549 1.1 christos return (ret); 550 1.2 christos } 551 1.1 christos 552 1.1 christos T_FUNC(naked_double_quote, "naked double quote") 553 1.2 christos { 554 1.2 christos struct t_file *tf; 555 1.2 christos int ret; 556 1.2 christos 557 1.2 christos tf = t_fopen(NULL); 558 1.1 christos t_fprintf(tf, "\""); 559 1.1 christos t_frewind(tf); 560 1.1 christos ret = orw_expect(tf, NULL, 0 /*lines*/, 1 /*eof*/, 0 /*eol*/); 561 1.1 christos t_fclose(tf); 562 1.1 christos return (ret); 563 1.2 christos } 564 1.1 christos 565 1.1 christos T_FUNC(empty_single_quotes, "empty single quotes") 566 1.2 christos { 567 1.2 christos struct t_file *tf; 568 1.2 christos int ret; 569 1.2 christos 570 1.2 christos tf = t_fopen(NULL); 571 1.1 christos t_fprintf(tf, "''\n"); 572 1.1 christos t_frewind(tf); 573 1.1 christos ret = orw_expect(tf, "", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 574 1.1 christos t_fclose(tf); 575 1.1 christos return (ret); 576 1.2 christos } 577 1.1 christos 578 1.1 christos T_FUNC(empty_double_quotes, "empty double quotes") 579 1.2 christos { 580 1.2 christos struct t_file *tf; 581 1.2 christos int ret; 582 1.2 christos 583 1.2 christos tf = t_fopen(NULL); 584 1.1 christos t_fprintf(tf, "\"\"\n"); 585 1.1 christos t_frewind(tf); 586 1.1 christos ret = orw_expect(tf, "", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 587 1.1 christos t_fclose(tf); 588 1.1 christos return (ret); 589 1.2 christos } 590 1.1 christos 591 1.1 christos T_FUNC(single_quotes_within_double_quotes, "single quotes within double quotes") 592 1.2 christos { 593 1.2 christos struct t_file *tf; 594 1.2 christos int ret; 595 1.2 christos 596 1.2 christos tf = t_fopen(NULL); 597 1.1 christos t_fprintf(tf, "\"' '\"\n"); 598 1.1 christos t_frewind(tf); 599 1.1 christos ret = orw_expect(tf, "' '", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 600 1.1 christos t_fclose(tf); 601 1.1 christos return (ret); 602 1.2 christos } 603 1.1 christos 604 1.1 christos T_FUNC(double_quotes_within_single_quotes, "double quotes within single quotes") 605 1.2 christos { 606 1.2 christos struct t_file *tf; 607 1.2 christos int ret; 608 1.2 christos 609 1.2 christos tf = t_fopen(NULL); 610 1.1 christos t_fprintf(tf, "'\" \"'\n"); 611 1.1 christos t_frewind(tf); 612 1.1 christos ret = orw_expect(tf, "\" \"", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 613 1.1 christos t_fclose(tf); 614 1.1 christos return (ret); 615 1.2 christos } 616 1.1 christos 617 1.1 christos T_FUNC(single_quoted_whitespace, "single-quoted whitespace") 618 1.2 christos { 619 1.2 christos struct t_file *tf; 620 1.2 christos int ret; 621 1.2 christos 622 1.2 christos tf = t_fopen(NULL); 623 1.2 christos t_fprintf(tf, "' ' '\t' '\r' '\n'\n"); 624 1.2 christos t_frewind(tf); 625 1.2 christos ret = orw_expect(tf, " ", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 626 1.1 christos orw_expect(tf, "\t", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 627 1.1 christos orw_expect(tf, "\r", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 628 1.1 christos orw_expect(tf, "\n", 1 /*lines*/, 0 /*eof*/, 1 /*eol*/); 629 1.1 christos t_fclose(tf); 630 1.1 christos return (ret); 631 1.2 christos } 632 1.1 christos 633 1.1 christos T_FUNC(double_quoted_whitespace, "double-quoted whitespace") 634 1.2 christos { 635 1.2 christos struct t_file *tf; 636 1.2 christos int ret; 637 1.2 christos 638 1.2 christos tf = t_fopen(NULL); 639 1.2 christos t_fprintf(tf, "\" \" \"\t\" \"\r\" \"\n\"\n"); 640 1.2 christos t_frewind(tf); 641 1.2 christos ret = orw_expect(tf, " ", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 642 1.1 christos orw_expect(tf, "\t", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 643 1.1 christos orw_expect(tf, "\r", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 644 1.1 christos orw_expect(tf, "\n", 1 /*lines*/, 0 /*eof*/, 1 /*eol*/); 645 1.1 christos t_fclose(tf); 646 1.1 christos return (ret); 647 1.2 christos } 648 1.1 christos 649 1.1 christos T_FUNC(single_quoted_words, "single-quoted words") 650 1.2 christos { 651 1.2 christos struct t_file *tf; 652 1.2 christos int ret; 653 1.2 christos 654 1.2 christos tf = t_fopen(NULL); 655 1.1 christos t_fprintf(tf, "'hello world'\n"); 656 1.1 christos t_frewind(tf); 657 1.1 christos ret = orw_expect(tf, "hello world", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 658 1.1 christos t_fclose(tf); 659 1.1 christos return (ret); 660 1.2 christos } 661 1.2 christos 662 1.2 christos T_FUNC(double_quoted_words, "double-quoted words") 663 1.2 christos { 664 1.2 christos struct t_file *tf; 665 1.2 christos int ret; 666 1.2 christos 667 1.2 christos tf = t_fopen(NULL); 668 1.2 christos t_fprintf(tf, "\"hello world\"\n"); 669 1.2 christos t_frewind(tf); 670 1.2 christos ret = orw_expect(tf, "hello world", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 671 1.2 christos t_fclose(tf); 672 1.2 christos return (ret); 673 1.2 christos } 674 1.2 christos 675 1.2 christos 676 1.2 christos /*************************************************************************** 678 1.2 christos * Combinations of quoted and unquoted text 679 1.2 christos */ 680 1.2 christos 681 1.2 christos T_FUNC(single_quote_before_word, "single quote before word") 682 1.2 christos { 683 1.2 christos struct t_file *tf; 684 1.2 christos int ret; 685 1.2 christos 686 1.2 christos tf = t_fopen(NULL); 687 1.2 christos t_fprintf(tf, "'hello 'world\n"); 688 1.2 christos t_frewind(tf); 689 1.2 christos ret = orw_expect(tf, "hello world", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 690 1.2 christos t_fclose(tf); 691 1.2 christos return (ret); 692 1.2 christos } 693 1.2 christos 694 1.2 christos T_FUNC(double_quote_before_word, "double quote before word") 695 1.2 christos { 696 1.2 christos struct t_file *tf; 697 1.2 christos int ret; 698 1.2 christos 699 1.2 christos tf = t_fopen(NULL); 700 1.2 christos t_fprintf(tf, "\"hello \"world\n"); 701 1.2 christos t_frewind(tf); 702 1.2 christos ret = orw_expect(tf, "hello world", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 703 1.2 christos t_fclose(tf); 704 1.2 christos return (ret); 705 1.2 christos } 706 1.2 christos 707 1.2 christos T_FUNC(single_quote_within_word, "single quote within word") 708 1.2 christos { 709 1.2 christos struct t_file *tf; 710 1.2 christos int ret; 711 1.2 christos 712 1.2 christos tf = t_fopen(NULL); 713 1.2 christos t_fprintf(tf, "hello' 'world\n"); 714 1.2 christos t_frewind(tf); 715 1.2 christos ret = orw_expect(tf, "hello world", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 716 1.2 christos t_fclose(tf); 717 1.2 christos return (ret); 718 1.1 christos } 719 1.1 christos 720 1.2 christos T_FUNC(double_quote_within_word, "double quote within word") 721 1.2 christos { 722 1.2 christos struct t_file *tf; 723 1.2 christos int ret; 724 1.2 christos 725 1.2 christos tf = t_fopen(NULL); 726 1.2 christos t_fprintf(tf, "hello\" \"world\n"); 727 1.2 christos t_frewind(tf); 728 1.2 christos ret = orw_expect(tf, "hello world", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 729 1.2 christos t_fclose(tf); 730 1.2 christos return (ret); 731 1.2 christos } 732 1.2 christos 733 1.2 christos T_FUNC(single_quote_after_word, "single quote after word") 734 1.2 christos { 735 1.2 christos struct t_file *tf; 736 1.2 christos int ret; 737 1.2 christos 738 1.2 christos tf = t_fopen(NULL); 739 1.2 christos t_fprintf(tf, "hello' world'\n"); 740 1.2 christos t_frewind(tf); 741 1.2 christos ret = orw_expect(tf, "hello world", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 742 1.2 christos t_fclose(tf); 743 1.2 christos return (ret); 744 1.2 christos } 745 1.2 christos 746 1.2 christos T_FUNC(double_quote_after_word, "double quote after word") 747 1.2 christos { 748 1.2 christos struct t_file *tf; 749 1.2 christos int ret; 750 1.2 christos 751 1.1 christos tf = t_fopen(NULL); 752 1.1 christos t_fprintf(tf, "hello\" world\"\n"); 753 1.1 christos t_frewind(tf); 754 1.1 christos ret = orw_expect(tf, "hello world", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 755 1.1 christos t_fclose(tf); 756 1.1 christos return (ret); 757 1.1 christos } 758 1.1 christos 759 1.1 christos 760 1.1 christos /*************************************************************************** 762 1.2 christos * Combinations of escape and quotes 763 1.1 christos */ 764 1.1 christos 765 1.2 christos T_FUNC(escaped_single_quote, 766 1.2 christos "escaped single quote") 767 1.2 christos { 768 1.2 christos struct t_file *tf; 769 1.2 christos int ret; 770 1.1 christos 771 1.1 christos tf = t_fopen(NULL); 772 1.1 christos t_fprintf(tf, "\\'\n"); 773 1.1 christos t_frewind(tf); 774 1.1 christos ret = orw_expect(tf, "'", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 775 1.1 christos t_fclose(tf); 776 1.2 christos return (ret); 777 1.1 christos } 778 1.1 christos 779 1.2 christos T_FUNC(escaped_double_quote, 780 1.2 christos "escaped double quote") 781 1.2 christos { 782 1.2 christos struct t_file *tf; 783 1.2 christos int ret; 784 1.1 christos 785 1.1 christos tf = t_fopen(NULL); 786 1.1 christos t_fprintf(tf, "\\\"\n"); 787 1.1 christos t_frewind(tf); 788 1.1 christos ret = orw_expect(tf, "\"", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 789 1.1 christos t_fclose(tf); 790 1.2 christos return (ret); 791 1.1 christos } 792 1.1 christos 793 1.2 christos T_FUNC(escaped_whitespace_within_single_quotes, 794 1.2 christos "escaped whitespace within single quotes") 795 1.2 christos { 796 1.2 christos struct t_file *tf; 797 1.2 christos int ret; 798 1.2 christos 799 1.2 christos tf = t_fopen(NULL); 800 1.2 christos t_fprintf(tf, "'\\ ' '\\\t' '\\\r' '\\\n'\n"); 801 1.1 christos t_frewind(tf); 802 1.1 christos ret = orw_expect(tf, "\\ ", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 803 1.1 christos orw_expect(tf, "\\\t", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 804 1.1 christos orw_expect(tf, "\\\r", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 805 1.1 christos orw_expect(tf, "\\\n", 1 /*lines*/, 0 /*eof*/, 1 /*eol*/); 806 1.1 christos t_fclose(tf); 807 1.2 christos return (ret); 808 1.1 christos } 809 1.1 christos 810 1.2 christos T_FUNC(escaped_whitespace_within_double_quotes, 811 1.2 christos "escaped whitespace within double quotes") 812 1.2 christos { 813 1.2 christos struct t_file *tf; 814 1.2 christos int ret; 815 1.2 christos 816 1.1 christos tf = t_fopen(NULL); 817 1.2 christos t_fprintf(tf, "\"\\ \" \"\\\t\" \"\\\r\" \"\\\n\"\n"); 818 1.2 christos t_frewind(tf); 819 1.1 christos ret = orw_expect(tf, "\\ ", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 820 1.1 christos orw_expect(tf, "\\\t", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 821 1.1 christos orw_expect(tf, "\\\r", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 822 1.1 christos /* this last one is a line continuation */ 823 1.1 christos orw_expect(tf, "", 1 /*lines*/, 0 /*eof*/, 1 /*eol*/); 824 1.1 christos t_fclose(tf); 825 1.2 christos return (ret); 826 1.1 christos } 827 1.1 christos 828 1.2 christos T_FUNC(escaped_letter_within_single_quotes, 829 1.2 christos "escaped letter within single quotes") 830 1.2 christos { 831 1.2 christos struct t_file *tf; 832 1.2 christos int ret; 833 1.1 christos 834 1.1 christos tf = t_fopen(NULL); 835 1.1 christos t_fprintf(tf, "'\\z'\n"); 836 1.1 christos t_frewind(tf); 837 1.1 christos ret = orw_expect(tf, "\\z", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 838 1.1 christos t_fclose(tf); 839 1.2 christos return (ret); 840 1.1 christos } 841 1.1 christos 842 1.2 christos T_FUNC(escaped_letter_within_double_quotes, 843 1.2 christos "escaped letter within double quotes") 844 1.2 christos { 845 1.2 christos struct t_file *tf; 846 1.2 christos int ret; 847 1.1 christos 848 1.1 christos tf = t_fopen(NULL); 849 1.1 christos t_fprintf(tf, "\"\\z\"\n"); 850 1.1 christos t_frewind(tf); 851 1.1 christos ret = orw_expect(tf, "\\z", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 852 1.1 christos t_fclose(tf); 853 1.2 christos return (ret); 854 1.1 christos } 855 1.1 christos 856 1.2 christos T_FUNC(escaped_escape_within_single_quotes, 857 1.2 christos "escaped escape within single quotes") 858 1.2 christos { 859 1.2 christos struct t_file *tf; 860 1.2 christos int ret; 861 1.1 christos 862 1.1 christos tf = t_fopen(NULL); 863 1.1 christos t_fprintf(tf, "'\\\\'\n"); 864 1.1 christos t_frewind(tf); 865 1.1 christos ret = orw_expect(tf, "\\\\", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 866 1.1 christos t_fclose(tf); 867 1.2 christos return (ret); 868 1.1 christos } 869 1.1 christos 870 1.2 christos T_FUNC(escaped_escape_within_double_quotes, 871 1.2 christos "escaped escape within double quotes") 872 1.2 christos { 873 1.2 christos struct t_file *tf; 874 1.2 christos int ret; 875 1.1 christos 876 1.1 christos tf = t_fopen(NULL); 877 1.1 christos t_fprintf(tf, "\"\\\\\"\n"); 878 1.1 christos t_frewind(tf); 879 1.1 christos ret = orw_expect(tf, "\\", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 880 1.1 christos t_fclose(tf); 881 1.2 christos return (ret); 882 1.1 christos } 883 1.1 christos 884 1.2 christos T_FUNC(escaped_single_quote_within_single_quotes, 885 1.2 christos "escaped single quote within single quotes") 886 1.2 christos { 887 1.2 christos struct t_file *tf; 888 1.2 christos int ret; 889 1.1 christos 890 1.1 christos tf = t_fopen(NULL); 891 1.1 christos t_fprintf(tf, "'\\''\n"); 892 1.1 christos t_frewind(tf); 893 1.1 christos ret = orw_expect(tf, NULL, 1 /*lines*/, 1 /*eof*/, 0 /*eol*/); 894 1.1 christos t_fclose(tf); 895 1.2 christos return (ret); 896 1.1 christos } 897 1.1 christos 898 1.2 christos T_FUNC(escaped_double_quote_within_single_quotes, 899 1.2 christos "escaped double quote within single quotes") 900 1.2 christos { 901 1.2 christos struct t_file *tf; 902 1.2 christos int ret; 903 1.1 christos 904 1.1 christos tf = t_fopen(NULL); 905 1.1 christos t_fprintf(tf, "'\\\"'\n"); 906 1.1 christos t_frewind(tf); 907 1.1 christos ret = orw_expect(tf, "\\\"", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 908 1.1 christos t_fclose(tf); 909 1.2 christos return (ret); 910 1.1 christos } 911 1.1 christos 912 1.2 christos T_FUNC(escaped_single_quote_within_double_quotes, 913 1.2 christos "escaped single quote within double quotes") 914 1.2 christos { 915 1.2 christos struct t_file *tf; 916 1.2 christos int ret; 917 1.1 christos 918 1.1 christos tf = t_fopen(NULL); 919 1.1 christos t_fprintf(tf, "\"\\'\"\n"); 920 1.1 christos t_frewind(tf); 921 1.1 christos ret = orw_expect(tf, "\\'", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 922 1.1 christos t_fclose(tf); 923 1.2 christos return (ret); 924 1.1 christos } 925 1.1 christos 926 1.2 christos T_FUNC(escaped_double_quote_within_double_quotes, 927 1.2 christos "escaped double quote within double quotes") 928 1.2 christos { 929 1.2 christos struct t_file *tf; 930 1.2 christos int ret; 931 1.1 christos 932 1.1 christos tf = t_fopen(NULL); 933 1.1 christos t_fprintf(tf, "\"\\\"\"\n"); 934 1.1 christos t_frewind(tf); 935 1.1 christos ret = orw_expect(tf, "\"", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 936 1.3 christos t_fclose(tf); 937 1.1 christos return (ret); 938 1.1 christos } 939 1.3 christos 940 1.3 christos 941 1.3 christos /*************************************************************************** 943 1.1 christos * Line continuation 944 1.3 christos */ 945 1.3 christos 946 1.3 christos T_FUNC(line_continuation_within_whitespace, "line continuation within whitespace") 947 1.3 christos { 948 1.3 christos struct t_file *tf; 949 1.3 christos int ret; 950 1.3 christos 951 1.3 christos tf = t_fopen(NULL); 952 1.1 christos t_fprintf(tf, "hello \\\n world\n"); 953 1.3 christos t_frewind(tf); 954 1.3 christos ret = orw_expect(tf, "hello", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 955 1.3 christos orw_expect(tf, "world", 1 /*lines*/, 0 /*eof*/, 1 /*eol*/); 956 1.3 christos t_fclose(tf); 957 1.3 christos return (ret); 958 1.3 christos } 959 1.3 christos 960 1.3 christos T_FUNC(line_continuation_before_whitespace, "line continuation before whitespace") 961 1.3 christos { 962 1.3 christos struct t_file *tf; 963 1.3 christos int ret; 964 1.3 christos 965 1.3 christos tf = t_fopen(NULL); 966 1.3 christos t_fprintf(tf, "hello\\\n world\n"); 967 1.3 christos t_frewind(tf); 968 1.3 christos ret = orw_expect(tf, "hello", 1 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 969 1.3 christos orw_expect(tf, "world", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 970 1.3 christos t_fclose(tf); 971 1.3 christos return (ret); 972 1.3 christos } 973 1.3 christos 974 1.3 christos T_FUNC(line_continuation_after_whitespace, "line continuation after whitespace") 975 1.3 christos { 976 1.3 christos struct t_file *tf; 977 1.3 christos int ret; 978 1.3 christos 979 1.3 christos tf = t_fopen(NULL); 980 1.3 christos t_fprintf(tf, "hello \\\nworld\n"); 981 1.3 christos t_frewind(tf); 982 1.3 christos ret = orw_expect(tf, "hello", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 983 1.3 christos orw_expect(tf, "world", 1 /*lines*/, 0 /*eof*/, 1 /*eol*/); 984 1.3 christos t_fclose(tf); 985 1.3 christos return (ret); 986 1.3 christos } 987 1.3 christos 988 1.3 christos T_FUNC(line_continuation_within_word, "line continuation within word") 989 1.3 christos { 990 1.3 christos struct t_file *tf; 991 1.3 christos int ret; 992 1.3 christos 993 1.3 christos tf = t_fopen(NULL); 994 1.3 christos t_fprintf(tf, "hello\\\nworld\n"); 995 1.3 christos t_frewind(tf); 996 1.3 christos ret = orw_expect(tf, "helloworld", 1 /*lines*/, 0 /*eof*/, 1 /*eol*/); 997 1.3 christos t_fclose(tf); 998 1.3 christos return (ret); 999 1.3 christos } 1000 1.1 christos 1001 1.1 christos 1002 1.1 christos /*************************************************************************** 1004 1.1 christos * Boilerplate 1005 1.3 christos */ 1006 1.3 christos 1007 1.3 christos static int 1008 1.3 christos t_prepare(int argc, char *argv[]) 1009 1.3 christos { 1010 1.3 christos 1011 1.3 christos (void)argc; 1012 1.3 christos (void)argv; 1013 1.3 christos 1014 1.3 christos T(empty_input); 1015 1.3 christos T(empty_line); 1016 1.3 christos T(unterminated_line); 1017 1.3 christos T(single_whitespace); 1018 1.3 christos T(multiple_whitespace); 1019 1.3 christos T(comment); 1020 1.3 christos T(whitespace_before_comment); 1021 1.3 christos T(single_quoted_comment); 1022 1.3 christos T(double_quoted_comment); 1023 1.3 christos T(comment_at_eof); 1024 1.3 christos 1025 1.3 christos T(single_word); 1026 1.3 christos T(single_whitespace_before_word); 1027 1.3 christos T(double_whitespace_before_word); 1028 1.3 christos T(single_whitespace_after_word); 1029 1.3 christos T(double_whitespace_after_word); 1030 1.3 christos T(comment_after_word); 1031 1.3 christos T(word_containing_hash); 1032 1.3 christos T(two_words); 1033 1.3 christos 1034 1.3 christos T(naked_escape); 1035 1.3 christos T(escaped_escape); 1036 1.3 christos T(escaped_whitespace); 1037 1.3 christos T(escaped_newline_before_word); 1038 1.3 christos T(escaped_newline_within_word); 1039 1.3 christos T(escaped_newline_after_word); 1040 1.3 christos T(escaped_letter); 1041 1.3 christos T(escaped_comment); 1042 1.3 christos T(escape_at_eof); 1043 1.3 christos 1044 1.3 christos T(naked_single_quote); 1045 1.3 christos T(naked_double_quote); 1046 1.3 christos T(empty_single_quotes); 1047 1.3 christos T(empty_double_quotes); 1048 1.3 christos T(single_quotes_within_double_quotes); 1049 1.3 christos T(double_quotes_within_single_quotes); 1050 1.3 christos T(single_quoted_whitespace); 1051 1.3 christos T(double_quoted_whitespace); 1052 1.3 christos T(single_quoted_words); 1053 1.3 christos T(double_quoted_words); 1054 1.3 christos 1055 1.3 christos T(single_quote_before_word); 1056 1.3 christos T(double_quote_before_word); 1057 1.3 christos T(single_quote_within_word); 1058 1.3 christos T(double_quote_within_word); 1059 1.3 christos T(single_quote_after_word); 1060 1.3 christos T(double_quote_after_word); 1061 1.3 christos 1062 1.3 christos T(escaped_single_quote); 1063 1.3 christos T(escaped_double_quote); 1064 1.3 christos T(escaped_whitespace_within_single_quotes); 1065 1.3 christos T(escaped_whitespace_within_double_quotes); 1066 1.3 christos T(escaped_letter_within_single_quotes); 1067 1.3 christos T(escaped_letter_within_double_quotes); 1068 1.3 christos T(escaped_escape_within_single_quotes); 1069 1.3 christos T(escaped_escape_within_double_quotes); 1070 1.3 christos T(escaped_single_quote_within_single_quotes); 1071 1.3 christos T(escaped_double_quote_within_single_quotes); 1072 1.3 christos T(escaped_single_quote_within_double_quotes); 1073 1.1 christos T(escaped_double_quote_within_double_quotes); 1074 1.1 christos 1075 1.3 christos T(line_continuation_within_whitespace); 1076 1.3 christos T(line_continuation_before_whitespace); 1077 1.1 christos T(line_continuation_after_whitespace); 1078 1.3 christos T(line_continuation_within_word); 1079 1.3 christos 1080 1.1 christos return (0); 1081 } 1082 1083 int 1084 main(int argc, char *argv[]) 1085 { 1086 1087 t_main(t_prepare, NULL, argc, argv); 1088 } 1089