1(import (readit parser) test)23(define (parse-file path)4 (call-with-input-file (string-append "testdata" "/" path)5 (lambda (port) (parse-readit port))))67(define (parse-entries path)8 (let ((r (parse-file path)))9 (if r r (error "syntax error"))))1011(define (parse-entry path)12 (car (parse-entries path)))1314(test-group "parser"15 (test "parse entry without fields and notes"16 (list (make-meta #\-17 'thompson1984trust18 "Reflections on Trusting Trust") '() "")19 (parse-entry "thompson1984trust.txt"))2021 (test "parse entry with fields and without notes"22 (list (make-meta #\x23 'chomsky1956hierarchy24 "Three models for the description of language")25 '(26 ("Importance" . "High")27 ("DOI" . "10.1109/TIT.1956.1056813")28 )29 "")30 (parse-entry "chomsky1956hierarchy.txt"))3132 (test "parse entry with set fields"33 (list (make-meta #\x34 'ritchie1974unix35 "The UNIX Time-Sharing System")36 '(37 ("Authors" . #("Dennis M. Ritchie" "Ken Thompson"))38 ("Topics" . #("UNIX"))39 )40 "")41 (parse-entry "ritchie1974unix.txt"))4243 (test "parse entry with escaped set fields"44 (list (make-meta #\-45 'bratus2015bugs46 "The Bugs We Have to Kill")47 '(48 ("Escaped Comma" . #("foo,bar"))49 ("Escaped Bracket" . #("foo{bar}"))50 ("Escaped Backslash" . #("foo\\bar"))51 ("Escaped All" . #("foobar"))52 ("Escaped Multiple" . #("foo," "bar"))53 )54 "")55 (parse-entry "bratus2015bugs.txt"))5657 (test "parse entry with ref fields"58 (list (make-meta #\x59 'bach1986unix60 "The Design of the UNIX Operating System")61 '(62 ("Related" . #(ritchie1974unix))63 ("References" . #(dijkstra68sequential pike84blit))64 )65 "")66 (parse-entry "bach1986unix.txt"))6768 (test "parse entry without fields and with a single note"69 (list (make-meta #\-70 'mccarthy1960lisp71 "Recursive functions of symbolic expressions and their computation by machine, part I")72 '()73 "* Introduces a programming system called LISP\n")74 (parse-entry "mccarthy1960lisp.txt"))7576 (test "parse entry without fields and nested numbered notes"77 (list (make-meta #\-78 'rfc722879 "Terminology for Constrained-Node Networks")80 '()81 (string-append82 "* Distinguishes three classes of constrained devices:\n"83 "\t1. Class 0: Very constrained sensor-like motes\n"84 "\t2. Class 1: Quite constrained in code space and processing capabilities\n"85 "\t3. Class 2: Can utilize conventional Internet protocols\n"86 ))87 (parse-entry "rfc7228.txt"))8889 (test "parse entry with fields and notes"90 (list (make-meta #\-91 'landin1966languages92 "The next 700 programming languages")93 '(("DOI" . "10.1145/365230.365257"))94 (string-append95 "* Describes a family of unimplemented languages\n"96 "* Focuses on expression-based languages\n"97 ))98 (parse-entry "landin1966languages.txt"))99100 (test "parse entry with spaces in notes"101 (list (make-meta #\-102 'foo103 "bar")104 '()105 (string-append106 "* foo\n"107 "* bar\n"108 "* baz\n"109 ))110 (parse-entry "notes-with-spaces.txt"))111112 (test "parse multiple entries"113 (list114 (list (make-meta #\-115 'liedtke1995microkernel116 "On μ-kernel construction") '() "")117 (list (make-meta #\-118 'basili1984complexity119 "Software Errors and Complexity: An Empirical Investigation")120 '(121 ("Authors" . #("Victor R. Basili" "Barry T. Perricone"))122 ("DOI" . "10.1145/69605.2085")123 ("Topics" . #("Software Engineering"))124 )125 "")126 (list (make-meta #\x127 'tanenbaum2006secure128 "Can We Make Operating Systems Reliable and Secure?")129 '(130 ("Authors" . #("Andrew S. Tanenbaum" "Jorrit N. Herder" "Herbert Bos"))131 ("DOI" . "10.1109/MC.2006.156")132 ("Topics" . #("Computer Security" "Operating Systems"))133 ("References" . #(basili1984complexity liedtke1995microkernel))134 )135 (string-append136 "* Discusses techniques for improving the security of operating systems\n"137 "* Emphasises the importance of isolation mechanisms\n"138 "* Has a focus on microkernel architectures\n"139 )))140 (parse-entries "example.txt"))141142 (test "parse partially invalid data"143 #f144 (parse-readit "- [foo]: bar\n- [föö]: baz\n")))145146(test-exit)