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