1(import (readit parser) test)
2
3(define (parse-file path)
4 (call-with-input-file (string-append "testdata" "/" path)
5 (lambda (port) (parse-readit port))))
6
7(define (parse-entries path)
8 (let ((r (parse-file path)))
9 (if r r (error "syntax error"))))
10
11(define (parse-entry path)
12 (car (parse-entries path)))
13
14(test-group "parser"
15 (test "parse entry without fields and notes"
16 (list (make-meta #\-
17 'thompson1984trust
18 "Reflections on Trusting Trust") '() "")
19 (parse-entry "thompson1984trust.txt"))
20
21 (test "parse entry with fields and without notes"
22 (list (make-meta #\x
23 'chomsky1956hierarchy
24 "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"))
31
32 (test "parse entry with set fields"
33 (list (make-meta #\x
34 'ritchie1974unix
35 "The UNIX Time-Sharing System")
36 '(
37 ("Authors" . #("Dennis M. Ritchie" "Ken Thompson"))
38 ("Topics" . #("UNIX"))
39 )
40 "")
41 (parse-entry "ritchie1974unix.txt"))
42
43 (test "parse entry with escaped set fields"
44 (list (make-meta #\-
45 'bratus2015bugs
46 "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"))
56
57 (test "parse entry with ref fields"
58 (list (make-meta #\x
59 'bach1986unix
60 "The Design of the UNIX Operating System")
61 '(
62 ("Related" . #(ritchie1974unix))
63 ("References" . #(dijkstra68sequential pike84blit))
64 )
65 "")
66 (parse-entry "bach1986unix.txt"))
67
68 (test "parse entry without fields and with a single note"
69 (list (make-meta #\-
70 'mccarthy1960lisp
71 "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"))
75
76 (test "parse entry without fields and nested numbered notes"
77 (list (make-meta #\-
78 'rfc7228
79 "Terminology for Constrained-Node Networks")
80 '()
81 (string-append
82 "* 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"))
88
89 (test "parse entry with fields and notes"
90 (list (make-meta #\-
91 'landin1966languages
92 "The next 700 programming languages")
93 '(("DOI" . "10.1145/365230.365257"))
94 (string-append
95 "* Describes a family of unimplemented languages\n"
96 "* Focuses on expression-based languages\n"
97 ))
98 (parse-entry "landin1966languages.txt"))
99
100 (test "parse entry with spaces in notes"
101 (list (make-meta #\-
102 'foo
103 "bar")
104 '()
105 (string-append
106 "* foo\n"
107 "* bar\n"
108 "* baz\n"
109 ))
110 (parse-entry "notes-with-spaces.txt"))
111
112 (test "parse multiple entries"
113 (list
114 (list (make-meta #\-
115 'liedtke1995microkernel
116 "On μ-kernel construction") '() "")
117 (list (make-meta #\-
118 'basili1984complexity
119 "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 #\x
127 'tanenbaum2006secure
128 "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-append
136 "* 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"))
141
142 (test "parse partially invalid data"
143 #f
144 (parse-readit "- [foo]: bar\n- [föö]: baz\n")))
145
146(test-exit)