]> dreyeck.freedombox.rocks Git - topic-maps.git/blob - tests/xtm-name-reification.lisp
Integrate qualified XML anyType values into the XTM reader
[topic-maps.git] / tests / xtm-name-reification.lisp
1 (in-package #:topic-maps.xtm.tests)
2
3 (defun name-reifier-names (map)
4 (loop for topic in (topic-map-topics map) append (topic-names topic)))
5 (defun name-reifier-current-p (map)
6 (and (variants-current-p map) (topic-maps.tmdm::validate-map-reification map)
7 (topic-maps.tmdm::validate-map-item-identifiers map)
8 (every (lambda (name) (let ((r (item-reifier name)))
9 (or (null r) (and (typep r 'topic) (eq r (canonical-topic r))
10 (member r (topic-map-topics map) :test #'eq) (eq name (topic-reified r)))))) (name-reifier-names map))))
11 (defun name-reifier-model-data (map)
12 (let ((topics (topic-map-topics map)) (names (name-reifier-names map)))
13 (topic-maps.test-foundation::fields "identity" (variant-model-data map)
14 "canonicalNameReifierInverseEQ" (if (name-reifier-current-p map) :true :false)
15 "mapReifierTopic" (when (item-reifier map) (1+ (position (item-reifier map) topics :test #'eq)))
16 "nameReifierTopics" (coerce (mapcar (lambda (name) (when (item-reifier name)
17 (1+ (position (item-reifier name) topics :test #'eq)))) names) 'vector)
18 "topicReifiedNames" (coerce (mapcar (lambda (topic) (let ((p (position (topic-reified topic) names :test #'eq)))
19 (when p (1+ p)))) topics) 'vector))))
20 (defun name-reifier-state (map &optional held)
21 (list (map-reifier-state map)
22 (loop for item in held collect
23 (list item (topic-maps.tmdm::canonical-item item)
24 (when (topic-maps.tmdm::reifiable-p item) (topic-maps.tmdm::%item-reifier item))
25 (typecase item (topic (topic-maps.tmdm::%topic-forward item))
26 (topic-name (topic-maps.tmdm::%topic-name-forward item)))))))
27 (defun name-reifier-pure (label map &optional held)
28 (let* ((before (name-reifier-state map held))
29 (actual (topic-maps.cxtm:canonicalize-octets map :base-locator *document*)))
30 (check (concatenate 'string "name-reifier:" label ":pure-deterministic-current-and-retained-handles")
31 (and (equal before (name-reifier-state map held))
32 (equalp actual (topic-maps.cxtm:canonicalize-octets map :base-locator *document*))
33 (equal before (name-reifier-state map held))))
34 actual))
35 (defun name-reifier-xml (iri &optional (value "N") (tail ""))
36 (format nil "<name reifier='~A'><value>~A</value>~A</name>" iri value tail))
37
38 (defun name-reifier-original-contracts ()
39 (setf *name-reifier-outputs* nil)
40 (dolist (spec '(("name-reifier" "reifier" 1 180 434) ("name-duplicate-reified" "reifier1" 2 251 435)))
41 (destructuring-bind (stem r-id source-count source-size baseline-size) spec
42 (let* ((id (format nil "xtm2/in/~A.xtm" stem))
43 (*document* (concatenate 'string "https://xtm-tests.example.invalid/cd165b150176c1d6842b37be9cc9051b40d4996b/" id))
44 (label (concatenate 'string "name-reifier-original:" stem)) (raw (file-bytes (corpus-path id))) (copy (copy-seq raw))
45 (baseline (corpus-path (format nil "xtm2/baseline/~A.xtm.cxtm" stem))) (expected (file-bytes baseline))
46 (case (topic-maps.test-foundation:make-test-case :id id :category :valid :source-pathname (corpus-path id)
47 :document-iri *document* :expected-outcome :cxtm-equal :expected-baseline baseline
48 :clauses '("XTM 2.0 4.3.1-4.3.4,4.10" "TMDM 5.3.4,5.3.5,5.4,6.2,6.3" "CXTM 3,4")))
49 (map nil) (actual nil) (c nil))
50 (setf *cases* (append *cases* (list case)))
51 (handler-case
52 (progn
53 (let ((saved (symbol-function 'topic-maps.xml:parse-octets)) (calls 0) (same nil))
54 (unwind-protect
55 (progn (setf (symbol-function 'topic-maps.xml:parse-octets)
56 (lambda (source handler) (incf calls) (setf same (eq raw source)) (funcall saved source handler)))
57 (setf map (deserialize-octets raw :document-iri *document* :source-key id))
58 (check (concatenate 'string label ":qualified-parser-once-original-octets-eq") (and (= 1 calls) same)))
59 (setf (symbol-function 'topic-maps.xml:parse-octets) saved)))
60 (let* ((root (topic-maps.xml:parse-octets raw (make-instance 'topic-maps.xtm::source-handler)))
61 (source-topic (first (topic-maps.xtm::elements root)))
62 (source-names (topic-maps.xtm::elements source-topic))
63 (owner (by-id map "topic")) (name (first (topic-names owner)))
64 (r (by-id map r-id)) (type (by-si map (default-name-type-identifier))))
65 (check (concatenate 'string label ":actual-original-source-properties")
66 (and (= source-size (length raw)) (= source-count (length source-names))
67 (equal "topic" (topic-maps.xtm::attr source-topic "id"))
68 (every (lambda (node) (and (equal "name" (topic-maps.xtm::node-name node))
69 (equal (concatenate 'string "#" r-id) (topic-maps.xtm::attr node "reifier"))
70 (= 1 (length (topic-maps.xtm::elements node)))
71 (equal "value" (topic-maps.xtm::node-name (first (topic-maps.xtm::elements node))))
72 (equal '("Topic") (topic-maps.xtm::node-children (first (topic-maps.xtm::elements node)))))) source-names)))
73 (check (concatenate 'string label ":native-normalized-name-reifier-inverse-and-canonical-eq")
74 (and (= 3 (length (topic-map-topics map))) (null (topic-map-associations map))
75 (= 1 (length (name-reifier-names map))) (= 1 (length (topic-names owner)))
76 (eq owner (topic-name-parent name)) (eq name (canonical-topic-name name))
77 (eq type (topic-name-type name)) (equal "Topic" (topic-name-value name))
78 (null (topic-name-scope name)) (null (topic-name-variants name))
79 (eq r (item-reifier name)) (eq name (topic-reified r)) (eq r (canonical-topic r))
80 (null (item-reifier map)) (null (topic-reified owner)) (null (topic-reified type))
81 (name-reifier-current-p map)))
82 (check (concatenate 'string label ":complete-separated-identifier-sets")
83 (and (null (item-identifiers map)) (null (item-identifiers name))
84 (equal (list (concatenate 'string *document* "#topic")) (item-identifiers owner))
85 (equal (list (concatenate 'string *document* "#" r-id)) (item-identifiers r))
86 (equal (list (default-name-type-identifier)) (topic-subject-identifiers type)) (null (item-identifiers type))
87 (null (topic-subject-identifiers owner)) (null (topic-subject-locators owner))
88 (null (topic-subject-identifiers r)) (null (topic-subject-locators r)) (null (topic-subject-locators type))
89 (null (topic-names r)) (null (topic-names type))
90 (every (lambda (topic) (and (null (topic-occurrences topic)) (null (topic-roles-played topic)))) (topic-map-topics map))))
91 (setf actual (name-reifier-pure stem map (list owner name r type)))
92 (check (concatenate 'string label ":unmodified-source-baseline-size")
93 (and (equalp raw copy) (= baseline-size (length expected))))
94 (let ((other (deserialize-octets raw :document-iri *document* :source-key "independent:name-reifier")))
95 (check (concatenate 'string label ":source-key-independent-model-cxtm")
96 (and (equalp (name-reifier-model-data map) (name-reifier-model-data other))
97 (equalp actual (topic-maps.cxtm:canonicalize-octets other :base-locator *document*)))))))
98 (error (condition) (setf c condition)))
99 (record-original-result case actual expected c)
100 (push (topic-maps.test-foundation::fields "id" id "documentIRI" *document* "sourceKey" id
101 "sourceBytes" (length raw) "sourceHex" (format nil "~{~2,'0X~}" (coerce raw 'list))
102 "sourceText" (babel:octets-to-string raw :encoding :utf-8) "sourceNameCount" source-count
103 "reifierLocator" (concatenate 'string *document* "#" r-id)
104 "model" (when map (name-reifier-model-data map)) "condition" (map-reifier-condition-data c)
105 "actualCXTM" (when actual (babel:octets-to-string actual :encoding :utf-8))
106 "expectedCXTM" (babel:octets-to-string expected :encoding :utf-8)
107 "actualBytes" (when actual (length actual)) "expectedBytes" (length expected)
108 "firstDifferentByte" (when actual (mismatch actual expected))
109 "status" (string-downcase (string (topic-maps.test-foundation:test-case-status case)))) *name-reifier-outputs*)
110 (when c (error c))
111 (check (concatenate 'string label ":byte-exact") (equalp actual expected)))))
112 (setf *name-reifier-outputs* (nreverse *name-reifier-outputs*))
113 (check "name-reifier-originals:65-unique-records-two-new-positives"
114 (and (= 65 (length *cases*)) (= 57 (count :valid *cases* :key #'topic-maps.test-foundation:test-case-category))
115 (= 65 (length (remove-duplicates *cases* :key #'topic-maps.test-foundation:test-case-id :test #'equal))))))
116
117 (defun name-reifier-control (label body verify)
118 (let* ((source (document body)) (raw (bytes source)) (copy (copy-seq raw))
119 (map (deserialize-octets raw :document-iri *document* :source-key label)))
120 (funcall verify map)
121 (check (concatenate 'string "name-reifier:" label ":canonical-native-reification") (name-reifier-current-p map))
122 (let ((actual (name-reifier-pure label map (append (topic-map-topics map) (name-reifier-names map)))))
123 (check (concatenate 'string "name-reifier:" label ":original-source-bytes-preserved") (equalp raw copy))
124 (push (topic-maps.test-foundation::fields "label" label "sourceText" source "model" (name-reifier-model-data map)
125 "actualCXTM" (babel:octets-to-string actual :encoding :utf-8) "condition" nil) *name-reifier-controls*))))
126 (defun name-reifier-error-control (label body class code &optional thunk map)
127 ;; Reuse the existing native/XTM Condition verifier and JSON format. Bind its
128 ;; output separately so historical Map-Reification evidence stays independent.
129 (let ((*map-reifier-controls* nil))
130 (unwind-protect
131 (map-reifier-error-control (concatenate 'string "name:" label) (when body (document body)) class code thunk map)
132 (when *map-reifier-controls* (push (first *map-reifier-controls*) *name-reifier-controls*)))))
133
134 (defun name-reifier-value-tests ()
135 (dolist (row `(("absolute" "urn:name-r" "urn:name-r")
136 ("relative" "../reifiers#n" "https://xtm-tests.example.invalid/cd165b150176c1d6842b37be9cc9051b40d4996b/xtm2/reifiers#n")
137 ("fragment" "#r" ,(concatenate 'string *document* "#r"))
138 ("empty" "" ,*document*) ("not-topicref-fragment" "#2r/path" ,(concatenate 'string *document* "#2r/path"))
139 ("percent-utf8" "urn:%E9%A6%AC%F0%9F%A6%8A" "urn:馬🦊") ("unicode-xml" "urn:馬&amp;🦊" "urn:馬&🦊")))
140 (destructuring-bind (label reference expected) row
141 (name-reifier-control label (format nil "<topic id='a'>~A</topic>" (name-reifier-xml reference " N &amp; 馬🦊 "))
142 (lambda (map) (let* ((owner (by-id map "a")) (name (first (topic-names owner))) (r (item-reifier name)))
143 (check (concatenate 'string "name-reifier:" label ":correct-name-not-parent-map-or-type")
144 (and (= 3 (length (topic-map-topics map))) (eq name (topic-reified r))
145 (equal (list expected) (item-identifiers r)) (null (topic-subject-identifiers r)) (null (topic-subject-locators r))
146 (equal " N & 馬🦊 " (topic-name-value name)) (null (item-identifiers name))
147 (null (item-identifiers map)) (null (item-reifier map)) (null (topic-reified owner))
148 (null (topic-reified (topic-name-type name))))))))))
149 (dolist (spec '(("existing-II" "itemIdentity" t) ("SI-only" "subjectIdentifier" t) ("SL-only" "subjectLocator" nil)))
150 (destructuring-bind (label kind merged) spec
151 (name-reifier-control label
152 (format nil "<topic id='r'><~A href='urn:reifier'/></topic><topic id='a'>~A</topic>" kind (name-reifier-xml "urn:reifier"))
153 (lambda (map) (let* ((name (first (topic-names (by-id map "a")))) (r (item-reifier name)) (old (by-id map "r")))
154 (check (concatenate 'string "name-reifier:" label ":ii-required-independent-of-si-sl")
155 (and (member "urn:reifier" (item-identifiers r) :test #'equal)
156 (if merged (and (eq r old) (same-identifiers-p (item-identifiers r)
157 (list "urn:reifier" (concatenate 'string *document* "#r"))))
158 (and (not (eq r old)) (equal '("urn:reifier") (item-identifiers r)) (null (topic-reified old)))))))))))
159 (name-reifier-control "name-II-type-scope-variant-forward"
160 (concatenate 'string "<itemIdentity href='urn:map'/><topic id='a'><name reifier='#r'><itemIdentity href='urn:name'/><type><topicRef href='#t'/></type><scope><topicRef href='#s'/></scope><value>N</value><variant><scope><topicRef href='#v'/></scope><resourceData>V</resourceData></variant></name></topic><topic id='r'/><topic id='t'/><topic id='s'/><topic id='v'/>")
161 (lambda (map) (let* ((owner (by-id map "a")) (name (first (topic-names owner))) (r (item-reifier name)) (v (first (topic-name-variants name))))
162 (check "name-reifier:identifiers-type-scope-variant:complete-model-and-eq"
163 (and (eq r (by-id map "r")) (eq name (topic-reified r)) (eq owner (topic-name-parent name))
164 (equal '("urn:map") (item-identifiers map)) (equal '("urn:name") (item-identifiers name))
165 (equal (list (concatenate 'string *document* "#r")) (item-identifiers r))
166 (eq (by-id map "t") (topic-name-type name)) (scope-eq-p (topic-name-scope name) (list (by-id map "s")))
167 (eq name (variant-parent v)) (equal "V" (variant-value v)) (equal (string-datatype) (variant-datatype v))
168 (scope-eq-p (variant-scope v) (list (by-id map "s") (by-id map "v"))))))))
169 (dolist (same '(nil t))
170 (let ((label (if same "equal-names-same-reifier" "equal-names-different-reifiers")))
171 (name-reifier-control label
172 (format nil "<topic id='a'><name reifier='#r1'><itemIdentity href='urn:n1'/><value>N</value></name><name reifier='#~A'><itemIdentity href='urn:n2'/><value>N</value><variant><scope><topicRef href='#s'/></scope><resourceData>V</resourceData></variant></name></topic>" (if same "r1" "r2"))
173 (lambda (map) (let* ((names (name-reifier-names map)) (name (first names)) (r (item-reifier name)))
174 (check (concatenate 'string "name-reifier:" label ":normalized-name-identifier-union-native-reifier")
175 (and (= 1 (length names)) (same-identifiers-p '("urn:n1" "urn:n2") (item-identifiers name))
176 (same-identifiers-p (item-identifiers r) (if same (list (concatenate 'string *document* "#r1"))
177 (list (concatenate 'string *document* "#r1") (concatenate 'string *document* "#r2"))))
178 (eq name (variant-parent (first (topic-name-variants name)))) (eq name (topic-reified r)))))))))
179 (name-reifier-control "different-names-different-reifiers"
180 (format nil "<topic id='a'>~A~A</topic>" (name-reifier-xml "#r1" "A") (name-reifier-xml "#r2" "B"))
181 (lambda (map) (let* ((names (topic-names (by-id map "a"))))
182 (check "name-reifier:different-names:two-independent-reifications"
183 (and (= 2 (length names)) (not (eq (item-reifier (first names)) (item-reifier (second names))))
184 (every (lambda (n) (eq n (topic-reified (item-reifier n)))) names))))))
185 (let* ((map (deserialize-octets (bytes (map-reifier-xml "#map-r" (format nil "<topic id='a'>~A</topic>" (name-reifier-xml "#name-r")))) :document-iri *document*))
186 (name (first (topic-names (by-id map "a")))))
187 (check "name-reifier:map-and-name:distinct-reifiers-inverses-identifiers"
188 (and (map-reifier-current-p map) (name-reifier-current-p map)
189 (not (eq (item-reifier map) (item-reifier name))) (eq name (topic-reified (item-reifier name)))
190 (null (item-identifiers map)) (null (item-identifiers name))))
191 (name-reifier-pure "map-and-name" map)))
192
193 (defun name-reifier-merge-tests ()
194 ;; Nine reader-level routes: Parent, Type or Scope merging by SI, SL or II.
195 (dolist (where '(:parent :type :scope))
196 (dolist (kind '("subjectIdentifier" "subjectLocator" "itemIdentity"))
197 (let* ((label (format nil "merge-~A-~A" where kind))
198 (one (format nil "<name reifier='#r1'><itemIdentity href='urn:n1'/>~A~A<value>N</value></name>"
199 (if (eq where :type) "<type><topicRef href='#x'/></type>" "")
200 (if (eq where :scope) "<scope><topicRef href='#x'/></scope>" "")))
201 (two (format nil "<name reifier='#r2'><itemIdentity href='urn:n2'/>~A~A<value>N</value></name>"
202 (if (eq where :type) "<type><topicRef href='#y'/></type>" "")
203 (if (eq where :scope) "<scope><topicRef href='#y'/></scope>" "")))
204 (body (concatenate 'string
205 (if (eq where :parent) (format nil "<topic id='x'>~A</topic><topic id='y'>~A</topic>" one two)
206 (format nil "<topic id='a'>~A~A</topic>" one two))
207 (format nil "<topic id='first'><itemIdentity href='#x'/><~A href='urn:shared'/></topic><topic id='last'><itemIdentity href='#y'/><~A href='urn:shared'/></topic>" kind kind)))
208 (topic-maps.xtm::*document-iri* *document*) (topic-maps.xtm::*source-key* label)
209 (root (topic-maps.xml:parse-octets (bytes (document body)) (make-instance 'topic-maps.xtm::source-handler)))
210 (map (make-topic-map)) (held nil))
211 (topic-maps.xtm::validate-source root)
212 (loop for node in (topic-maps.xtm::elements root) for step from 1 do
213 (topic-maps.xtm::read-topic node map)
214 (when (= step (if (eq where :parent) 2 1))
215 (setf held (append (name-reifier-names map) (mapcar #'item-reifier (name-reifier-names map))
216 (list (by-id map "x") (by-id map "y"))))
217 (check (concatenate 'string "name-reifier:" label ":before-distinct-native-names-reifiers")
218 (and (= 2 (length (name-reifier-names map)))
219 (not (eq (first held) (second held))) (not (eq (third held) (fourth held)))))))
220 (let* ((name (first (name-reifier-names map))) (r (item-reifier name)))
221 (check (concatenate 'string "name-reifier:" label ":normalized-old-new-names-reifiers-eq")
222 (and (= 1 (length (name-reifier-names map)))
223 (eq name (canonical-topic-name (first held))) (eq name (canonical-topic-name (second held)))
224 (eq r (canonical-topic (third held))) (eq r (canonical-topic (fourth held)))
225 (eq name (topic-reified (third held))) (eq name (topic-reified (fourth held)))
226 (same-identifiers-p '("urn:n1" "urn:n2") (item-identifiers name))
227 (same-identifiers-p (item-identifiers r)
228 (list (concatenate 'string *document* "#r1") (concatenate 'string *document* "#r2")))
229 (eq (canonical-topic (fifth held)) (canonical-topic (sixth held)))
230 (case where (:parent (eq (topic-name-parent name) (by-id map "x")))
231 (:type (eq (topic-name-type name) (by-id map "x")))
232 (:scope (scope-eq-p (topic-name-scope name) (list (by-id map "x")))))
233 (name-reifier-current-p map)))
234 (name-reifier-pure (concatenate 'string label ":staged") map held)
235 (name-reifier-control label body (lambda (other)
236 (check (concatenate 'string "name-reifier:" label ":public-api-equivalent")
237 (equalp (name-reifier-model-data map) (name-reifier-model-data other)))))))))
238 (let* ((body "<topic id='a'><name reifier='#r'><value>N</value></name></topic><topic id='definition'><itemIdentity href='#r'/></topic>")
239 (topic-maps.xtm::*document-iri* *document*)
240 (root (topic-maps.xml:parse-octets (bytes (document body)) (make-instance 'topic-maps.xtm::source-handler)))
241 (map (make-topic-map)))
242 (topic-maps.xtm::validate-source root)
243 (topic-maps.xtm::read-topic (first (topic-maps.xtm::elements root)) map)
244 (let* ((name (first (name-reifier-names map))) (r (item-reifier name)))
245 (check "name-reifier:forward-definition:created-before-later-topic" (and r (eq name (topic-reified r)) (null (by-id map "definition"))))
246 (topic-maps.xtm::read-topic (second (topic-maps.xtm::elements root)) map)
247 (check "name-reifier:forward-definition:old-reifier-new-canonical-eq-and-ii-union"
248 (and (not (eq r (canonical-topic r))) (eq (canonical-topic r) (by-id map "definition"))
249 (eq (canonical-topic r) (by-id map "r")) (eq (canonical-topic r) (item-reifier name)) (eq name (topic-reified r))
250 (same-identifiers-p (item-identifiers r) (list (concatenate 'string *document* "#r") (concatenate 'string *document* "#definition")))))
251 (name-reifier-pure "forward-definition:staged" map (list name r))
252 (name-reifier-control "forward-definition" body (lambda (other)
253 (check "name-reifier:forward-definition:public-api-equivalent" (equalp (name-reifier-model-data map) (name-reifier-model-data other)))))))
254 ;; A previously reified Name also survives merging with an unreified equal Name.
255 (let* ((map (make-topic-map)) (p (intern-topic map :item-identifier "urn:p")) (q (intern-topic map :item-identifier "urn:q"))
256 (a (add-default-name p "N")) (b (add-default-name q "N")) (r (intern-topic map :item-identifier "urn:r")))
257 (set-item-reifier a r) (merge-topics p q)
258 (check "name-reifier:normalization:one-reified-one-unreified-preserves-canonical-inverse"
259 (and (eq (canonical-topic-name a) (canonical-topic-name b)) (eq r (item-reifier b))
260 (eq (canonical-topic-name a) (topic-reified r)) (name-reifier-current-p map)))
261 (name-reifier-pure "one-reified-one-unreified" map (list p q a b r))))
262
263 (defun name-reifier-syntax-conflict-tests ()
264 (dolist (row '(("space" "urn:a b" :invalid-iri) ("bad-percent" "urn:%GG" :invalid-percent-escape)
265 ("bad-utf8" "urn:%C3%28" :invalid-percent-utf8) ("surrogate-utf8" "urn:%ED%A0%80" :invalid-percent-utf8)
266 ("decoded-control" "urn:%00" :invalid-iri) ("relative-colon" "1bad:iri" :invalid-iri)))
267 (name-reifier-error-control (first row) (format nil "<topic id='a'>~A</topic>" (name-reifier-xml (second row))) 'xtm-rejection (third row)))
268 (dolist (row '(("extra-attribute" "<name reifier='#r' other='x'><value>N</value></name>" :unexpected-attribute)
269 ("qualified-reifier" "<name xmlns:q='urn:q' q:reifier='#r'><value>N</value></name>" :unexpected-attribute)
270 ("reifier-child" "<name><reifier href='#r'/><value>N</value></name>" :unexpected-element)
271 ("wrong-namespace" "<name xmlns='urn:wrong' reifier='#r'><value>N</value></name>" :invalid-namespace)
272 ("identity-order" "<name reifier='#r'><value>N</value><itemIdentity href='urn:n'/></name>" :element-order)))
273 (name-reifier-error-control (first row) (format nil "<topic id='a'>~A</topic>" (second row)) 'xtm-rejection (third row)))
274 (name-reifier-error-control "malformed-XML" "<topic id='a'><name reifier='#r'><value>N</name></topic>" 'xtm-xml-error :xml-not-well-formed)
275 (name-reifier-error-control "variant-reifier-excluded-datatype"
276 "<topic id='a'><name reifier='#n'><value>N</value><variant reifier='#v'><scope><topicRef href='#s'/></scope><resourceData datatype='http://www.w3.org/2001/XMLSchema#anyType'>42</resourceData></variant></name></topic>" 'xtm-unsupported :resource-resolver-required)
277 (name-reifier-error-control "name-own-II-collision"
278 "<topic id='a'><name reifier='urn:name'><itemIdentity href='urn:name'/><value>N</value></name></topic>"
279 'topic-maps.tmdm::occurrence-identifier-error :duplicate-item-identifier)
280 (name-reifier-error-control "map-II-collision"
281 "<itemIdentity href='urn:map'/><topic id='a'><name reifier='urn:map'><value>N</value></name></topic>"
282 'topic-maps.tmdm::occurrence-identifier-error :duplicate-item-identifier)
283 (name-reifier-error-control "reuse-reifier"
284 (format nil "<topic id='a'>~A~A</topic>" (name-reifier-xml "#r" "A") (name-reifier-xml "#r" "B"))
285 'reification-error :reifier-conflict)
286 (let* ((map (read-body (format nil "<topic id='a'>~A~A</topic>" (name-reifier-xml "#r1" "A") (name-reifier-xml "#r2" "B"))))
287 (names (name-reifier-names map)) (a (first names)) (b (second names)) (r (item-reifier a)) (s (item-reifier b)))
288 (name-reifier-error-control "native-reuse-reifier" nil 'reification-error :reifier-conflict (lambda () (set-item-reifier b r)) map)
289 (name-reifier-error-control "native-distinct-reified-merge" nil 'reification-error :reifier-conflict (lambda () (merge-topics r s)) map)
290 (add-item-identifier a "urn:name")
291 (name-reifier-error-control "native-II-collision" nil 'topic-maps.tmdm::occurrence-identifier-error :duplicate-item-identifier
292 (lambda () (intern-topic map :item-identifier "urn:name")) map)
293 ;; Here Parent merging would make the Names equal, but both Topics already
294 ;; reify DIFFERENT live Names. TMDM 6.2 rejects the Topic merge first.
295 (let* ((self-map (read-body "<topic id='one'><name reifier='#one'><value>N</value></name></topic><topic id='two'><name reifier='#two'><value>N</value></name></topic>"))
296 (one (by-id self-map "one")) (two (by-id self-map "two")))
297 (name-reifier-error-control "native-parent-merge-reifier-conflict" nil 'reification-error :reifier-conflict
298 (lambda () (merge-topics one two)) self-map))
299 (check "name-reifier:conflicts:canonical-name-and-reifier-handles-preserved"
300 (and (eq a (canonical-topic-name a)) (eq b (canonical-topic-name b)) (eq a (topic-reified r)) (eq b (topic-reified s))
301 (eq r (item-reifier a)) (eq s (item-reifier b)) (name-reifier-current-p map)))))
302 (defun name-reifier-tests ()
303 (name-reifier-value-tests) (name-reifier-merge-tests) (name-reifier-syntax-conflict-tests))