]> dreyeck.freedombox.rocks Git - topic-maps.git/blob - tests/ctm-occurrences.lisp
Qualify pinned CXML encodings with reproducible local patches
[topic-maps.git] / tests / ctm-occurrences.lisp
1 (in-package #:topic-maps.ctm.tests)
2
3 (defparameter *occurrence-ids*
4 '("occurrence-string" "occurrence-string2" "occurrence-uri-relative" "occurrence-two"))
5 (defvar *last-occurrence-checks* nil)
6 (defvar *occurrence-observations* nil)
7 (defun occurrence-checks () *last-occurrence-checks*)
8 (defun all-occurrences (map) (mapcan #'topic-maps.tmdm:topic-occurrences (topic-map-topics map)))
9 (defun occurrence-handle-state (items)
10 (loop for o in items collect
11 (list o (topic-maps.tmdm::%occurrence-forward o) (topic-maps.tmdm::%occurrence-parent o)
12 (topic-maps.tmdm::%occurrence-type o) (topic-maps.tmdm::%occurrence-value o)
13 (topic-maps.tmdm::%occurrence-datatype o) (copy-list (topic-maps.tmdm::%occurrence-item-identifiers o)))))
14 (defun local-topic (map id &optional (doc "https://example.invalid/a/doc.ctm"))
15 (find-if (lambda (topic) (member (concatenate 'string doc "#" id) (topic-item-identifiers topic) :test #'string=))
16 (topic-map-topics map)))
17 (defun occurrence-condition (thunk)
18 (handler-case (progn (funcall thunk) nil) (topic-maps.tmdm:occurrence-error (c) c)))
19 (defun ctm-condition (text)
20 (handler-case (progn (read-text text) nil) (ctm-error (c) c)))
21
22 (defun occurrence-observation (map)
23 (let ((topics (topic-map-topics map)))
24 (topic-maps.test-foundation::fields
25 "topicCount" (length topics) "occurrenceCount" (length (all-occurrences map))
26 "nameCount" (reduce #'+ topics :key (lambda (x) (length (topic-names x))) :initial-value 0)
27 "associationCount" (length (topic-maps.tmdm:topic-map-associations map))
28 "topics" (topic-maps.test-foundation::json-array
29 (loop for topic in topics for ordinal from 1 collect
30 (topic-maps.test-foundation::fields
31 "ordinal" ordinal "itemIdentifiers" (topic-maps.test-foundation::json-array (topic-item-identifiers topic))
32 "subjectIdentifiers" (topic-maps.test-foundation::json-array (topic-subject-identifiers topic))
33 "subjectLocators" (topic-maps.test-foundation::json-array (topic-subject-locators topic))
34 "occurrences" (topic-maps.test-foundation::json-array
35 (loop for o in (topic-maps.tmdm:topic-occurrences topic) collect
36 (topic-maps.test-foundation::fields
37 "value" (topic-maps.tmdm:occurrence-value o) "datatype" (topic-maps.tmdm:occurrence-datatype o)
38 "parentTopicOrdinal" (1+ (position (topic-maps.tmdm:occurrence-parent o) topics :test #'eq))
39 "typeTopicOrdinal" (1+ (position (topic-maps.tmdm:occurrence-type o) topics :test #'eq))
40 "itemIdentifiers" (topic-maps.test-foundation::json-array (topic-maps.tmdm:occurrence-item-identifiers o)))))))))))
41
42 (defun exercise-occurrence-cases ()
43 (setf *occurrence-observations* nil)
44 (dolist (name *occurrence-ids*)
45 (let* ((id (format nil "ctm/in/~A.ctm" name))
46 (case (first (topic-maps.test-foundation:select-cases *cxtm-corpus* :id id)))
47 (doc (topic-maps.test-foundation:test-case-document-iri case))
48 (map (deserialize-file (topic-maps.test-foundation:test-case-source-pathname case) :document-iri doc :source-name id))
49 (two (string= name "occurrence-two"))
50 (owner (local-topic map (if two "tmcl-schema" "topic") doc))
51 (items (topic-maps.tmdm:topic-occurrences owner)))
52 (setf (topic-maps.test-foundation:test-case-clauses case)
53 '("CTM 3.2" "CTM 3.3.3" "CTM 3.3.5-3.3.7" "CTM 3.3.11" "CTM 3.4.1-3.4.2" "CTM 3.8-3.10"
54 "TMDM 4.3" "TMDM 5.1" "TMDM 5.3" "TMDM 5.6" "TMDM 6.2" "TMDM 6.5"
55 "CXTM 3.5" "CXTM 3.8" "CXTM 3.13-3.23" "CXTM 4.2-4.6" "CXTM 4.9"))
56 (check (concatenate 'string name ":topic-count") (= (if two 3 2) (length (topic-map-topics map))))
57 (check (concatenate 'string name ":occurrence-count") (= (if two 2 1) (length items)))
58 (check (concatenate 'string name ":no-extra-items")
59 (and (= (length items) (length (all-occurrences map))) (notany #'topic-names (topic-map-topics map))
60 (null (topic-maps.tmdm:topic-map-associations map))))
61 (check (concatenate 'string name ":topic-identifiers")
62 (every (lambda (tpc) (and (= 1 (length (topic-item-identifiers tpc)))
63 (null (topic-subject-identifiers tpc)) (null (topic-subject-locators tpc))))
64 (topic-map-topics map)))
65 (check (concatenate 'string name ":parents-and-empty-identifiers")
66 (every (lambda (o) (and (eq owner (topic-maps.tmdm::%occurrence-parent o))
67 (eq o (topic-maps.tmdm:canonical-occurrence o))
68 (null (topic-maps.tmdm:occurrence-item-identifiers o)))) items))
69 (loop for o in items for index from 1 do
70 (let* ((iri (or (string= name "occurrence-uri-relative") (and two (= index 2))))
71 (type (local-topic map (if two (if iri "see-also" "description") "occtype") doc))
72 (value (cond ((string= name "occurrence-uri-relative")
73 (concatenate 'string (subseq doc 0 (1+ (position #\/ doc :from-end t))) "file.html"))
74 ((and two iri) "http://www.isotopicmaps.org/tmcl/tmcl.html")
75 (two (format nil "A meta-schema for TMCL, describing the allowed structure~% of TMCL schemas."))
76 (t "Occurrence"))))
77 (check (format nil "~A:type-reference:~D" name index) (eq type (topic-maps.tmdm::%occurrence-type o)))
78 (check (format nil "~A:value-and-datatype:~D" name index)
79 (and (string= value (topic-maps.tmdm:occurrence-value o))
80 (string= (if iri (topic-maps.tmdm:iri-datatype) (topic-maps.tmdm:string-datatype))
81 (topic-maps.tmdm:occurrence-datatype o))))))
82 (let* ((state (map-state map)) (actual (topic-maps.cxtm:canonicalize-octets map :base-locator doc))
83 (expected (binary-file (topic-maps.test-foundation:test-case-expected-baseline case)))
84 (different (mismatch actual expected)))
85 (topic-maps.test-foundation:record-result case (if different :cxtm-mismatch :cxtm-match)
86 :diagnostics (when different (list (format nil "First mismatch byte ~D: actual ~D bytes, expected ~D bytes."
87 different (length actual) (length expected)))))
88 (check (concatenate 'string name ":byte-equal-cxtm") (null different))
89 (check (concatenate 'string name ":canonicalization-pure") (equal state (map-state map)))
90 (setf *cxtm-results* (append *cxtm-results*
91 (list (list :id id :base doc :actual (cxtm map doc) :expected (uiop:read-file-string
92 (topic-maps.test-foundation:test-case-expected-baseline case) :external-format :utf-8)
93 :match (null different) :bytes (length actual))))))
94 (push (topic-maps.test-foundation::fields "id" id "documentIRI" doc "status" "pass"
95 "ctmSource" (uiop:read-file-string (topic-maps.test-foundation:test-case-source-pathname case) :external-format :utf-8)
96 "actualObjects" (occurrence-observation map)) *occurrence-observations*)
97 (format t "~&OCCURRENCE-CXTM ~A: PASS~%" id)))
98 (setf *occurrence-observations* (nreverse *occurrence-observations*))
99 (check "29-imported-passes-244-unexecuted"
100 (equal (getf (topic-maps.test-foundation:summarize-corpus *cxtm-corpus*) :statuses)
101 '(:pass 29 :fail 0 :unsupported 0 :not-run 244))))
102
103 (defun occurrence-semantic-tests ()
104 (let* ((map (read-text "a r:\"http://example.org/resource\"; s: <http://example.org/resource>."))
105 (items (all-occurrences map)) (a (local-topic map "a")))
106 (check "uri-looking-string-remains-string" (string= (topic-maps.tmdm:occurrence-datatype (first items)) (topic-maps.tmdm:string-datatype)))
107 (check "iri-literal-is-locator" (string= (topic-maps.tmdm:occurrence-datatype (second items)) (topic-maps.tmdm:iri-datatype)))
108 (check "datatype-locator-is-not-a-topic" (every (lambda (o) (stringp (topic-maps.tmdm:occurrence-datatype o))) items))
109 (check "uri-value-is-not-subject-identity" (and (= 3 (length (topic-map-topics map))) (every #'null (mapcar #'topic-subject-identifiers (topic-map-topics map)))))
110 (check "public-parent-and-type-identity" (and (every (lambda (o) (eq a (topic-maps.tmdm:occurrence-parent o))) items)
111 (eq (local-topic map "r") (topic-maps.tmdm:occurrence-type (first items))))))
112 (let ((map (read-text "a r:\"file.html\"; s: <file.html>.")))
113 (check "quoted-relative-content-not-resolved" (string= "file.html" (topic-maps.tmdm:occurrence-value (first (all-occurrences map)))))
114 (check "iri-content-resolved-once" (string= "https://example.invalid/a/file.html" (topic-maps.tmdm:occurrence-value (second (all-occurrences map))))))
115 (let ((map (read-text "a <urn:type>: \"\\n\\t\\u00C4\"; - \"Name\";. relation(role: a)")))
116 (check "iri-type-is-subject-identified-topic" (equal '("urn:type") (topic-subject-identifiers (topic-maps.tmdm:occurrence-type (first (all-occurrences map))))))
117 (check "string-escapes-preserved" (string= (format nil "~%~CÄ" #\Tab) (topic-maps.tmdm:occurrence-value (first (all-occurrences map)))))
118 (check "name-occurrence-roleplayed-child-order"
119 (< (search "<name number=" (cxtm map)) (search "<occurrence number=" (cxtm map)) (search "<rolePlayed " (cxtm map)))))
120 (let* ((map (read-text "a r:\"https://example.invalid/a/doc.ctm#z\"; s:<#z>.")) (out (cxtm map)))
121 (check "string-url-not-locator-normalized" (search "<value>https://example.invalid/a/doc.ctm#z</value>" out))
122 (check "uri-url-locator-normalized" (search "<value>#z</value>" out)))
123 (dolist (text '("a ^<urn:type>: \"x\"." "a =<urn:type>: \"x\"."))
124 (check (concatenate 'string "occurrence-type-topic-reference:" text) (= 2 (length (topic-map-topics (read-text text))))))
125 (dolist (entry '(("a t: ." ctm-rejection :expected-occurrence-value 5)
126 ("a t:" ctm-rejection :expected-occurrence-value 4)
127 ("a t: ;." ctm-rejection :expected-occurrence-value 5)
128 ("a t \"x\"." ctm-rejection :expected-occurrence-type-separator 4)
129 ("a t:\"x\" r:\"y\"." ctm-rejection :expected-separator 8)
130 ("a t: 2000-12-31T12:00:60+01:00." ctm-unsupported :datetime-leap-second-context 5)
131 ("a t:*." ctm-unsupported :occurrence-literal-datatype 4)
132 ("a t: 42x." ctm-rejection :invalid-occurrence-literal 5)
133 ("a t:\"x\"^^datatype." ctm-rejection :expected-datatype-iri 9)
134 ("a t:\"x\"^<urn:d>." ctm-rejection :invalid-datatype-marker 7)
135 ("a ex:t: \"x\"." undefined-prefix :undefined-prefix 2)
136 ("a t: ex:v." undefined-prefix :undefined-prefix 5)
137 ("a t:\"x\"^^xsd:string." undefined-prefix :undefined-prefix 9)))
138 (destructuring-bind (text class code position) entry
139 (let ((condition (ctm-condition text)))
140 (check (concatenate 'string "occurrence-diagnostic:" text)
141 (and (typep condition class) (eq code (error-code condition))
142 (= position (error-position condition)) (= 1 (error-line condition))
143 (= (1+ position) (error-column condition)))))))
144 (check "explicit-string-datatype-now-supported"
145 (string= (topic-maps.tmdm:string-datatype)
146 (topic-maps.tmdm:occurrence-datatype
147 (first (all-occurrences (read-text "a t:\"x\"^^<http://www.w3.org/2001/XMLSchema#string>."))))))
148 (check "scoped-occurrence-now-deserialized"
149 (= 1 (length (topic-maps.tmdm:occurrence-scope
150 (first (all-occurrences (read-text "a t:\"x\" @theme.")))))))
151 (dolist (text '("a t:\"x\" ~reifier." "a t: 2000-12-31T12:00:60+01:00." "a t: 2000-12-31T12:00:60-01:00." "a t:* ."))
152 (check (concatenate 'string "occurrence-feature-boundary:" text) (if (find #\~ text) (null (ctm-condition text)) (typep (ctm-condition text) 'ctm-unsupported)))))
153
154 (defun occurrence-api-tests ()
155 (let* ((map (read-text "a. t.")) (a (local-topic map "a")) (type (local-topic map "t"))
156 (first (topic-maps.tmdm:add-occurrence a type "Same" :item-identifiers '("urn:o:1")))
157 (second (topic-maps.tmdm:add-occurrence a type "Same" :item-identifiers '("urn:o:2" "urn:o:1")))
158 (third (topic-maps.tmdm:add-occurrence a type "Same" :item-identifiers '("urn:o:3"))))
159 (check "duplicate-occurrence-replaced" (and (not (eq first second)) (not (eq second third)) (= 1 (length (all-occurrences map)))))
160 (check "occurrence-canonical-handle-chain" (and (eq third (topic-maps.tmdm:canonical-occurrence first)) (eq third (topic-maps.tmdm:canonical-occurrence second))))
161 (check "occurrence-identifiers-union" (equal '("urn:o:1" "urn:o:2" "urn:o:3") (sort (topic-maps.tmdm:occurrence-item-identifiers first) #'string<)))
162 (let ((items (list first second third)) (state (map-state map)))
163 (let ((handles (occurrence-handle-state items)))
164 (check "occurrence-identifier-cxtm-serialization" (search "<locator>urn:o:3</locator>" (cxtm map)))
165 (check "retained-occurrence-handles-not-mutated" (equal handles (occurrence-handle-state items)))
166 (check "occurrence-map-not-mutated" (equal state (map-state map)))))
167 (let ((set (topic-maps.tmdm:topic-occurrences a)) (ids (topic-maps.tmdm:occurrence-item-identifiers first)))
168 (setf (first set) nil (first ids) "corrupted")
169 (check "occurrence-set-readers-return-copies" (and (eq third (first (topic-maps.tmdm:topic-occurrences a)))
170 (not (member "corrupted" (topic-maps.tmdm:occurrence-item-identifiers first) :test #'string=)))))
171 (let ((state (map-state map)))
172 (loop for fixture in (list (list :foreign-type (lambda () (topic-maps.tmdm:add-occurrence a (first-topic (read-text "other.")) "x")))
173 (list :invalid-datatype (lambda () (topic-maps.tmdm:add-occurrence a type "42" :datatype "relative-datatype")))
174 (list :relative-uri-value (lambda () (topic-maps.tmdm:add-occurrence a type "file.html" :datatype (topic-maps.tmdm:iri-datatype))))
175 (list :duplicate-item-identifier (lambda () (topic-maps.tmdm:add-occurrence a type "Different" :item-identifiers '("urn:o:1"))))
176 (list :duplicate-item-identifier (lambda () (topic-maps.tmdm:intern-topic map :item-identifier "urn:o:1")))
177 (list :duplicate-item-identifier (lambda () (topic-maps.tmdm:add-topic-identifier a :item-identifier "urn:o:1")))) for fixture-index from 0 do
178 (check (format nil "invalid-occurrence-api:~A:~D" (first fixture) fixture-index)
179 (eq (first fixture) (topic-maps.tmdm:occurrence-error-code (occurrence-condition (second fixture)))))
180 (check (format nil "invalid-occurrence-api-atomic:~A:~D" (first fixture) (length *checks*)) (equal state (map-state map))))))
181 (let* ((map (read-text "a. t.")) (a (local-topic map "a")) (type (local-topic map "t"))
182 (o (topic-maps.tmdm:add-occurrence a type "x" :item-identifiers '("urn:overlap")))
183 (subject (topic-maps.tmdm:intern-topic map :subject-identifier "urn:overlap")))
184 (check "occurrence-SI-II-overlap-does-not-reify" (and (null (topic-maps.tmdm:item-reifier o))
185 (null (topic-maps.tmdm:topic-reified subject))))
186 (check "occurrence-SI-II-overlap-preserves-distinct-properties"
187 (and (equal '("urn:overlap") (topic-maps.tmdm:occurrence-item-identifiers o))
188 (equal '("urn:overlap") (topic-subject-identifiers subject)) (null (topic-item-identifiers subject)))))
189 (let* ((map (read-text "a. t.")) (a (local-topic map "a")) (type (local-topic map "t")))
190 (topic-maps.tmdm:add-occurrence a type "urn:same")
191 (topic-maps.tmdm:add-occurrence a type "urn:same" :datatype (topic-maps.tmdm:iri-datatype))
192 (check "same-lexical-value-distinct-datatype" (= 2 (length (all-occurrences map))))))
193
194 (defun occurrence-order-tests ()
195 (let ((reference nil))
196 (dolist (order (permutations '("p" "r" "s")))
197 (dolist (occ-order (permutations '(0 1 2 3)))
198 (let ((map (topic-maps.tmdm:make-topic-map)) (topics (make-hash-table :test #'equal)))
199 (dolist (id order) (setf (gethash id topics) (api-topic map (concatenate 'string "urn:" id))))
200 (dolist (i occ-order)
201 (topic-maps.tmdm:add-occurrence (gethash "p" topics) (gethash (if (member i '(1 3)) "s" "r") topics)
202 (case i ((0 1) "Same") (2 "Zulu") (3 "urn:a"))
203 :datatype (if (= i 3) (topic-maps.tmdm:iri-datatype) (topic-maps.tmdm:string-datatype))))
204 (let ((state (map-state map)) (out (cxtm map)))
205 (unless reference (setf reference out))
206 (check (format nil "occurrence-construction:~{~A~}:~{~D~}" order occ-order) (string= reference out))
207 (check (format nil "occurrence-construction-purity:~{~A~}:~{~D~}" order occ-order) (equal state (map-state map)))))))
208 (check "occurrences-numbered-by-value-then-type"
209 (search (format nil "<occurrence number=\"1\">~%<value>Same</value>~%<datatype>http://www.w3.org/2001/XMLSchema#string</datatype>~%<type topicref=\"2\"></type>") reference))
210 (check "string-values-sort-before-locator-values"
211 (< (search "<value>Zulu</value>" reference) (search "<value>urn:a</value>" reference))))
212 (let* ((map (read-text "a t:<#z>; t:<http://outside.invalid/a>.")) (state (map-state map)) (out (cxtm map)))
213 (check "anyuri-value-normalized-for-order-and-output" (< (search "<value>#z</value>" out) (search "<value>http://outside.invalid/a</value>" out)))
214 (check "uri-value-remains-absolute-in-model" (and (equal state (map-state map))
215 (find "https://example.invalid/a/doc.ctm#z" (all-occurrences map) :key #'topic-maps.tmdm:occurrence-value :test #'string=))))
216 (let* ((map (read-text "a t:\"x\".")) (out (cxtm map "http://www.w3.org/2001/XMLSchema")))
217 (check "datatype-output-not-base-normalized" (search "<datatype>http://www.w3.org/2001/XMLSchema#string</datatype>" out))))
218
219 (defun occurrence-graph-tests ()
220 (let ((possible '((0 1) (0 2) (0 3) (1 2) (1 3) (2 3))))
221 (dotimes (mask 64)
222 (let* ((edges (loop for e in possible for bit from 0 when (logbitp bit mask) collect e))
223 (components (graph-components '(0 1 2 3) edges)) (reference nil))
224 (dolist (reverse '(nil t))
225 (let* ((map (topic-maps.tmdm:make-topic-map))
226 (topics (loop for i below 4 collect (api-topic map (format nil "urn:occ-node:~D" i))))
227 (handles (list (topic-maps.tmdm:add-occurrence (first topics) (third topics) "Same")
228 (topic-maps.tmdm:add-occurrence (second topics) (fourth topics) "Same")
229 (topic-maps.tmdm:add-occurrence (first topics) (fourth topics) "urn:v" :datatype (topic-maps.tmdm:iri-datatype))
230 (topic-maps.tmdm:add-occurrence (second topics) (third topics) "urn:v")))
231 (label (format nil "occurrence-graph:~D:~A:" mask reverse)))
232 (dolist (e (if reverse (reverse edges) edges))
233 (dolist (node e) (topic-maps.tmdm:add-topic-identifier (nth node topics) :subject-identifier (format nil "urn:occ-edge:~D:~D" (first e) (second e)))))
234 (labels ((root (node)
235 (topic-maps.tmdm:canonical-topic (nth (apply #'min (find-if (lambda (c) (member node c)) components)) topics))))
236 (let ((expected-parents (list (root 0) (root 1) (root 0) (root 1)))
237 (expected-types (list (root 2) (root 3) (root 3) (root 2))))
238 (check (concatenate 'string label "stored-parent-references")
239 (every (lambda (o p) (eq p (topic-maps.tmdm::%occurrence-parent (topic-maps.tmdm:canonical-occurrence o)))) handles expected-parents))
240 (check (concatenate 'string label "stored-type-references")
241 (every (lambda (o typ) (eq typ (topic-maps.tmdm::%occurrence-type (topic-maps.tmdm:canonical-occurrence o)))) handles expected-types))
242 (check (concatenate 'string label "duplicate-count") (= (if (and (eq (root 0) (root 1)) (eq (root 2) (root 3))) 3 4) (length (all-occurrences map))))
243 (check (concatenate 'string label "canonical-handles-live")
244 (every (lambda (o) (member (topic-maps.tmdm:canonical-occurrence o) (all-occurrences map) :test #'eq)) handles))))
245 (let ((state (map-state map)) (retained (occurrence-handle-state handles)) (out (cxtm map)))
246 (if reference (check (concatenate 'string label "merge-order-independent") (string= reference out)) (setf reference out))
247 (check (concatenate 'string label "canonicalization-pure") (and (equal state (map-state map)) (equal retained (occurrence-handle-state handles)))))))))))
248
249 (defun occurrence-late-merge-and-error-tests ()
250 (let* ((map (read-text "a. b. r. s.")) (a (local-topic map "a")) (b (local-topic map "b"))
251 (r (local-topic map "r")) (s (local-topic map "s"))
252 (o1 (topic-maps.tmdm:add-occurrence a r "Same" :item-identifiers '("urn:late:1")))
253 (o2 (topic-maps.tmdm:add-occurrence b s "Same" :item-identifiers '("urn:late:2"))))
254 (topic-maps.tmdm:merge-topics a b)
255 (check "parent-merge-alone-preserves-distinct-types" (= 2 (length (all-occurrences map))))
256 (topic-maps.tmdm:merge-topics r s)
257 (check "late-type-merge-removes-duplicate" (= 1 (length (all-occurrences map))))
258 (check "late-merge-canonical-occurrence-aliases" (eq (topic-maps.tmdm:canonical-occurrence o1) (topic-maps.tmdm:canonical-occurrence o2)))
259 (check "late-merge-identifiers-union" (equal '("urn:late:1" "urn:late:2") (sort (topic-maps.tmdm:occurrence-item-identifiers o1) #'string<)))
260 (check "late-merge-parent-type-raw-canonical"
261 (let ((current (topic-maps.tmdm:canonical-occurrence o1)))
262 (and (eq (topic-maps.tmdm::%occurrence-parent current) (topic-maps.tmdm:canonical-topic a))
263 (eq (topic-maps.tmdm::%occurrence-type current) (topic-maps.tmdm:canonical-topic r)))))
264 (let ((state (map-state map)) (retained (occurrence-handle-state (list o1 o2))))
265 (cxtm map)
266 (check "late-merge-canonicalization-purity" (and (equal state (map-state map)) (equal retained (occurrence-handle-state (list o1 o2)))))))
267 (let* ((map (read-text "a. t.")) (a (local-topic map "a")) (type (local-topic map "t"))
268 (value (concatenate 'string "<&>" (map 'string #'code-char '(101 769 #x1f600)) (string #\Return)))
269 (o (topic-maps.tmdm:add-occurrence a type value)) (state (map-state map)) (out (cxtm map)))
270 (check "occurrence-nfc-escaping-and-utf8" (search (concatenate 'string "<value>&lt;&amp;&gt;" (string (code-char 233)) (string (code-char #x1f600)) "&#xD;</value>") out))
271 (check "occurrence-lexical-string-not-rewritten-by-nfc"
272 (and (string= value (topic-maps.tmdm:occurrence-value o)) (equal state (map-state map)))))
273 (let* ((map (read-text "a. t.")) (a (local-topic map "a")) (type (local-topic map "t"))
274 (bad (topic-maps.tmdm::%make-occurrence "42" "http://www.w3.org/2001/XMLSchema#dateTime" type a)))
275 ;; Private fixture verifies the canonicalizer independently of the reader.
276 (setf (topic-maps.tmdm::%topic-occurrences a) (list bad))
277 (let ((state (map-state map)) (condition (cxtm-condition (lambda () (cxtm map)))))
278 (check "invalid-datetime-not-silently-serialized"
279 (and (typep condition 'topic-maps.cxtm:cxtm-error) (not (typep condition 'topic-maps.cxtm:cxtm-unsupported))
280 (eq :invalid-datetime-value (topic-maps.cxtm:error-code condition))))
281 (check "unsupported-occurrence-canonicalization-is-pure" (equal state (map-state map))))))
282
283 (defun run-occurrence-tests ()
284 ;; Run the retained CXTM suite once, creating fresh case records for this run.
285 (run-cxtm-tests)
286 (let ((*checks* nil))
287 (exercise-occurrence-cases) (occurrence-semantic-tests) (occurrence-api-tests)
288 (occurrence-order-tests) (occurrence-graph-tests) (occurrence-late-merge-and-error-tests)
289 (setf *last-occurrence-checks* (nreverse *checks*))
290 (format t "~&OCCURRENCES-PASS: ~D checks; 4 new byte-equal baselines; 29 imported PASS, 244 NOT-RUN.~%" (length *last-occurrence-checks*)) t))
291 (defun write-occurrence-report (path)
292 (with-open-file (out path :direction :output :if-exists :supersede :if-does-not-exist :create)
293 (topic-maps.test-foundation::emit-json-value
294 (topic-maps.test-foundation::fields "kind" "occurrence-semantic-and-cxtm-evidence"
295 "passed" (length *last-occurrence-checks*) "failed" 0
296 "checks" (topic-maps.test-foundation::json-array *last-occurrence-checks*)
297 "cases" (topic-maps.test-foundation::json-array *occurrence-observations*)) out)
298 (terpri out)))