]> dreyeck.freedombox.rocks Git - topic-maps.git/blob - tests/xtm-associations.lisp
feat(tmdm): readers for the TMDM 7.2/7.3 relationships; tests for both default name...
[topic-maps.git] / tests / xtm-associations.lisp
1 (in-package #:topic-maps.xtm.tests)
2
3 ;; Slice 22J uses the existing native TMDM model and the existing case registry.
4 (defparameter *association-originals*
5 '("association" "association-binary" "association-binary-duplicate"
6 "association-ternary" "association-scope" "association-duplicate-role"
7 "association-instanceof-duplicate" "association-instanceof-scope" "merge-itemid-with-association"))
8 (defun as-roles (map) (loop for a in (topic-map-associations map) append (association-roles a)))
9 (defun as-current-p (map)
10 (and (occurrence-current-p map)
11 (every (lambda (a)
12 (and (eq a (canonical-association a)) (eq map (association-parent a))
13 (eq (association-type a) (canonical-topic (association-type a)))
14 (= (length (association-scope a)) (length (remove-duplicates (association-scope a) :test #'eq)))
15 (every (lambda (s) (eq s (canonical-topic s))) (association-scope a))
16 (association-roles a)
17 (every (lambda (r) (and (eq r (canonical-association-role r))
18 (eq a (association-role-parent r))
19 (eq (association-role-type r) (canonical-topic (association-role-type r)))
20 (eq (association-role-player r) (canonical-topic (association-role-player r)))
21 (= 1 (count r (topic-roles-played (association-role-player r)) :test #'eq)))) (association-roles a))))
22 (topic-map-associations map))
23 (every (lambda (topic) (every (lambda (r)
24 (and (member r (as-roles map) :test #'eq) (eq topic (association-role-player r)))) (topic-roles-played topic))) (topic-map-topics map))))
25 (defun as-model (map)
26 (let ((topics (topic-map-topics map)) (associations (topic-map-associations map)))
27 (flet ((ref (topic) (1+ (position topic topics :test #'eq))))
28 (mm-fields "existingModel" (occurrence-model map) "canonicalAssociationRoleReferencesEQ" (if (as-current-p map) :true :false)
29 "topicCount" (length topics) "associationCount" (length associations) "roleCount" (length (as-roles map))
30 "associations" (coerce (loop for a in associations collect
31 (mm-fields "parentIsActualMapEQ" (if (eq map (association-parent a)) :true :false)
32 "type" (ref (association-type a)) "scope" (coerce (mapcar #'ref (association-scope a)) 'vector)
33 "itemIdentifiers" (coerce (item-identifiers a) 'vector)
34 "roles" (coerce (loop for r in (association-roles a) collect
35 (mm-fields "parentAssociation" (1+ (position (association-role-parent r) associations :test #'eq))
36 "type" (ref (association-role-type r)) "player" (ref (association-role-player r))
37 "inverseRolesPlayedEQ" (if (member r (topic-roles-played (association-role-player r)) :test #'eq) :true :false)
38 "itemIdentifiers" (coerce (item-identifiers r) 'vector))) 'vector))) 'vector)))))
39 (defun as-observe (raw key)
40 ;; Passive observation of the actual pre-normalization native handles. This
41 ;; observes duplicate roles before MAKE-ASSOCIATION normalizes them; no model
42 ;; item is constructed or changed by the observer. Always restore operations.
43 (let ((normalize (symbol-function 'topic-maps.tmdm::normalize-associations))
44 (parser (symbol-function 'topic-maps.xml:parse-octets))
45 (observations (make-hash-table :test #'eq)) (calls 0) (same nil) (map nil))
46 (unwind-protect
47 (progn
48 (setf (symbol-function 'topic-maps.xml:parse-octets)
49 (lambda (input &rest args) (incf calls) (setf same (eq raw input)) (apply parser input args)))
50 (setf (symbol-function 'topic-maps.tmdm::normalize-associations)
51 (lambda (model)
52 (unless (gethash model observations) (setf (gethash model observations) (list nil nil)))
53 (dolist (i (append (topic-map-associations model) (as-roles model)))
54 (pushnew i (first (gethash model observations)) :test #'eq))
55 (let ((before (list (length (topic-map-associations model)) (length (as-roles model)))))
56 (prog1 (funcall normalize model)
57 (push (append before (list (length (topic-map-associations model)) (length (as-roles model)))) (second (gethash model observations)))))))
58 (setf map (deserialize-octets raw :document-iri *document* :source-key key)))
59 (setf (symbol-function 'topic-maps.xml:parse-octets) parser
60 (symbol-function 'topic-maps.tmdm::normalize-associations) normalize))
61 ;; Core-subject preflights normalize private shadow maps as well. Only
62 ;; handles belonging to the actual returned reader Map are reader evidence.
63 (values map (first (gethash map observations)) (nreverse (second (gethash map observations))) calls same)))
64 (defun as-held-current-p (map held)
65 (every (lambda (i) (member (topic-maps.tmdm::canonical-item i)
66 (append (topic-map-associations map) (as-roles map)) :test #'eq)) held))
67 (defun as-pure (label map)
68 (let ((before (mm-state map)) (cx (mm-cxtm map)) (held (topic-maps.tmdm::map-information-items map)))
69 (check (format nil "association:~A:pure-repeated-CXTM-canonical-handles" label)
70 (and (equalp cx (mm-cxtm map)) (equal before (mm-state map)) (as-current-p map)
71 (every (lambda (i) (eq i (topic-maps.tmdm::canonical-item i))) held))) cx))
72 (defun as-native-original (name map)
73 (let* ((a (first (topic-map-associations map)))
74 (single (equal name "association"))
75 (ternary (member name '("association-ternary" "association-duplicate-role") :test #'equal))
76 (corep (search "instanceof" name)) (merged (equal name "merge-itemid-with-association"))
77 (theme (cond ((equal name "association-scope") "scopingtopic") ((equal name "association-instanceof-scope") "expert1")))
78 (players (cond (single '("topic")) (ternary '("topic1" "topic2" "topic3")) (merged '("topic" "topic3")) (t '("topic1" "topic2"))))
79 (types (cond (single '("roletype")) (ternary '("roletype1" "roletype2" "roletype3")) (t '("roletype1" "roletype2")))))
80 (check (format nil "association-original:~A:exact-native-types-players-scope-parent" name)
81 (and (= 1 (length (topic-map-associations map)))
82 (= (+ 1 (* 2 (length players)) (if theme 1 0)) (length (topic-map-topics map)))
83 (= (length players) (length (association-roles a)))
84 (eq (by-id map "assoctype") (association-type a))
85 (scope-eq-p (association-scope a) (when theme (list (by-id map theme))))
86 (loop for p in players for rt in types always
87 (some (lambda (r) (and (eq (by-id map p) (association-role-player r))
88 (eq (by-id map rt) (association-role-type r)))) (association-roles a)))
89 (null (all-occurrences map)) (null (name-reifier-names map)) (null (item-identifiers map))
90 (every (lambda (i) (and (null (item-identifiers i)) (null (item-reifier i)))) (cons a (association-roles a)))
91 (as-current-p map)))
92 (when corep
93 (check (format nil "association-original:~A:implicit-explicit-core-SI-identity" name)
94 (and (eq (core map "type-instance") (by-id map "assoctype"))
95 (eq (core map "instance") (by-id map "roletype1")) (eq (core map "type") (by-id map "roletype2")))))
96 (when merged
97 (check "association-original:merge-itemid:all-identifiers-retained-canonical-player"
98 (and (eq (by-id map "topic") (by-id map "topic2"))
99 (same-identifiers-p (item-identifiers (by-id map "topic"))
100 (list (concatenate 'string *document* "#topic") (concatenate 'string *document* "#topic2") "http://example.org/#topic")))))))
101 (defun association-original-contracts ()
102 (setf *association-outputs* nil)
103 (let ((previous (copy-list *cases*)))
104 (dolist (name *association-originals*)
105 (let* ((id (format nil "xtm2/in/~A.xtm" name))
106 (*document* (concatenate 'string "https://xtm-tests.example.invalid/cd165b150176c1d6842b37be9cc9051b40d4996b/" id))
107 (raw (file-bytes (corpus-path id))) (copy (copy-seq raw))
108 (baseline (corpus-path (format nil "xtm2/baseline/~A.xtm.cxtm" name))) (expected (file-bytes baseline))
109 (case (topic-maps.test-foundation:make-test-case :id id :category :valid :source-pathname (corpus-path id)
110 :document-iri *document* :expected-outcome :cxtm-equal :expected-baseline baseline
111 :clauses '("XTM 4.13-4.14,4.18-4.20" "TMDM 5.7-5.8,6.2,6.6-6.7" "CXTM 3.9-3.10,4.10-4.11")))
112 (map nil) (held nil) (stages nil) (calls 0) (same nil) (actual nil) (c nil))
113 (check (format nil "association-original:~A:unique-new-case" name)
114 (null (find id *cases* :key #'topic-maps.test-foundation:test-case-id :test #'equal)))
115 (setf *cases* (append *cases* (list case)))
116 (handler-case
117 (progn
118 (multiple-value-setq (map held stages calls same) (as-observe raw id))
119 (as-native-original name map)
120 (check (format nil "association-original:~A:raw-octets-qualified-parser-document-context" name)
121 (and (= 1 calls) same (equalp raw copy)))
122 (check (format nil "association-original:~A:all-pre-normalization-handles-resolve" name) (as-held-current-p map held))
123 (when (member name '("association-binary-duplicate" "association-duplicate-role" "association-instanceof-duplicate" "merge-itemid-with-association") :test #'equal)
124 (check (format nil "association-original:~A:actual-replacement-forwarding" name)
125 (some (lambda (i) (not (eq i (topic-maps.tmdm::canonical-item i)))) held)))
126 (setf actual (as-pure name map))
127 (let ((other (deserialize-octets raw :document-iri *document* :source-key "independent:association-original")))
128 (check (format nil "association-original:~A:source-key-independent" name)
129 (and (equalp (as-model map) (as-model other)) (equalp actual (mm-cxtm other))))))
130 (error (condition) (setf c condition)))
131 (record-original-result case actual expected c)
132 (push (mm-fields "id" id "documentIRI" *document* "sourceKey" id "sourceBytes" (length raw)
133 "sourceHex" (format nil "~{~2,'0X~}" (coerce raw 'list)) "sourceText" (babel:octets-to-string raw :encoding :utf-8)
134 "qualifiedParserCalls" calls "originalOctetsEQ" (if same :true :false)
135 "model" (when map (as-model map)) "normalizationStages" (coerce (mapcar (lambda (s) (coerce s 'vector)) stages) 'vector)
136 "observedNativeHandles" (length held) "replacedNativeHandles" (count-if (lambda (i) (not (eq i (topic-maps.tmdm::canonical-item i)))) held)
137 "oldHandlesCanonicalAndLive" (if (and map (as-held-current-p map held)) :true :false)
138 "actualBytes" (when actual (length actual)) "expectedBytes" (length expected)
139 "actualCXTM" (when actual (babel:octets-to-string actual :encoding :utf-8)) "expectedCXTM" (babel:octets-to-string expected :encoding :utf-8)
140 "firstDifferentByte" (when actual (mismatch actual expected)) "condition" (mm-condition c)
141 "status" (string-downcase (string (topic-maps.test-foundation:test-case-status case)))) *association-outputs*)
142 (when c (error c))
143 (check (format nil "association-original:~A:complete-original-CXTM-byte-exact" name) (equalp actual expected))))
144 (as-negative-original)
145 (check "association-original:requested-set-once-all-prior-PASS-preserved"
146 (and (every (lambda (case) (and (member case *cases* :test #'eq) (eq :pass (topic-maps.test-foundation:test-case-status case)))) previous)
147 (same-identifiers-p (mapcar #'topic-maps.test-foundation:test-case-id (set-difference *cases* previous :test #'eq))
148 (append (mapcar (lambda (n) (format nil "xtm2/in/~A.xtm" n)) *association-originals*) '("xtm2/invalid/topicref-no-fragment-id.xtm")))
149 (every (lambda (case) (= 1 (count (topic-maps.test-foundation:test-case-id case) *cases* :key #'topic-maps.test-foundation:test-case-id :test #'equal))) *cases*))))
150 (setf *association-outputs* (nreverse *association-outputs*)))
151 (defun as-negative-original ()
152 (let* ((id "xtm2/invalid/topicref-no-fragment-id.xtm")
153 (iri (concatenate 'string "https://xtm-tests.example.invalid/cd165b150176c1d6842b37be9cc9051b40d4996b/" id))
154 (raw (file-bytes (corpus-path id))) (copy (copy-seq raw))
155 (spec '("topicref-no-fragment-id" xtm-rejection :invalid-topic-ref "topicRef requires an XPointer shorthand fragment." 7 38 "XTM 4.20: href must contain an XPointer shorthand fragment"))
156 (c (condition-from (lambda () (deserialize-octets raw :document-iri iri :source-key id))))
157 (case (topic-maps.test-foundation:make-test-case :id id :category :invalid :source-pathname (corpus-path id)
158 :document-iri iri :expected-outcome :ctm-rejection :clauses (list (seventh spec)))))
159 (record-negative-original-result case spec c iri id)
160 (setf *cases* (append *cases* (list case)))
161 (push (mm-fields "id" id "documentIRI" iri "sourceKey" id "sourceBytes" (length raw)
162 "sourceHex" (format nil "~{~2,'0X~}" (coerce raw 'list)) "sourceText" (babel:octets-to-string raw :encoding :utf-8)
163 "condition" (mm-condition c) "intendedCauseReached" (if (intended-negative-p spec c iri id) :true :false)
164 "status" (string-downcase (string (topic-maps.test-foundation:test-case-status case)))) *association-outputs*)
165 (check "association-negative-original:intended-class-code-detail-position-context"
166 (and (intended-negative-p spec c iri id) (equalp copy raw)))
167 (check "association-negative-original:no-preliminary-Unsupported"
168 (and (not (typep c 'xtm-unsupported)) (eq :pass (topic-maps.test-foundation:test-case-status case))))))
169
170 (defun as-role-xml (type player)
171 (format nil "<role><type><topicRef href='~A'/></type><topicRef href='~A'/></role>" type player))
172 (defun as-xml (type roles &optional themes)
173 (format nil "<association><type><topicRef href='~A'/></type>~A~A</association>" type
174 (if themes (format nil "<scope>~{<topicRef href='~A'/>~}</scope>" themes) "")
175 (apply #'concatenate 'string (mapcar (lambda (pair) (apply #'as-role-xml pair)) roles))))
176 (defun as-probe (label text verify &optional replacement)
177 (multiple-value-bind (map held stages calls same) (as-observe (bytes (document text)) label)
178 (check (format nil "association:~A:actual-XML-reader-native-EQ" label) (and (= 1 calls) same (as-current-p map) (as-held-current-p map held)))
179 (funcall verify map)
180 (when replacement
181 (check (format nil "association:~A:actual-native-handle-replacement" label)
182 (some (lambda (i) (not (eq i (topic-maps.tmdm::canonical-item i)))) held)))
183 (let ((cx (as-pure label map)))
184 (push (mm-fields "label" label "sourceText" (document text) "model" (as-model map)
185 "CXTM" (babel:octets-to-string cx :encoding :utf-8) "bytes" (length cx)
186 "normalizationStages" (coerce (mapcar (lambda (s) (coerce s 'vector)) stages) 'vector)
187 "observedHandles" (length held) "replacedHandles" (count-if (lambda (i) (not (eq i (topic-maps.tmdm::canonical-item i)))) held)
188 "oldHandlesResolveToLiveCanonicalItems" :true) *association-controls*)) map))
189 (defun as-counts (label associations roles)
190 (lambda (map) (check (format nil "association:~A:expected-distinct-associations-role-sets" label)
191 (and (= associations (length (topic-map-associations map))) (= roles (length (as-roles map)))))))
192 (defun as-error (label body class code)
193 (let* ((raw (document body)) (c (condition-from (lambda () (deserialize-octets (bytes raw) :document-iri *document* :source-key label)))))
194 (push (mm-fields "label" label "sourceText" raw "condition" (mm-condition c)) *association-controls*)
195 (check (format nil "association-error:~A:actual-class-code-and-context" label)
196 (and (eq (type-of c) class) (eq code (error-code c))
197 (equal *document* (error-document-iri c)) (equal label (error-source-key c))
198 (if (typep c 'xtm-xml-error) (topic-maps.xtm:error-cause c) (and (integerp (error-line c)) (integerp (error-column c)))))) c))
199 (defun association-tests ()
200 (setf *association-controls* nil)
201 (let ((base (as-xml "#t" '(("#r" "#p") ("#s" "#q")))))
202 (as-probe "role-order-set-equality" (concatenate 'string base (as-xml "#t" '(("#s" "#q") ("#r" "#p")))) (as-counts "role-order-set-equality" 1 2) t)
203 (dolist (row (list (list "different-association-types" (as-xml "#other" '(("#r" "#p") ("#s" "#q"))))
204 (list "different-players" (as-xml "#t" '(("#r" "#other") ("#s" "#q"))))
205 (list "different-role-types" (as-xml "#t" '(("#other" "#p") ("#s" "#q"))))
206 (list "different-scopes" (as-xml "#t" '(("#r" "#p") ("#s" "#q")) '("#theme")))))
207 (as-probe (first row) (concatenate 'string base (second row)) (as-counts (first row) 2 4)))
208 (as-probe "different-arity" (concatenate 'string base (as-xml "#t" '(("#r" "#p")))) (as-counts "different-arity" 2 3))
209 (as-probe "duplicate-themes-and-roles" (as-xml "#t" '(("#r" "#p") ("#r" "#p")) '("#theme" "#theme"))
210 (lambda (map) (funcall (as-counts "duplicate-themes-and-roles" 1 1) map)
211 (check "association:duplicate-themes:one-canonical-theme" (equal (list (by-id map "theme")) (association-scope (first (topic-map-associations map)))))) t))
212 ;; Identity cascades occur AFTER both complete associations have been read.
213 (dolist (kind '("subjectIdentifier" "subjectLocator" "itemIdentity"))
214 (let* ((label (concatenate 'string "late-" kind))
215 (source (concatenate 'string (as-xml "#t" '(("#r" "#p")) '("#s")) (as-xml "#u" '(("#rr" "#q")) '("#v"))
216 (format nil "<topic id='t'><~A href='urn:type'/></topic><topic id='u'><~A href='urn:type'/></topic><topic id='r'><~A href='urn:role'/></topic><topic id='rr'><~A href='urn:role'/></topic><topic id='p'><~A href='urn:player'/></topic><topic id='q'><~A href='urn:player'/></topic><topic id='s'><~A href='urn:scope'/></topic><topic id='v'><~A href='urn:scope'/></topic>" kind kind kind kind kind kind kind kind))))
217 (as-probe label source
218 (lambda (map) (funcall (as-counts label 1 1) map)
219 (check (format nil "association:~A:late-types-players-themes-all-EQ" label)
220 (and (eq (by-id map "p") (by-id map "q")) (eq (by-id map "t") (by-id map "u"))
221 (eq (by-id map "r") (by-id map "rr")) (eq (by-id map "s") (by-id map "v"))))) t)))
222 (as-probe "late-player-collapse-within-one-parent"
223 (concatenate 'string (as-xml "#t" '(("#r" "#p") ("#r" "#q")))
224 "<topic id='p'><subjectIdentifier href='urn:one'/></topic><topic id='q'><subjectIdentifier href='urn:one'/></topic>")
225 (as-counts "late-player-collapse-within-one-parent" 1 1) t)
226 (as-probe "SI-reference-hit-no-new-II-absolute-relative-and-forward"
227 (concatenate 'string "<topic id='known'><subjectIdentifier href='https://external.example/map#p'/></topic>"
228 (as-xml "#t" '(("#r" "https://external.example/map#p") ("#r" "../other.xtm#late")))
229 "<topic id='later'><itemIdentity href='../other.xtm#late'/></topic>")
230 (lambda (map)
231 (check "association:SI-lookup:no-new-II-on-existing-topic-and-forward-II-merge"
232 (and (equal (list (concatenate 'string *document* "#known")) (item-identifiers (by-id map "known")))
233 (some (lambda (r) (eq (by-id map "known") (association-role-player r))) (as-roles map))
234 (some (lambda (r) (eq (by-id map "later") (association-role-player r))) (as-roles map))
235 (member (mm-child-iri "../other.xtm#late") (item-identifiers (by-id map "later")) :test #'equal)))))
236 (as-probe "instanceOf-explicit-late-player-merge"
237 (concatenate 'string
238 "<topic id='p'><instanceOf><topicRef href='#t'/></instanceOf></topic>"
239 (as-xml "#at" '(("#ir" "#q") ("#tr" "#t")))
240 "<topic id='at'><subjectIdentifier href='http://psi.topicmaps.org/iso13250/model/type-instance'/></topic><topic id='ir'><subjectIdentifier href='http://psi.topicmaps.org/iso13250/model/instance'/></topic><topic id='tr'><subjectIdentifier href='http://psi.topicmaps.org/iso13250/model/type'/></topic><topic id='p2'><itemIdentity href='#p'/><subjectIdentifier href='urn:instance'/></topic><topic id='q'><subjectIdentifier href='urn:instance'/></topic>")
241 (lambda (map)
242 (funcall (as-counts "instanceOf-explicit-late-player-merge" 1 2) map)
243 (check "association:instanceOf-explicit:core-identities-preserved-after-late-player-merge"
244 (and (eq (by-id map "p") (by-id map "q"))
245 (eq (core map "type-instance") (association-type (first (topic-map-associations map))))))) t)
246 ;; Contexts/cardinalities are validated before native model construction.
247 (dolist (row '(("missing-association-type" "<association/>" xtm-rejection :missing-type)
248 ("missing-roles" "<association><type><topicRef href='#t'/></type></association>" xtm-rejection :missing-roles)
249 ("missing-role-type" "<association><type><topicRef href='#t'/></type><role><topicRef href='#p'/></role></association>" xtm-rejection :missing-type)
250 ("missing-role-player" "<association><type><topicRef href='#t'/></type><role><type><topicRef href='#r'/></type></role></association>" xtm-rejection :missing-role-player)
251 ("multiple-players" "<association><type><topicRef href='#t'/></type><role><type><topicRef href='#r'/></type><topicRef href='#p'/><topicRef href='#q'/></role></association>" xtm-rejection :role-player-cardinality)
252 ("role-before-type" "<association><role><type><topicRef href='#r'/></type><topicRef href='#p'/></role><type><topicRef href='#t'/></type></association>" xtm-rejection :missing-type)
253 ("scope-after-role" "<association><type><topicRef href='#t'/></type><role><type><topicRef href='#r'/></type><topicRef href='#p'/></role><scope><topicRef href='#s'/></scope></association>" xtm-rejection :element-order)
254 ("role-player-before-type" "<association><type><topicRef href='#t'/></type><role><topicRef href='#p'/><type><topicRef href='#r'/></type></role></association>" xtm-rejection :missing-type)
255 ("duplicate-type" "<association><type><topicRef href='#t'/></type><type><topicRef href='#u'/></type></association>" xtm-rejection :duplicate-type)
256 ("duplicate-scope" "<association><type><topicRef href='#t'/></type><scope><topicRef href='#s'/></scope><scope><topicRef href='#s'/></scope></association>" xtm-rejection :duplicate-scope)
257 ("type-cardinality" "<association><type/></association>" xtm-rejection :type-cardinality)
258 ("empty-scope" "<association><type><topicRef href='#t'/></type><scope/></association>" xtm-rejection :empty-scope)
259 ("association-in-topic" "<topic id='p'><association/></topic>" xtm-rejection :unexpected-element)
260 ("role-in-map" "<role/>" xtm-rejection :unexpected-element)
261 ("bad-namespace" "<association xmlns='urn:wrong'/>" xtm-rejection :invalid-namespace)
262 ("text-in-role" "<association><type><topicRef href='#t'/></type><role>bad</role></association>" xtm-rejection :unexpected-text)
263 ("unknown-child" "<association><bogus/></association>" xtm-rejection :unexpected-element)
264 ("unknown-attribute" "<association bogus='1'/>" xtm-rejection :unexpected-attribute)
265 ("malformed-XML" "<association>" xtm-xml-error :xml-not-well-formed)
266 ("association-reifier" "<association reifier='#r'><type><topicRef href='#t'/></type><role reifier='#excluded-role%GG'><type><topicRef href='#rt'/></type><topicRef href='#p'/></role></association>" xtm-rejection :invalid-percent-escape)
267 ("role-reifier" "<association><type><topicRef href='#t'/></type><role reifier='#r%GG'><type><topicRef href='#rt'/></type><topicRef href='#p'/></role></association>" xtm-rejection :invalid-percent-escape)
268 ("association-II" "<association reifier='#excluded'><itemIdentity href='urn:as'/><type><topicRef href='#t'/></type><role reifier='#excluded-role%GG'><type><topicRef href='#rt'/></type><topicRef href='#p'/></role></association>" xtm-rejection :invalid-percent-escape)
269 ("role-II" "<association><type><topicRef href='#t'/></type><role reifier='#excluded%GG'><itemIdentity href='urn:role'/><type><topicRef href='#rt'/></type><topicRef href='#p'/></role></association>" xtm-rejection :invalid-percent-escape)))
270 (apply #'as-error row))
271 (dolist (value '("no-fragment" "#" "#1bad" "#a:b" "#xpointer(id)"))
272 (as-error (concatenate 'string "invalid-fragment:" value) (as-xml value '(("#r" "#p"))) 'xtm-rejection :invalid-topic-ref))
273 (dolist (context '("role-type" "player" "scope"))
274 (as-error (concatenate 'string "bad-reference:" context)
275 (as-xml "#t" (if (equal context "role-type") '(("#1bad" "#p")) (if (equal context "player") '(("#r" "#1bad")) '(("#r" "#p"))))
276 (when (equal context "scope") '("#1bad"))) 'xtm-rejection :invalid-topic-ref))
277 (as-native-conflict)
278 (as-import-test)
279 (setf *association-controls* (nreverse *association-controls*)))
280 (defun as-native-conflict ()
281 ;; Real native core identity conflict, after an explicit association exists.
282 (let* ((source (document (concatenate 'string (as-xml "#t" '(("#r" "#p")))
283 "<topic id='t'><subjectIdentifier href='http://psi.topicmaps.org/iso13250/model/type-instance'/><subjectIdentifier href='http://psi.topicmaps.org/iso13250/model/type'/></topic>")))
284 (c (condition-from (lambda () (deserialize-octets (bytes source) :document-iri *document* :source-key "association-native-core-conflict")))))
285 (check "association-error:native-core-conflict-original-TMDM-class"
286 (and (typep c 'core-subject-error) (eq :core-subject-conflict (core-subject-error-code c))))
287 (push (mm-fields "label" "native-core-conflict" "sourceText" source "condition" (mm-condition c)
288 "nativeCode" (when (typep c 'core-subject-error) (string-downcase (string (core-subject-error-code c))))
289 "nativeConditionHasNoSourcePosition" :true) *association-controls*)))
290 (defun as-import-test ()
291 (let* ((mid (mm-child-iri "mid.xtm")) (child (mm-child-iri "leaf.xtm"))
292 (raw (bytes (document (concatenate 'string "<itemIdentity href='urn:child-map'/><topic id='p'><subjectIdentifier href='urn:shared-player'/><name><value>Name</value></name></topic>"
293 (as-xml "#t" '(("#r" "#p") ("#r2" "#q")) '("#s")))))))
294 (mm-call "association-native-nested-import"
295 (document (concatenate 'string (mm-directive "mid.xtm") "<topic id='local'><subjectIdentifier href='urn:shared-player'/></topic>"))
296 (list (list mid (bytes (document (mm-directive "leaf.xtm"))) "middle:diagnostic-only") (list child raw "child:diagnostic-only"))
297 (lambda (map imports calls)
298 (check "association:import:two-real-contexts-exact-resolver-IRIs"
299 (equal calls (list (list mid :mergemap *document* "http://psi.topicmaps.org/iso13250/xtm")
300 (list child :mergemap mid "http://psi.topicmaps.org/iso13250/xtm"))))
301 (check "association:import:native-EQ-players-types-scope-parents-source-preserved"
302 (and (as-current-p map) (eq (by-id map "local") (mm-local map child "p"))
303 (null (item-identifiers map)) (= 1 (length (topic-map-associations map)))
304 (let ((a (first (topic-map-associations map))))
305 (and (eq (mm-local map child "t") (association-type a))
306 (equal (list (mm-local map child "s")) (association-scope a))
307 (some (lambda (r) (eq (by-id map "local") (association-role-player r))) (association-roles a))))
308 (every (lambda (record)
309 (let* ((source (first record)) (resolve (second record)) (a (first (topic-map-associations source))))
310 (and (not (eq source (association-parent (funcall resolve a))))
311 (mm-current-p (association-parent (funcall resolve a)))
312 (not (eq a (funcall resolve a)))
313 (every (lambda (r) (and (not (eq r (funcall resolve r)))
314 (member (funcall resolve r) (association-roles (funcall resolve a)) :test #'eq))) (association-roles a))))) imports)))
315 (push (mm-fields "label" "nested-native-association-import" "sourceText" (babel:octets-to-string raw :encoding :utf-8)
316 "model" (as-model map) "sourceMapIdentifiersExcluded" :true "sourceMapsUnchanged" :true) *association-controls*)))))