]> dreyeck.freedombox.rocks Git - topic-maps.git/blob - tests/xtm-identity.lisp
Implement XTM association and role core with original conformance evidence
[topic-maps.git] / tests / xtm-identity.lisp
1 (defpackage #:topic-maps.xtm.tests
2 (:use #:cl #:topic-maps.tmdm)
3 (:import-from #:topic-maps.xtm #:deserialize-octets #:xtm-rejection #:xtm-unsupported
4 #:xtm-xml-error #:error-code #:error-document-iri #:error-source-key #:error-line #:error-column)
5 (:export #:run-tests #:write-report))
6 (in-package #:topic-maps.xtm.tests)
7
8 (defparameter *document* "https://xtm-tests.example.invalid/cd165b150176c1d6842b37be9cc9051b40d4996b/xtm2/in/example.xtm")
9 (defvar *occurrence-outputs* nil)
10 (defvar *occurrence-controls* nil)
11 (defvar *registered-mergemap-outputs* nil)
12 (defvar *association-outputs* nil)
13 (defvar *association-controls* nil)
14 (defvar *mergemap-controls* nil)
15 (defvar *mergemap-originals* nil)
16 (defvar *datatype-outputs* nil)
17 (defvar *datatype-controls* nil)
18 (defvar *checks* nil)
19 (defvar *cases* nil)
20 (defvar *outputs* nil)
21 (defvar *fixture* nil)
22 (defvar *negative-outputs* nil)
23 (defvar *negative-controls* nil)
24 (defvar *name-outputs* nil)
25 (defvar *name-controls* nil)
26 (defvar *scope-outputs* nil)
27 (defvar *scope-controls* nil)
28 (defvar *iid-outputs* nil)
29 (defvar *iid-controls* nil)
30 (defvar *variant-outputs* nil)
31 (defvar *variant-negative-outputs* nil)
32 (defvar *variant-controls* nil)
33 (defvar *variant-merge-outputs* nil)
34 (defvar *resource-ref-outputs* nil)
35 (defvar *resource-ref-controls* nil)
36 (defvar *uri-data-outputs* nil)
37 (defvar *uri-data-controls* nil)
38 (defvar *variant-iid-outputs* nil)
39 (defvar *variant-iid-controls* nil)
40 (defvar *map-reifier-outputs* nil)
41 (defvar *map-reifier-controls* nil)
42 (defvar *name-reifier-outputs* nil)
43 (defvar *name-reifier-controls* nil)
44 (defvar *name-followup-outputs* nil)
45 (defvar *variant-reifier-outputs* nil)
46 (defvar *variant-reifier-controls* nil)
47 (defun check (name truth)
48 (push name *checks*)
49 (unless truth (error "XTM test failed: ~A" name))
50 (format t "XTM-CHECK-PASS ~A~%" name))
51 (defun bytes (text &optional (encoding :utf-8) bom)
52 (concatenate '(vector (unsigned-byte 8))
53 (if bom (ecase encoding (:utf-8 #(239 187 191)) (:utf-16le #(255 254)) (:utf-16be #(254 255))) #())
54 (babel:string-to-octets text :encoding encoding :use-bom nil)))
55 (defun file-bytes (path)
56 (with-open-file (in path :element-type '(unsigned-byte 8))
57 (let ((data (make-array (file-length in) :element-type '(unsigned-byte 8))))
58 (assert (= (read-sequence data in) (length data))) data)))
59 (defun corpus-path (relative) (merge-pathnames relative (topic-maps.test-foundation:default-corpus-root)))
60 (defun document (body) (format nil "<topicMap xmlns='http://www.topicmaps.org/xtm/' version='2.0'>~A</topicMap>" body))
61 (defun read-body (body &optional (iri *document*))
62 (deserialize-octets (bytes (document body)) :document-iri iri :source-key "local:xtm-semantic-test"))
63 (defun by-id (map name)
64 (find-if (lambda (topic) (member (concatenate 'string *document* "#" name)
65 (topic-item-identifiers topic) :test #'string=)) (topic-map-topics map)))
66 (defun by-si (map iri) (find iri (topic-map-topics map) :test (lambda (iri topic) (member iri (topic-subject-identifiers topic) :test #'string=))))
67 (defun core (map name) (by-si map (concatenate 'string "http://psi.topicmaps.org/iso13250/model/" name)))
68 (defun condition-from (thunk) (handler-case (progn (funcall thunk) nil) (error (c) c)))
69 (defun rejection (name source class code)
70 (let ((c (condition-from (lambda () (deserialize-octets (bytes source) :document-iri *document* :source-key name)))))
71 (check (concatenate 'string name ":class") (typep c class))
72 (check (concatenate 'string name ":code") (eq code (error-code c)))
73 (check (concatenate 'string name ":context") (and (equal (error-document-iri c) *document*) (equal (error-source-key c) name)))
74 (check (concatenate 'string name ":position") (and (integerp (error-line c)) (plusp (error-line c))
75 (integerp (error-column c)) (not (minusp (error-column c)))))))
76 (defun public-state (map)
77 ;; Actual references are retained in the snapshot, not only equivalent XML.
78 (list (item-identifiers map)
79 (mapcar (lambda (topic) (list topic (topic-parent topic) (topic-item-identifiers topic)
80 (topic-subject-identifiers topic) (topic-subject-locators topic)
81 (topic-names topic) (topic-occurrences topic) (topic-roles-played topic))) (topic-map-topics map))
82 (mapcar (lambda (a) (list a (association-parent a) (association-type a) (association-scope a) (item-identifiers a)
83 (mapcar (lambda (r) (list r (association-role-parent r) (association-role-type r)
84 (association-role-player r) (item-identifiers r))) (association-roles a))))
85 (topic-map-associations map))))
86 (defun graph-checks (label map owner type)
87 (let* ((a (first (topic-map-associations map))) (roles (association-roles a))
88 (instance (find (core map "instance") roles :key #'association-role-type :test #'eq))
89 (type-role (find (core map "type") roles :key #'association-role-type :test #'eq)))
90 (check (concatenate 'string label ":counts") (and (= 5 (length (topic-map-topics map))) (= 1 (length (topic-map-associations map))) (= 2 (length roles))))
91 (check (concatenate 'string label ":map-parent-eq") (and (eq map (association-parent a)) (every (lambda (topic) (eq map (topic-parent topic))) (topic-map-topics map))))
92 (check (concatenate 'string label ":association-type-eq") (eq (association-type a) (core map "type-instance")))
93 (check (concatenate 'string label ":role-parent-eq") (every (lambda (role) (eq a (association-role-parent role))) roles))
94 (check (concatenate 'string label ":players-eq") (and (eq owner (association-role-player instance)) (eq type (association-role-player type-role))))
95 (check (concatenate 'string label ":roles-played-eq") (and (member instance (topic-roles-played owner) :test #'eq) (member type-role (topic-roles-played type) :test #'eq)))
96 (check (concatenate 'string label ":canonical-handles") (and (eq a (canonical-association a)) (every (lambda (r) (eq r (canonical-association-role r))) roles)))))
97
98 ;; Slice 21A's twenty successful, previously unregistered originals. Keep this
99 ;; explicit: similar filenames and .sub helpers are not additional contracts.
100 (defparameter *additional-originals*
101 '("itemid-duplicate" "itemid-fragment" "itemid-relative" "itemid"
102 "merge-itemid-with-types" "merge-itemid" "merge-subjid" "merge-subjloc"
103 "subjid-duplicate" "subjid-escaping" "subjid-escaping2" "subjid-fragment"
104 "subjid-relative" "subjid-sameas-itemid" "subjid"
105 "subjloc-duplicate" "subjloc-fragment" "subjloc-multiple" "subjloc-relative" "subjloc"))
106
107 (defun references-current-p (map)
108 (let ((topics (topic-map-topics map)) (associations (topic-map-associations map)))
109 (flet ((live (topic) (and (member topic topics :test #'eq) (eq topic (canonical-topic topic)))))
110 (and
111 (every (lambda (topic) (and (live topic) (eq map (topic-parent topic))
112 (every (lambda (role) (and (eq topic (association-role-player role))
113 (member (association-role-parent role) associations :test #'eq)
114 (member role (association-roles (association-role-parent role)) :test #'eq)))
115 (topic-roles-played topic)))) topics)
116 (every (lambda (a) (and (eq a (canonical-association a)) (eq map (association-parent a))
117 (live (association-type a)) (every #'live (association-scope a))
118 (every (lambda (role) (and (eq role (canonical-association-role role))
119 (eq a (association-role-parent role)) (live (association-role-type role))
120 (live (association-role-player role))
121 (member role (topic-roles-played (association-role-player role)) :test #'eq)))
122 (association-roles a)))) associations)))))
123
124 (defun same-identifiers-p (a b)
125 (and (= (length a) (length b)) (null (set-exclusive-or a b :test #'equal))))
126
127 (defun additional-model-checks (name map)
128 (let* ((topic (by-id map "topic"))
129 (ii (list (concatenate 'string *document* "#topic"))) (si nil) (sl nil)
130 (directory (subseq *document* 0 (1+ (position #\/ *document* :from-end t))))
131 (shared "http://example.org/#topic"))
132 (check (concatenate 'string name ":declared-topic-live-eq")
133 (and topic (eq topic (canonical-topic topic)) (member topic (topic-map-topics map) :test #'eq)))
134 (cond
135 ((equal name "itemid-fragment") (push (concatenate 'string *document* "#topic2") ii))
136 ((equal name "itemid-relative") (push (concatenate 'string directory "more-tests/test.xtm#topic") ii))
137 ((equal name "itemid") (push shared ii))
138 ((member name '("merge-itemid" "merge-itemid-with-types" "merge-subjid" "merge-subjloc") :test #'equal)
139 (push (concatenate 'string *document* "#topic2") ii)
140 (cond ((member name '("merge-itemid" "merge-itemid-with-types") :test #'equal) (push shared ii))
141 ((equal name "merge-subjid") (push shared si))
142 (t (push shared sl)))
143 (check (concatenate 'string name ":merged-declarations-eq") (eq topic (by-id map "topic2"))))
144 ((member name '("subjid-duplicate" "subjid-relative") :test #'equal)
145 (push (concatenate 'string directory "photo.jpg") si))
146 ((equal name "subjid-escaping") (push "http://example.org/test+folder/#topic" si))
147 ((equal name "subjid-escaping2") (push "http://example.org/test folder/#topic" si))
148 ((equal name "subjid-fragment") (push (concatenate 'string *document* "#topic") si))
149 ((equal name "subjid-sameas-itemid")
150 (push "http://psi.example.org/test" ii) (push "http://psi.example.org/test" si))
151 ((equal name "subjid") (push shared si))
152 ((member name '("subjloc-duplicate" "subjloc-relative") :test #'equal)
153 (push (concatenate 'string directory "photo.jpg") sl))
154 ((equal name "subjloc-fragment") (push (concatenate 'string *document* "#topic") sl))
155 ((equal name "subjloc-multiple") (setf sl (list shared "http://example.org/#subject")))
156 ((equal name "subjloc") (push shared sl)))
157 (check (concatenate 'string name ":exact-ii-set") (same-identifiers-p ii (topic-item-identifiers topic)))
158 (check (concatenate 'string name ":exact-si-set") (same-identifiers-p si (topic-subject-identifiers topic)))
159 (check (concatenate 'string name ":exact-sl-set") (same-identifiers-p sl (topic-subject-locators topic)))
160 (check (concatenate 'string name ":no-unrequested-statements-or-reification")
161 (and (null (item-identifiers map)) (null (item-reifier map))
162 (every (lambda (topic) (and (null (topic-names topic)) (null (topic-occurrences topic))
163 (null (topic-reified topic)))) (topic-map-topics map))))
164 (when (equal name "merge-itemid-with-types")
165 (dolist (type-id '("topictype1" "topictype2"))
166 (let* ((type (by-id map type-id))
167 (role (find type (loop for a in (topic-map-associations map) append (association-roles a))
168 :key #'association-role-player :test #'eq))
169 (a (and role (association-role-parent role))))
170 (check (concatenate 'string name ":forward-reference:" type-id)
171 (and type role (eq type (canonical-topic type))
172 (equal (list (concatenate 'string *document* "#" type-id)) (topic-item-identifiers type))
173 (eq (association-role-type role) (core map "type"))
174 (eq (association-type a) (core map "type-instance"))
175 (= 2 (length (association-roles a)))
176 (find-if (lambda (r) (and (eq topic (association-role-player r))
177 (eq (core map "instance") (association-role-type r)))) (association-roles a))))))
178 (dolist (core-id '("type" "instance" "type-instance"))
179 (check (concatenate 'string name ":core-no-extra-ii:" core-id)
180 (null (topic-item-identifiers (core map core-id))))))))
181
182 (defun original-condition-data (condition)
183 (when condition
184 (let ((code (cond ((typep condition 'topic-maps.xtm:xtm-error) (error-code condition))
185 ((typep condition 'item-identifier-error) (item-identifier-error-code condition)))))
186 (topic-maps.test-foundation::fields
187 "class" (string (type-of condition)) "code" (when code (string-downcase (string code)))
188 "message" (princ-to-string condition)))))
189
190 (defun record-original-result (case actual expected condition)
191 ;; No rejection (XML, XTM or TMDM) can satisfy a positive original contract.
192 (topic-maps.test-foundation:record-result case
193 (cond ((typep condition 'xtm-unsupported) :unsupported) (condition :execution-error)
194 ((equalp actual expected) :cxtm-match) (t :cxtm-mismatch))
195 :diagnostics (list (if condition (format nil "~A: ~A" (type-of condition) condition)
196 (format nil "Actual ~D bytes; original baseline ~D bytes." (length actual) (length expected))))))
197
198 (defun original-model-data (map)
199 (when map
200 (flet ((array (items) (coerce items 'vector))
201 (fields (&rest args) (apply #'topic-maps.test-foundation::fields args)))
202 (let ((topics (topic-map-topics map)))
203 (labels ((ref (topic) (1+ (position topic topics :test #'eq))))
204 (fields "topicCount" (length topics) "associationCount" (length (topic-map-associations map))
205 "canonicalParentsAndInverseReferences" (if (references-current-p map) :true :false)
206 "topics" (array (loop for topic in topics collect
207 (fields "ordinal" (ref topic) "itemIdentifiers" (array (topic-item-identifiers topic))
208 "subjectIdentifiers" (array (topic-subject-identifiers topic)) "subjectLocators" (array (topic-subject-locators topic)))))
209 "associations" (array (loop for a in (topic-map-associations map) collect
210 (fields "type" (ref (association-type a)) "roles" (array (loop for role in (association-roles a) collect
211 (fields "type" (ref (association-role-type role)) "player" (ref (association-role-player role))))))))))))))
212
213 (defun original-contracts ()
214 (setf *cases* nil *outputs* nil)
215 (dolist (name (append '("empty" "topic" "itemid-tm" "topic-type" "topic-type-duplicate" "merge-three-way") *additional-originals*))
216 (let* ((id (format nil "xtm2/in/~A.xtm" name))
217 (iri (concatenate 'string "https://xtm-tests.example.invalid/cd165b150176c1d6842b37be9cc9051b40d4996b/" id))
218 (source (corpus-path id)) (baseline (corpus-path (format nil "xtm2/baseline/~A.xtm.cxtm" name)))
219 (case (topic-maps.test-foundation:make-test-case :id id :category :valid :source-pathname source
220 :document-iri iri :expected-outcome :cxtm-equal :expected-baseline baseline
221 :clauses '("XTM 2.0 4.3-4.9,4.20" "TMDM 5.1-5.3,5.7-5.8,6,7.2" "CXTM 3.13,3.18,4")))
222 (raw (file-bytes source)) (raw-before (copy-seq raw))
223 (expected (file-bytes baseline)) (map nil) (actual nil) (condition nil) (before nil))
224 (push case *cases*)
225 (handler-case
226 (setf map (deserialize-octets raw :document-iri iri :source-key id)
227 before (public-state map)
228 actual (topic-maps.cxtm:canonicalize-octets map :base-locator iri))
229 (error (c) (setf condition c)))
230 (record-original-result case actual expected condition)
231 (push (list id actual expected (original-model-data map) (original-condition-data condition) (length raw)) *outputs*)
232 (when condition (error condition))
233 (check (concatenate 'string name ":original-byte-exact") (equalp actual expected))
234 (check (concatenate 'string name ":pure") (equal before (public-state map)))
235 (check (concatenate 'string name ":deterministic") (equalp actual (topic-maps.cxtm:canonicalize-octets map :base-locator iri)))
236 (check (concatenate 'string name ":repeat-pure") (equal before (public-state map)))
237 (check (concatenate 'string name ":topic-count") (= (length (topic-map-topics map))
238 (cond ((member name '("empty" "itemid-tm") :test #'equal) 0)
239 ((member name '("topic-type" "topic-type-duplicate") :test #'equal) 5)
240 ((equal name "merge-itemid-with-types") 6) (t 1))))
241 (check (concatenate 'string name ":association-count") (= (length (topic-map-associations map))
242 (cond ((member name '("topic-type" "topic-type-duplicate") :test #'equal) 1)
243 ((equal name "merge-itemid-with-types") 2) (t 0))))
244 (check (concatenate 'string name ":canonical-parent-and-inverse-eq") (references-current-p map))
245 (check (concatenate 'string name ":source-octets-preserved") (equalp raw raw-before))
246 (when (member name *additional-originals* :test #'equal)
247 (let* ((*document* iri)
248 (other (deserialize-octets raw :document-iri iri :source-key "different-provenance-only")))
249 (additional-model-checks name map)
250 (check (concatenate 'string name ":source-key-only-provenance")
251 (and (equalp (original-model-data map) (original-model-data other))
252 (equalp actual (topic-maps.cxtm:canonicalize-octets other :base-locator iri))))))
253 (when (equal name "topic")
254 (check "topic:actual-item-locator" (equal (topic-item-identifiers (first (topic-map-topics map))) (list (concatenate 'string iri "#topic")))))
255 (when (equal name "itemid-tm")
256 (check "map:actual-item-locator" (equal (item-identifiers map) (list (concatenate 'string iri "#the-topic-map")))))
257 (when (equal name "merge-three-way")
258 (check "merge:three-identifiers" (= 3 (length (topic-item-identifiers (first (topic-map-topics map)))))))
259 (when (member name '("topic-type" "topic-type-duplicate") :test #'equal)
260 (let ((*document* iri)) (graph-checks name map (by-id map "xtm") (by-id map "format"))))))
261 (setf *cases* (nreverse *cases*) *outputs* (nreverse *outputs*))
262 (check "originals:26-unique-case-records"
263 (and (= 26 (length *cases*))
264 (= 26 (length (remove-duplicates *cases* :key #'topic-maps.test-foundation:test-case-id :test #'equal))))))
265
266 (defun result-classification-tests ()
267 (flet ((case-record () (topic-maps.test-foundation:make-test-case
268 :id "local:classification-control" :category :valid :expected-outcome :cxtm-equal)))
269 (let* ((case (case-record)) (expected (third (first *outputs*))) (actual (copy-seq expected)))
270 (setf (aref actual 0) (logxor 1 (aref actual 0)))
271 (record-original-result case actual expected nil)
272 (check "classification:changed-actual-cxtm-is-fail"
273 (and (eq :fail (topic-maps.test-foundation:test-case-status case))
274 (eq :cxtm-mismatch (topic-maps.test-foundation:test-case-actual-outcome case)))))
275 (dolist (spec (list (list "xml" "<a><b></a>" 'xtm-xml-error :fail)
276 (list "xtm" (document "<topic id='2bad'/>") 'xtm-rejection :fail)
277 (list "tmdm" (document "<itemIdentity href='#a'/><topic id='a'/>") 'item-identifier-error :fail)
278 (list "unsupported" (document "<topic id='a'><name><value>N</value><variant><scope><topicRef href='#s'/></scope><resourceData datatype='http://www.w3.org/2001/XMLSchema#anyType'>42</resourceData></variant></name></topic>") 'xtm-unsupported :unsupported)))
279 (let ((case (case-record))
280 (c (condition-from (lambda () (deserialize-octets (bytes (second spec)) :document-iri *document*)))))
281 (record-original-result case nil #() c)
282 (check (concatenate 'string "classification:" (first spec) ":never-positive-pass")
283 (and (typep c (third spec)) (eq (fourth spec) (topic-maps.test-foundation:test-case-status case))
284 (not (eq :cxtm-match (topic-maps.test-foundation:test-case-actual-outcome case)))))))))
285
286 (defun semantic-tests ()
287 (dolist (body '("<topic id='a'><instanceOf><topicRef href='#b'/></instanceOf></topic><topic id='b'/>"
288 "<topic id='b'/><topic id='a'><instanceOf><topicRef href='#b'/></instanceOf></topic>"))
289 (let ((map (read-body body)))
290 (graph-checks (if (search "id='b'/>" body :start2 0 :end2 (min 20 (length body))) "backward" "forward") map (by-id map "a") (by-id map "b"))))
291 (let* ((map (read-body "<topic id='type'><subjectIdentifier href='#si'/></topic><topic id='a'><instanceOf><topicRef href='#si'/></instanceOf></topic>"))
292 (type (by-id map "type")))
293 (graph-checks "si-hit" map (by-id map "a") type)
294 (check "si-hit:no-extra-ii" (equal (topic-item-identifiers type) (list (concatenate 'string *document* "#type")))))
295 (let* ((map (read-body "<topic id='a'><instanceOf><topicRef href='#si'/></instanceOf></topic><topic id='type'><subjectIdentifier href='#si'/></topic>"))
296 (type (by-id map "type")))
297 (graph-checks "forward-si" map (by-id map "a") type)
298 (check "forward-si:created-ii-retained" (= 2 (length (topic-item-identifiers type)))))
299 (let* ((map (read-body "<topic id='type'><itemIdentity href='#alias'/></topic><topic id='a'><instanceOf><topicRef href='#alias'/><topicRef href='#type'/></instanceOf></topic>"))
300 (type (by-id map "type")))
301 (graph-checks "ii-hit" map (by-id map "a") type)
302 (check "ii-hit:identifiers-unchanged" (= 2 (length (topic-item-identifiers type)))))
303 (let* ((map (make-topic-map)) (si (intern-topic map :subject-identifier (concatenate 'string *document* "#s")))
304 (hit (topic-maps.xtm::find-reference-topic map (concatenate 'string *document* "#s"))))
305 (check "direct-si:actual-eq" (eq si hit))
306 (check "direct-si:no-ii" (null (topic-item-identifiers si))))
307 ;; Retain the exact object produced by a forward reference, then deserialize
308 ;; a later declaration with the same reader operation in the same context.
309 (let* ((map (make-topic-map))
310 (old (topic-maps.xtm::find-reference-topic map (concatenate 'string *document* "#future")))
311 (other (intern-topic map :subject-identifier "urn:shared"))
312 (a (make-association map (core-topic-for-test map "type-instance")
313 (list (list (core-topic-for-test map "instance") old) (list (core-topic-for-test map "type") other))))
314 (role (find old (association-roles a) :key #'association-role-player :test #'eq)))
315 (let* ((topic-maps.xtm::*document-iri* *document*) (topic-maps.xtm::*source-key* "retained-forward")
316 (root (topic-maps.xml:parse-octets
317 (bytes (document "<topic id='future'><subjectIdentifier href='urn:shared'/></topic>"))
318 (make-instance 'topic-maps.xtm::source-handler))))
319 (topic-maps.xtm::validate-source root)
320 (topic-maps.xtm::read-topic (first (topic-maps.xtm::elements root)) map))
321 (check "retained:forward-handle-eq" (and (eq (canonical-topic old) (canonical-topic other)) (not (eq old (canonical-topic old)))))
322 (check "retained:role-player-canonical" (eq (association-role-player role) (canonical-topic old)))
323 (check "retained:role-parent-canonical" (eq (association-role-parent role) (canonical-association a)))
324 (let ((before (public-state map)) (pointer (topic-maps.tmdm::%topic-forward old)))
325 (topic-maps.cxtm:canonicalize map :base-locator *document*)
326 (check "retained:cxtm-does-not-mutate" (and (equal before (public-state map)) (eq pointer (topic-maps.tmdm::%topic-forward old))))))
327 (let ((a (read-body "<topic id='same'/>") ) (b (read-body "<topic id='same'/>" "https://other.example/map.xtm")))
328 (check "documents:distinct-object" (not (eq (first (topic-map-topics a)) (first (topic-map-topics b)))))
329 (check "documents:distinct-local-locators" (not (equal (topic-item-identifiers (first (topic-map-topics a))) (topic-item-identifiers (first (topic-map-topics b)))))))
330 (let ((map (read-body "<topic id='a'><subjectLocator href='resource'/><subjectIdentifier href='urn:subject'/><itemIdentity href='#alias'/></topic>")))
331 (check "identity:three-categories" (let ((topic (first (topic-map-topics map))))
332 (and (= 2 (length (topic-item-identifiers topic)))
333 (equal '("urn:subject") (topic-subject-identifiers topic))
334 (equal (list (concatenate 'string (subseq *document* 0 (1+ (position #\/ *document* :from-end t))) "resource")) (topic-subject-locators topic))))))
335 (let ((map (read-body "<topic id=' Ä水 '><subjectIdentifier href='http://example.org/%C3%A4/%F0%9F%A6%8A'/></topic>")))
336 (check "unicode:id-collapse" (by-id map "Ä水"))
337 (check "unicode:href-percent-utf8" (equal '("http://example.org/ä/🦊") (topic-subject-identifiers (first (topic-map-topics map))))))
338 (dolist (pair '(("../folder/./x#t" "https://example.test/folder/x#t")
339 ("#t" "https://example.test/a/map.xtm#t")
340 ("?q#t" "https://example.test/a/map.xtm?q#t")
341 ("http://EXAMPLE.test:80/a" "http://EXAMPLE.test:80/a")
342 ("http://example.test/a%20b#t" "http://example.test/a b#t")))
343 (let ((topic-maps.xtm::*document-iri* *document*) (topic-maps.xtm::*source-key* "iri-test"))
344 (check (concatenate 'string "iri:" (first pair))
345 (equal (topic-maps.xtm::resolve-iri (first pair) "https://example.test/a/map.xtm" nil) (second pair)))))
346 (let* ((source (document "<topic id='a'/><topic id='b'><instanceOf><topicRef href='#a'/></instanceOf></topic>"))
347 (one (read-body "<topic id='a'/><topic id='b'><instanceOf><topicRef href='#a'/></instanceOf></topic>"))
348 (two (read-body "<topic id='b'><instanceOf><topicRef href='#a'/></instanceOf></topic><topic id='a'/>")))
349 (check "order:canonical-independence" (equal (topic-maps.cxtm:canonicalize one :base-locator *document*) (topic-maps.cxtm:canonicalize two :base-locator *document*)))
350 (dolist (spec '((:utf-8 t "UTF-8") (:utf-16le t "UTF-16") (:utf-16be t "UTF-16")
351 (:utf-16le nil "UTF-16LE") (:utf-16be nil "UTF-16BE")))
352 (destructuring-bind (encoding bom label) spec
353 (let* ((xml (format nil "<?xml version='1.0' encoding='~A'?>~A" label source))
354 (map (deserialize-octets (bytes xml encoding bom) :document-iri *document*)))
355 (check (format nil "encoding:~A:~A" encoding bom) (equal (topic-maps.cxtm:canonicalize one :base-locator *document*) (topic-maps.cxtm:canonicalize map :base-locator *document*))))))))
356 (defun core-topic-for-test (map name)
357 (intern-topic map :subject-identifier (concatenate 'string "http://psi.topicmaps.org/iso13250/model/" name)))
358
359 (defun identity-cascade-tests ()
360 (let ((map (read-body "<topic id='a'><subjectIdentifier href='urn:one'/></topic><topic id='b'><subjectIdentifier href='urn:two'/></topic><topic id='c'><itemIdentity href='#a'/><subjectIdentifier href='urn:two'/></topic>")))
361 (check "transitive:mixed-identifiers-one-topic" (= 1 (length (topic-map-topics map))))
362 (check "transitive:three-ii-two-si" (let ((topic (first (topic-map-topics map))))
363 (and (= 3 (length (topic-item-identifiers topic))) (= 2 (length (topic-subject-identifiers topic)))))))
364 (let* ((map (read-body "<topic id='s'><subjectLocator href='#x'/></topic><topic id='a'><instanceOf><topicRef href='#x'/></instanceOf></topic>"))
365 (s (by-id map "s")) (x (by-id map "x")))
366 (check "reference:subject-locator-is-not-si-or-ii" (and s x (not (eq s x)) (= 6 (length (topic-map-topics map))))))
367 (let* ((map (make-topic-map)) (topic-maps.xtm::*document-iri* *document*)
368 (topic-maps.xtm::*source-key* "association-cascade")
369 (root (topic-maps.xml:parse-octets
370 (bytes (document "<topic id='a'><instanceOf><topicRef href='#t1'/><topicRef href='#t2'/></instanceOf></topic><topic id='t1'><itemIdentity href='#t2'/></topic>"))
371 (make-instance 'topic-maps.xtm::source-handler)))
372 (nodes (topic-maps.xtm::elements (topic-maps.xtm::validate-source root))))
373 (topic-maps.xtm::read-topic (first nodes) map)
374 (let* ((associations (topic-map-associations map))
375 (roles (loop for a in associations append (association-roles a)))
376 (old-type (by-id map "t2")))
377 (check "cascade:before-two-associations" (= 2 (length associations)))
378 (topic-maps.xtm::read-topic (second nodes) map)
379 (let ((a (first (topic-map-associations map))))
380 (check "cascade:after-one-association" (and (= 1 (length (topic-map-associations map))) (= 2 (length (association-roles a)))))
381 (check "cascade:retained-association-handles-eq" (every (lambda (old) (eq a (canonical-association old))) associations))
382 (check "cascade:retained-role-handles-eq" (every (lambda (r) (member (canonical-association-role r) (association-roles a) :test #'eq)) roles))
383 (check "cascade:stored-type-player-canonical" (every (lambda (r) (and (eq a (association-role-parent r))
384 (eq (association-role-type r) (canonical-topic (association-role-type r)))
385 (eq (association-role-player r) (canonical-topic (association-role-player r))))) (association-roles a)))
386 (check "cascade:retained-topic-handle-eq" (eq (canonical-topic old-type) (by-id map "t1")))
387 (let* ((handles (append associations roles (list old-type)))
388 (pointers (mapcar #'topic-maps.tmdm::canonical-item handles))
389 (before (public-state map)))
390 (topic-maps.cxtm:canonicalize map :base-locator *document*)
391 (check "cascade:all-handles-pure" (and (equal before (public-state map))
392 (every #'eq pointers (mapcar #'topic-maps.tmdm::canonical-item handles))))))))
393 (let* ((prefixed "<x:topicMap xmlns:x='http://www.topicmaps.org/xtm/' version='2.0'><x:topic id='a'/></x:topicMap>")
394 (source (bytes prefixed))
395 (a (deserialize-octets source :document-iri *document* :source-key "disk:a"))
396 (b (deserialize-octets source :document-iri *document* :source-key "memory:b")))
397 (check "namespace:prefix-equivalent" (by-id a "a"))
398 (check "source-key:not-topic-identity" (equal (topic-item-identifiers (by-id a "a")) (topic-item-identifiers (by-id b "a")))))
399 (let* ((map (read-body "<topic id='a'><instanceOf><topicRef href='https://external.example/map.xtm#unfetched'/></instanceOf></topic>"))
400 (type (find-if (lambda (topic) (member "https://external.example/map.xtm#unfetched" (topic-item-identifiers topic) :test #'equal)) (topic-map-topics map))))
401 (graph-checks "external-reference:no-retrieval" map (by-id map "a") type)))
402
403 (defun negative-tests ()
404 (dolist (spec '(("missing-id" "<topic/>" :missing-id)
405 ("invalid-id" "<topic id='2bad'/>" :invalid-id)
406 ("id-colon" "<topic id='a:b'/>" :invalid-id)
407 ("id-empty" "<topic id=''/>" :invalid-id)
408 ("id-spaces" "<topic id='a b'/>" :invalid-id)
409 ("duplicate-id" "<topic id='a'/><topic id=' a '/>" :duplicate-id)
410 ("unknown-attribute" "<topic id='a' other='v'/>" :unexpected-attribute)
411 ("qualified-attribute" "<topic xmlns:x='urn:x' x:id='a'/>" :unexpected-attribute)
412 ("unknown-element" "<topic id='a'><garbage/></topic>" :unexpected-element)
413 ("wrong-namespace-child" "<topic xmlns='urn:other' id='a'/>" :invalid-namespace)
414 ("topic-identity-order" "<topic id='a'><instanceOf><topicRef href='#b'/></instanceOf><itemIdentity href='#c'/></topic>" :element-order)
415 ("map-identity-order" "<topic id='a'/><itemIdentity href='#map'/>" :element-order)
416 ("instance-duplicate" "<topic id='a'><instanceOf><topicRef href='#b'/></instanceOf><instanceOf><topicRef href='#b'/></instanceOf></topic>" :duplicate-instance-of)
417 ("empty-instance" "<topic id='a'><instanceOf/></topic>" :empty-instance-of)
418 ("missing-href" "<topic id='a'><subjectIdentifier/></topic>" :missing-attribute)
419 ("nonempty-locator" "<topic id='a'><subjectIdentifier href='urn:s'><topic/></subjectIdentifier></topic>" :unexpected-child)
420 ("locator-text" "<topic id='a'><subjectIdentifier href='urn:s'>text</subjectIdentifier></topic>" :unexpected-text)
421 ("non-whitespace" "text" :unexpected-text)
422 ("no-ref-fragment" "<topic id='a'><instanceOf><topicRef href='other.xtm'/></instanceOf></topic>" :invalid-topic-ref)
423 ("bad-ref-fragment" "<topic id='a'><instanceOf><topicRef href='#2bad'/></instanceOf></topic>" :invalid-topic-ref)
424 ("empty-ref-fragment" "<topic id='a'><instanceOf><topicRef href='#'/></instanceOf></topic>" :invalid-topic-ref)
425 ("xpointer-ref" "<topic id='a'><instanceOf><topicRef href='#xpointer(a)'/></instanceOf></topic>" :invalid-topic-ref)
426 ("relative-colon" "<topic id='a'><subjectIdentifier href='1bad:subject'/></topic>" :invalid-iri)
427 ("decoded-control" "<topic id='a'><subjectIdentifier href='urn:%00'/></topic>" :invalid-iri)
428 ("bad-percent" "<topic id='a'><subjectIdentifier href='urn:%GG'/></topic>" :invalid-percent-escape)
429 ("bad-percent-utf8" "<topic id='a'><subjectIdentifier href='urn:%C3%28'/></topic>" :invalid-percent-utf8)
430 ("invalid-iri" "<topic id='a'><subjectIdentifier href='urn:a b'/></topic>" :invalid-iri)))
431 (rejection (first spec) (document (second spec)) 'xtm-rejection (third spec)))
432 (rejection "missing-version" "<topicMap xmlns='http://www.topicmaps.org/xtm/'/>" 'xtm-rejection :missing-attribute)
433 (rejection "version-21" "<topicMap xmlns='http://www.topicmaps.org/xtm/' version='2.1'/>" 'xtm-rejection :invalid-version)
434 (rejection "no-namespace" "<topicMap version='2.0'/>" 'xtm-rejection :invalid-namespace)
435 (rejection "namespace-10" "<topicMap xmlns='http://www.topicmaps.org/xtm/1.0/' version='2.0'/>" 'xtm-rejection :invalid-namespace)
436 (rejection "xml-misnested" "<a><b></a>" 'xtm-xml-error :xml-not-well-formed)
437 (rejection "xml-duplicate-attribute" "<topicMap version='2.0' version='2.0'/>" 'xtm-xml-error :xml-not-well-formed)
438 (rejection "xml-undeclared-prefix" "<x:topicMap/>" 'xtm-xml-error :xml-not-well-formed)
439 (dolist (body '("<!DOCTYPE topicMap>" "<!DOCTYPE topicMap SYSTEM 'file:///tmp/no-xtm-file'>"
440 "<!DOCTYPE topicMap SYSTEM 'http://127.0.0.1:9/no-xtm-network'>"
441 "<!DOCTYPE topicMap [<!ENTITY e SYSTEM 'file:///tmp/no-xtm-file'>]>"))
442 (rejection (concatenate 'string "doctype:" body) (concatenate 'string body (document "")) 'xtm-xml-error :doctype-forbidden))
443 (dolist (spec '(("unsupported-name-variant-resourceData-datatype" "<topic id='a'><name><value>Name</value><variant><scope><topicRef href='#s'/></scope><resourceData datatype='http://www.w3.org/2001/XMLSchema#anyType'>42</resourceData></variant></name></topic>" :resource-data-datatype)
444 ("unsupported-occurrence" "<topic id='a'><occurrence reifier='#r'><type><topicRef href='#t'/></type><resourceData>v</resourceData></occurrence></topic>" :unsupported-construct)
445 ("unsupported-association" "<association reifier='#excluded'><type><topicRef href='#t'/></type><role><type><topicRef href='#r'/></type><topicRef href='#p'/></role></association>" :unsupported-construct)
446 ("unsupported-mergemap" "<mergeMap href='other.xtm'/>" :resource-resolver-required)))
447 (rejection (first spec) (document (second spec)) 'xtm-unsupported (third spec)))
448 (rejection "unsupported-occurrence-reifier" (document "<topic id='a'><occurrence reifier='#r'><type><topicRef href='#t'/></type><resourceData>O</resourceData></occurrence></topic>") 'xtm-unsupported :unsupported-construct)
449 (let ((c (condition-from (lambda () (read-body (format nil "~%~%<topic id='2bad'/>"))))))
450 (check "diagnostic:multiline-observed-position" (and (typep c 'xtm-rejection) (= 3 (error-line c)) (plusp (error-column c)))))
451 (dolist (iri '(nil "relative.xtm" "https://example.test/a#fragment"))
452 (let ((c (condition-from (lambda () (deserialize-octets (bytes (document "")) :document-iri iri :source-key "document")))))
453 (check (format nil "document-iri:~S" iri) (and (typep c 'xtm-rejection) (eq (error-code c) :invalid-document-iri)))))
454 (check "api:raw-bytes-required" (typep (condition-from (lambda () (deserialize-octets (document "") :document-iri *document*))) 'type-error))
455 (let* ((source "<itemIdentity href='#a'/><topic id='a'/>")
456 (c (condition-from (lambda () (read-body source)))))
457 (check "tmdm:identifier-conflict-not-xml-or-xtm" (and (typep c 'item-identifier-error) (not (typep c 'topic-maps.xtm:xtm-error))))
458 (check "tmdm:identifier-conflict-specific" (eq (item-identifier-error-code c) :duplicate-item-identifier)))
459 (let ((c (condition-from (lambda () (read-body "<topic id='a'><subjectIdentifier href='http://psi.topicmaps.org/iso13250/model/type'/><subjectIdentifier href='http://psi.topicmaps.org/iso13250/model/instance'/></topic>")))))
460 (check "tmdm:core-subject-conflict-preserved" (and (typep c 'core-subject-error) (eq :core-subject-conflict (core-subject-error-code c)))))
461 (dolist (bad '(#(195 40) #(192 175) #(226 130) #(237 160 128)))
462 (let ((c (condition-from (lambda () (deserialize-octets
463 (concatenate '(vector (unsigned-byte 8)) (bytes "<topicMap xmlns='http://www.topicmaps.org/xtm/' version='2.0'><topic id='a'><subjectIdentifier href='urn:")
464 (coerce bad '(vector (unsigned-byte 8))) (bytes "'/></topic></topicMap>")) :document-iri *document*)))))
465 (check (format nil "actual-reader:invalid-utf8:~S" bad) (and (typep c 'xtm-xml-error) (eq :xml-not-well-formed (error-code c))))))
466 ;; Astral Unicode in an href exercises the qualified UTF-16 decoder through
467 ;; the real XTM reader. No pre-decoding strings are accepted by its API.
468 (dolist (encoding '(:utf-16le :utf-16be))
469 (let ((map (deserialize-octets (bytes (document "<topic id='a'><subjectIdentifier href='urn:🦊'/></topic>") encoding t) :document-iri *document*)))
470 (check (format nil "actual-reader:astral-surrogate:~A" encoding) (by-si map "urn:🦊"))))
471 (dolist (bad '(#(0 216) #(0 220) #(0 216 65 0)))
472 (let ((c (condition-from (lambda ()
473 (deserialize-octets (concatenate '(vector (unsigned-byte 8))
474 (bytes "<r>" :utf-16le t) (coerce bad '(vector (unsigned-byte 8))) (bytes "</r>" :utf-16le)) :document-iri *document*)))))
475 (check (format nil "actual-reader:invalid-surrogate:~S" bad) (typep c 'xtm-xml-error))))
476 ;; Verify the required entry point is actually called exactly once and sees
477 ;; the original octet vector by EQ, not a reconstructed decoded XML string.
478 (let* ((original (symbol-function 'topic-maps.xml:parse-octets))
479 (source (bytes (document "<topic id='a'/>"))) (calls 0) (same nil))
480 (unwind-protect
481 (progn (setf (symbol-function 'topic-maps.xml:parse-octets)
482 (lambda (bytes handler) (incf calls) (setf same (eq source bytes)) (funcall original bytes handler)))
483 (deserialize-octets source :document-iri *document*)
484 (check "boundary:real-parse-octets-only-once" (and (= 1 calls) same)))
485 (setf (symbol-function 'topic-maps.xml:parse-octets) original))))
486
487 (defun helper-source-test ()
488 (let* ((id "ctm/in/mergemap-xtm.sub")
489 (iri (concatenate 'string "https://xtm-tests.example.invalid/cd165b150176c1d6842b37be9cc9051b40d4996b/" id))
490 (*document* iri) (map (deserialize-octets (file-bytes (corpus-path id)) :document-iri iri :source-key id)))
491 (graph-checks "direct-sub" map (by-id map "lars") (by-id map "person"))
492 (check "direct-sub:exact-lars-ii" (equal (list (concatenate 'string iri "#lars")) (topic-item-identifiers (by-id map "lars"))))
493 (check "direct-sub:exact-person-ii" (equal (list (concatenate 'string iri "#person")) (topic-item-identifiers (by-id map "person"))))
494 (check "direct-sub:no-names-occurrences" (every (lambda (topic) (and (null (topic-names topic)) (null (topic-occurrences topic)))) (topic-map-topics map)))
495 (setf *fixture* map)))
496
497 (defun run-tests ()
498 (setf *association-outputs* nil *association-controls* nil *registered-mergemap-outputs* nil *occurrence-outputs* nil *occurrence-controls* nil *mergemap-controls* nil *mergemap-originals* nil *datatype-outputs* nil *datatype-controls* nil *checks* nil *fixture* nil *negative-outputs* nil *negative-controls* nil *name-outputs* nil *name-controls* nil *scope-outputs* nil *scope-controls* nil *iid-outputs* nil *iid-controls* nil *variant-outputs* nil *variant-negative-outputs* nil *variant-controls* nil *variant-merge-outputs* nil *resource-ref-outputs* nil *resource-ref-controls* nil *uri-data-outputs* nil *uri-data-controls* nil *variant-iid-outputs* nil *variant-iid-controls* nil *map-reifier-outputs* nil *map-reifier-controls* nil *name-reifier-outputs* nil *name-reifier-controls* nil *name-followup-outputs* nil *variant-reifier-outputs* nil *variant-reifier-controls* nil)
499 (handler-case
500 (progn (original-contracts) (negative-original-controls) (negative-original-contracts)
501 (name-original-contracts) (name-tests) (scope-original-contracts) (scope-tests) (iid-original-contracts) (iid-tests) (variant-original-contracts) (variant-negative-original) (variant-tests) (variant-merge-original-contract) (resource-ref-original-contracts) (resource-ref-tests) (uri-data-original-contract) (uri-data-tests) (variant-iid-original-contracts) (variant-iid-tests) (map-reifier-original-contract) (map-reifier-tests) (name-reifier-original-contracts) (name-reifier-tests) (name-reifier-followup-original-contracts) (variant-reifier-original-contracts) (variant-reifier-tests) (variant-reifier-followup-original-contract) (datatype-original-contract) (datatype-tests) (mergemap-tests) (occurrence-original-contracts) (occurrence-tests) (registered-mergemap-original-contracts) (association-original-contracts) (association-tests) (result-classification-tests)
502 (semantic-tests) (identity-cascade-tests) (negative-tests) (helper-source-test))
503 (error (condition)
504 ;; Preserve the actual failed outcome before ASDF propagates the failure.
505 (let ((report (uiop:getenv "TOPIC_MAPS_XTM_REPORT")))
506 (when report (write-report report)))
507 (error condition)))
508 (check "checks:unique-test-names" (= (length *checks*) (length (remove-duplicates *checks* :test #'equal))))
509 (format t "XTM-SUMMARY ~D PASS 0 FAIL; ~D original CXTM PASS; ~D negative originals PASS; helper source PASS~%"
510 (length *checks*) (count :valid *cases* :key #'topic-maps.test-foundation:test-case-category)
511 (count :invalid *cases* :key #'topic-maps.test-foundation:test-case-category))
512 (length *checks*))
513
514 (defun write-report (pathname)
515 (let ((cases *cases*) (fixture *fixture*))
516 (flet ((fields (&rest args) (apply #'topic-maps.test-foundation::fields args))
517 (array (items) (coerce items 'vector)))
518 (with-open-file (out pathname :direction :output :if-exists :supersede :external-format :utf-8)
519 (topic-maps.test-foundation::emit-json-value
520 (fields "scope" "XTM 2.0 identity/Name/Scope/Item-Identity/Variant/Reification and Occurrence/MergeMap/Association/Role subset; actual original outcomes are recorded in cases; no CTM Mergemap integration"
521 "corpusCommit" "cd165b150176c1d6842b37be9cc9051b40d4996b"
522 "statuses" (fields "pass" (count :pass cases :key #'topic-maps.test-foundation:test-case-status)
523 "fail" (count :fail cases :key #'topic-maps.test-foundation:test-case-status)
524 "unsupported" (count :unsupported cases :key #'topic-maps.test-foundation:test-case-status)
525 "not-run" (count :not-run cases :key #'topic-maps.test-foundation:test-case-status))
526 "otherCorpusInputs" (fields "positiveUnexecuted" (- (length (directory (corpus-path "xtm2/in/*.xtm"))) (count :valid cases :key #'topic-maps.test-foundation:test-case-category))
527 "negativeUnregisteredUnexecuted" (- (length (directory (corpus-path "xtm2/invalid/*.xtm")))
528 (count :invalid cases :key #'topic-maps.test-foundation:test-case-category)))
529 "checks" (array (reverse *checks*))
530 "cases" (array (loop for case in cases collect
531 (fields "id" (topic-maps.test-foundation:test-case-id case)
532 "documentIRI" (topic-maps.test-foundation:test-case-document-iri case)
533 "status" (string-downcase (symbol-name (topic-maps.test-foundation:test-case-status case)))
534 "actualOutcome" (string-downcase (symbol-name (topic-maps.test-foundation:test-case-actual-outcome case)))
535 "diagnostics" (array (topic-maps.test-foundation:test-case-diagnostics case)))))
536 "helperSource" (fields "id" "ctm/in/mergemap-xtm.sub" "status" (if fixture "pass" "not-run") "topics" (when fixture (length (topic-map-topics fixture)))
537 "associations" (when fixture (length (topic-map-associations fixture))) "roles" 2
538 "ctmMergemapContract" "NOT-RUN; direct helper deserialization only")
539 "negativeOriginals" (array *negative-outputs*)
540 "negativeControls" (array *negative-controls*)
541 "nameOriginals" (array *name-outputs*)
542 "nameControls" (array *name-controls*)
543 "scopeOriginals" (array *scope-outputs*)
544 "scopeControls" (array *scope-controls*)
545 "nameItemIdentityOriginals" (array *iid-outputs*)
546 "nameItemIdentityControls" (array *iid-controls*)
547 "variantOriginals" (array *variant-outputs*)
548 "variantNegativeOriginals" (array *variant-negative-outputs*)
549 "variantControls" (array *variant-controls*)
550 "variantMergeOriginals" (array *variant-merge-outputs*)
551 "variantResourceRefOriginals" (array *resource-ref-outputs*)
552 "variantResourceRefControls" (array *resource-ref-controls*)
553 "variantResourceDataURIOriginals" (array *uri-data-outputs*)
554 "variantResourceDataURIControls" (array *uri-data-controls*)
555 "variantItemIdentityOriginals" (array *variant-iid-outputs*)
556 "variantItemIdentityControls" (array *variant-iid-controls*)
557 "mapReifierOriginals" (array *map-reifier-outputs*)
558 "mapReifierControls" (array (reverse *map-reifier-controls*))
559 "nameReifierOriginals" (array *name-reifier-outputs*)
560 "nameReifierControls" (array (reverse *name-reifier-controls*))
561 "nameFollowupOriginals" (array *name-followup-outputs*)
562 "variantReifierOriginals" (array *variant-reifier-outputs*)
563 "variantReifierControls" (array (reverse *variant-reifier-controls*))
564 "datatypeOriginals" (array *datatype-outputs*)
565 "datatypeControls" (array *datatype-controls*)
566 "mergemapControls" (array *mergemap-controls*)
567 "mergemapOriginalObservations" (array *mergemap-originals*)
568 "occurrenceOriginals" (array *occurrence-outputs*)
569 "occurrenceControls" (array *occurrence-controls*)
570 "associationOriginals" (array *association-outputs*)
571 "associationControls" (array *association-controls*)
572 "registeredMergemapOriginals" (array *registered-mergemap-outputs*)
573 "actualAndExpected" (array (loop for (id actual expected model condition source-length) in *outputs* collect
574 (fields "id" id "actual" (when actual (babel:octets-to-string actual :encoding :utf-8))
575 "expected" (babel:octets-to-string expected :encoding :utf-8) "byteLength" (when actual (length actual))
576 "expectedByteLength" (length expected) "sourceByteLength" source-length
577 "firstDifferentByte" (when actual (mismatch actual expected))
578 "model" model "condition" condition)))) out)
579 (terpri out)))))