(in-package #:topic-maps.xtm.tests)
(defvar *mergemap-controls* nil)
(defvar *mergemap-originals* nil)
(defun mm-fields (&rest args) (apply #'topic-maps.test-foundation::fields args))
(defun mm-freeze (value)
(typecase value (string (copy-seq value))
(cons (cons (mm-freeze (car value)) (mm-freeze (cdr value)))) (t value)))
(defun mm-state (map)
;; Extend the existing snapshots for the native Occurrence/Association/Role
;; transfer probes. Actual references/forwarding handles are retained.
(mm-freeze (list (map-reifier-state map)
(loop for i in (topic-maps.tmdm::map-information-items map) collect
(typecase i
(occurrence (list i (occurrence-parent i) (occurrence-type i) (occurrence-value i)
(occurrence-datatype i) (occurrence-scope i) (item-identifiers i) (item-reifier i)
(topic-maps.tmdm::%occurrence-forward i)))
(association (list i (association-parent i) (association-type i) (association-scope i)
(association-roles i) (topic-maps.tmdm::%association-forward i)))
(association-role (list i (association-role-parent i) (association-role-type i)
(association-role-player i) (topic-maps.tmdm::%association-role-forward i))))))))
(defun mm-current-p (map)
(and (topic-maps.tmdm::validate-import-map map)
(every (lambda (i) (and (eq i (topic-maps.tmdm::canonical-item i))
(eq map (topic-maps.tmdm::item-topic-map i))))
(topic-maps.tmdm::map-information-items map))
(every (lambda (a) (every (lambda (r)
(and (eq a (association-role-parent r))
(member r (topic-roles-played (association-role-player r)) :test #'eq))) (association-roles a)))
(topic-map-associations map))))
(defun mm-cxtm (map &optional (doc *document*))
(topic-maps.cxtm:canonicalize-octets map :base-locator doc))
(defun mm-model (map)
(mm-fields "identity" (variant-reifier-model-data map)
"occurrences" (coerce (loop for topic in (topic-map-topics map) append
(loop for o in (topic-occurrences topic) collect (mm-fields
"value" (occurrence-value o) "datatype" (occurrence-datatype o)
"itemIdentifiers" (coerce (item-identifiers o) 'vector)))) 'vector)
"canonicalNativeReferencesEQ" (if (mm-current-p map) :true :false)))
(defun mm-condition (c)
(when c
(let ((data (map-reifier-condition-data c)))
(when (typep c 'topic-maps.xtm:xtm-resource-error)
(setf (cdr (assoc "cause" (topic-maps.test-foundation::json-object-members data) :test #'equal))
(mm-condition (topic-maps.xtm:error-cause c))))
(when (typep c 'map-import-error)
(setf (cdr (assoc "code" (topic-maps.test-foundation::json-object-members data) :test #'equal))
(string-downcase (string (map-import-error-code c)))))
data)))
(defun mm-local (map doc id)
(find-if (lambda (topic) (member (concatenate 'string doc "#" id) (item-identifiers topic) :test #'equal))
(topic-map-topics map)))
(defun mm-child-iri (&optional (name "child.xtm") (doc *document*))
(let ((topic-maps.xtm::*document-iri* doc) (topic-maps.xtm::*source-key* "test:resolve"))
(topic-maps.xtm::resolve-iri name doc nil)))
(defun mm-directive (href) (format nil "" href))
(defun mm-call (label source resources verify &key (doc *document*) (key label) (depth 32) augment)
"Observe the real qualified parser and TMDM importer without changing their results.
AUGMENT is explicit native-only test setup for constructs outside XML support."
(let* ((raw (if (stringp source) (bytes source) source)) (copies (mapcar (lambda (r) (copy-seq (second r))) resources))
(root-copy (copy-seq raw)) (calls nil) (parses nil) (imports nil)
(saved-parser (symbol-function 'topic-maps.xml:parse-octets))
(saved-import (symbol-function 'import-map-content)) (map nil))
(unwind-protect
(progn
(setf (symbol-function 'topic-maps.xml:parse-octets)
(lambda (input &rest args)
(push (list topic-maps.xtm::*document-iri* topic-maps.xtm::*source-key* input) parses)
(apply saved-parser input args)))
(setf (symbol-function 'import-map-content)
(lambda (target child)
(when augment (funcall augment child))
(let ((before (mm-state child)) (cx (mm-cxtm child doc)))
(multiple-value-bind (result resolve) (funcall saved-import target child)
(check (concatenate 'string "mm:" label ":source-preserved:" (write-to-string (length imports)))
(and (equal before (mm-state child)) (equalp cx (mm-cxtm child doc))))
(push (list child resolve before cx) imports)
(values result resolve)))))
(setf map (deserialize-octets raw :document-iri doc :source-key key :max-resource-depth depth
:resource-resolver (lambda (iri &key purpose from-document-iri notation)
(push (list iri purpose from-document-iri notation) calls)
(let ((r (assoc iri resources :test #'equal)))
(values (second r) (third r)))))))
(setf (symbol-function 'topic-maps.xml:parse-octets) saved-parser
(symbol-function 'import-map-content) saved-import))
(setf calls (nreverse calls) parses (nreverse parses) imports (nreverse imports))
(check (concatenate 'string "mm:" label ":raw-octets-qualified-parser")
(and (eq raw (third (first parses)))
(= (length parses) (1+ (length calls)))
(every (lambda (p) (if (equal (first p) doc) (eq (third p) raw)
(let ((r (assoc (first p) resources :test #'equal)))
(and r (equal (or (third r) (first r)) (second p))
(equalp (second r) (third p))
(or (not (typep (second r) '(vector (unsigned-byte 8)))) (eq (second r) (third p))))))) parses)))
(funcall verify map imports calls)
(check (concatenate 'string "mm:" label ":canonical-native-references-EQ") (mm-current-p map))
(dolist (record imports)
(check (format nil "mm:~A:retained-source-~D" label (position record imports :test #'eq))
(and (equal (third record) (mm-state (first record))) (equalp (fourth record) (mm-cxtm (first record) doc)))))
(let ((before (mm-state map)) (cx (mm-cxtm map doc)))
(check (concatenate 'string "mm:" label ":pure-cxtm-and-source-bytes")
(and (equalp cx (mm-cxtm map doc)) (equal before (mm-state map)) (equalp raw root-copy)
(every #'equalp copies (mapcar #'second resources))))
(push (mm-fields "label" label "sourceText" (babel:octets-to-string raw :encoding :utf-8)
"resolverCalls" (coerce (mapcar (lambda (c) (apply #'mm-fields
(list "resourceIRI" (first c) "purpose" (string-downcase (string (second c)))
"fromDocumentIRI" (third c) "notation" (fourth c)))) calls) 'vector)
"qualifiedParserCalls" (length parses) "sourceMapsPreserved" :true
"model" (mm-model map) "actualCXTM" (babel:octets-to-string cx :encoding :utf-8)
"condition" nil) *mergemap-controls*))
map))
(defun mm-positive-tests ()
(dolist (href '("child.xtm" "https://xtm-tests.example.invalid/absolute.xtm" "../%E9%A6%AC.xtm" "child.xtm?mode=one"))
(let* ((child (mm-child-iri href)) (raw (bytes (document "
"))))
(mm-call (concatenate 'string "href:" href)
(document (concatenate 'string (mm-directive href) ""))
(list (list child raw "same-source-label-for-all-documents"))
(lambda (map imports calls)
(check (concatenate 'string "mm:exact-resolver-arguments:" href)
(equal calls (list (list child :mergemap *document* "http://psi.topicmaps.org/iso13250/xtm"))))
(let* ((root-topic (by-id map "topic")) (child-topic (mm-local map child "topic"))
(record (first imports)) (source-topic (first (topic-map-topics (first record)))))
(check (concatenate 'string "mm:document-local-II-and-resolve-EQ:" href)
(and root-topic child-topic (not (eq root-topic child-topic))
(eq child-topic (funcall (second record) source-topic))
(not (eq source-topic child-topic))
(equal (list (concatenate 'string child "#topic")) (item-identifiers child-topic))
(= 1 (length (topic-map-associations map))))))))))
(let* ((child (mm-child-iri)) (raw (bytes (document " 馬 & A V ")))
(source (document (concatenate 'string (mm-directive "child.xtm") "Local")))
(map (mm-call "SI-merge" source (list (list child raw "source-one"))
(lambda (map imports calls) (declare (ignore calls))
(let* ((owner (by-si map "urn:shared")) (record (first imports))
(old (find "urn:shared" (topic-map-topics (first record)) :key (lambda (tpc) (first (topic-subject-identifiers tpc))) :test #'equal)))
(check "mm:SI-merge:imported-handle-resolves-after-later-local-merge"
(and (eq owner (by-id map "b")) (eq owner (mm-local map child "a"))
(eq owner (funcall (second record) old)) (= 2 (length (topic-names owner)))
(equal " V " (variant-value (first (all-variants map))))
(equal "urn:custom" (variant-datatype (first (all-variants map))))))))))
(other (mm-call "source-key-independent" source (list (list child raw "source-two"))
(lambda (&rest ignored) (declare (ignore ignored))) :key "independent-root-key")))
(check "mm:source-key-independent:identical-model-cxtm" (equalp (mm-cxtm map) (mm-cxtm other))))
(dolist (kind '("subjectLocator" "itemIdentity"))
(let ((child (mm-child-iri)))
(mm-call (concatenate 'string "merge-identity:" kind)
(document (format nil "~A<~A href='urn:identity'/>" (mm-directive "child.xtm") kind))
(list (list child (bytes (document (format nil "<~A href='urn:identity'/>" kind))) nil))
(lambda (map imports calls) (declare (ignore calls))
(check (concatenate 'string "mm:merge-identity-EQ:" kind)
(and (= 1 (length (topic-map-topics map))) (eq (by-id map "local") (mm-local map child "child"))
(eq (by-id map "local") (funcall (second (first imports)) (first (topic-map-topics (first (first imports))))))))))))
(let* ((a (mm-child-iri "a.xtm")) (b (mm-child-iri "b.xtm")) (c (mm-child-iri "nested/c.xtm"))
(raw-a (bytes (document (concatenate 'string (mm-directive "nested/c.xtm") ""))))
(raw-b (bytes (document ""))) (raw-c (bytes (document ""))))
(mm-call "nested-multiple-repeated"
(document (concatenate 'string (mm-directive "a.xtm") (mm-directive "b.xtm") (mm-directive "a.xtm") ""))
(list (list a raw-a "a") (list b raw-b "b") (list c raw-c "c"))
(lambda (map imports calls)
(check "mm:nested:document-order-no-global-visited-skip"
(and (= 5 (length imports)) (= 4 (length (topic-map-topics map)))
(equal (mapcar #'first calls) (list a c b a c))
(equal (mapcar #'third calls) (list *document* a *document* *document* a)))))))
;; Public reentrant calls are independent, even inside a caller's resolver.
(let* ((raw (bytes (document ""))) (observed nil)
(map (deserialize-octets (bytes (document (mm-directive "child.xtm"))) :document-iri *document*
:resource-resolver (lambda (&rest args) (declare (ignore args))
(setf observed (deserialize-octets raw :document-iri *document*)) (values raw nil)))))
(check "mm:reentrant-public-call-context-independent"
(and observed (= 1 (length (topic-map-topics map))) (= 1 (length (topic-map-topics observed)))))))
(defun mm-rich-test ()
(let* ((child (mm-child-iri))
(raw (bytes (map-reifier-xml "#map-r" "NV"))))
(mm-call "rich-native-content"
(map-reifier-xml "#root-r" (concatenate 'string "" (mm-directive "child.xtm") ""))
(list (list child raw "rich-child"))
(lambda (map imports calls) (declare (ignore calls))
(let* ((record (first imports)) (source (first record)) (resolve (second record))
(owner (by-si map "urn:owner")) (name (first (topic-names owner))) (v (first (topic-name-variants name)))
(occ (first (topic-occurrences owner)))
(as (find "urn:association" (topic-map-associations map) :test (lambda (id i) (member id (item-identifiers i) :test #'equal)))))
(check "mm:rich:map-metadata-separated-source-reifier-topic-imported-only"
(and (equal '("urn:root-map") (item-identifiers map))
(equal '("urn:child-map") (item-identifiers source))
(eq (by-id map "root-r") (item-reifier map)) (eq map (topic-reified (item-reifier map)))
(not (eq (item-reifier map) (funcall resolve (item-reifier source))))
(null (topic-reified (funcall resolve (item-reifier source))))
(eq source (topic-reified (item-reifier source)))))
(check "mm:rich:all-topic-name-variant-occurrence-role-identities-EQ"
(and (eq owner (by-id map "local")) (eq owner (topic-name-parent name)) (eq name (variant-parent v))
(eq owner (occurrence-parent occ)) (equal "42" (occurrence-value occ))
(equal "urn:occurrence-type" (occurrence-datatype occ))
(equal '("urn:occurrence") (item-identifiers occ))
(equal '("urn:name") (item-identifiers name)) (equal '("urn:variant") (item-identifiers v))
(scope-eq-p (variant-scope v) (list (mm-local map child "base") (mm-local map child "extra")))
(eq v (topic-reified (item-reifier v))) (eq name (topic-reified (item-reifier name)))
(eq occ (topic-reified (item-reifier occ)))
(eq map (association-parent as)) (eq as (topic-reified (item-reifier as)))
(some (lambda (role) (and (eq owner (association-role-player role))
(equal '("urn:role") (item-identifiers role))
(eq role (topic-reified (item-reifier role))))) (association-roles as))))
(check "mm:rich:all-import-resolutions-current-not-shared"
(every (lambda (item) (let ((target (funcall resolve item)))
(and (not (eq item target)) (eq map (topic-maps.tmdm::item-topic-map target))
(eq target (topic-maps.tmdm::canonical-item target)))))
(rest (topic-maps.tmdm::map-information-items source))))))
:augment (lambda (source)
;; Native test setup after real XML deserialization, before the real
;; importer. This does not implement XML occurrences/explicit associations.
(let* ((owner (by-si source "urn:owner")) (type (mm-local source child "type"))
(theme (mm-local source child "extra"))
(occ (add-occurrence owner type "42" :datatype "urn:occurrence-type" :scope (list theme)))
(as (make-association source type (list (list type owner) (list type theme)) :scope (list theme)))
(role (find owner (association-roles as) :key #'association-role-player :test #'eq)))
(loop for item in (list occ as role) for id in '("occurrence" "association" "role") do
(add-item-identifier item (concatenate 'string "urn:" id))
(set-item-reifier item (intern-topic source :item-identifier (concatenate 'string "urn:reifier:" id)))))))))
(defun mm-nested-supported-features ()
(let* ((mid (mm-child-iri "folder/mid.xtm")) (leaf (mm-child-iri "馬.xtm"))
(raw (bytes (document " 馬 & Name V & text ../%E9%A6%ACliteral%GG") :utf-16be t)))
(mm-call "nested-UTF16-supported-elements" (document (mm-directive "folder/mid.xtm"))
(list (list mid (bytes (document (mm-directive "../%E9%A6%AC.xtm"))) "mid") (list leaf raw "leaf-UTF16"))
(lambda (map imports calls) (declare (ignore imports))
(let* ((owner (mm-local map leaf "owner")) (name (first (topic-names owner)))
(variants (topic-name-variants name)) (v (find " V & text " variants :key #'variant-value :test #'equal)))
(check "mm:nested:UTF16-names-variants-values-scopes-types-and-identifiers"
(and (equal (mapcar #'first calls) (list mid leaf))
(equal " 馬 & Name " (topic-name-value name)) (eq owner (topic-name-parent name))
(eq (mm-local map leaf "type") (topic-name-type name))
(equal '("urn:nested-name") (item-identifiers name))
(equal '("urn:nested-variant") (item-identifiers v))
(eq v (topic-reified (mm-local map leaf "vr"))) (eq name (topic-reified (mm-local map leaf "nr")))
(= 4 (length variants))
(every (lambda (i) (scope-eq-p (variant-scope i) (list (mm-local map leaf "base") (mm-local map leaf "extra")))) variants)
(find "literal%GG" variants :key #'variant-value :test #'equal)
(= 2 (count (iri-datatype) variants :key #'variant-datatype :test #'equal))))))))
(let* ((child (mm-child-iri))
(raw (bytes (map-reifier-xml "#child-r" ""))))
(mm-call "map-reifier-topic-identity-merging"
(map-reifier-xml "#root-r" (concatenate 'string "" (mm-directive "child.xtm") ""))
(list (list child raw "source-map"))
(lambda (map imports calls) (declare (ignore calls))
(let* ((record (first imports)) (source (first record)) (r (item-reifier map)))
(check "mm:map-reifier:canonical-identity-merge-does-not-import-source-map-properties"
(and (eq r (by-id map "root-r")) (eq r (mm-local map child "child-r"))
(eq r (funcall (second record) (item-reifier source))) (eq map (topic-reified r))
(eq source (topic-reified (item-reifier source)))
(equal '("urn:target-map-metadata") (item-identifiers map))
(equal '("urn:child-map-metadata") (item-identifiers source)))))))))
(define-condition mm-resolver-denied (error) ())
(defun mm-error (label raw class code &key resolver (depth 32) (doc *document*)
(expected-doc doc) (expected-key label))
(let ((c (condition-from (lambda ()
(deserialize-octets (if (stringp raw) (bytes raw) raw) :document-iri doc :source-key label
:resource-resolver resolver :max-resource-depth depth)))))
(check (concatenate 'string "mm-error:" label ":specific-class-code")
(and (eq (type-of c) class) (eq code (error-code c))))
(check (concatenate 'string "mm-error:" label ":context-and-position")
(and (equal expected-doc (error-document-iri c)) (equal expected-key (error-source-key c))
(or (and (integerp (error-line c)) (integerp (error-column c)))
(and (typep c 'xtm-xml-error) (null (error-line c)) (null (error-column c))))))
(push (mm-fields "label" label "sourceText" (when (stringp raw) raw)
"condition" (mm-condition c) "expectedClass" (string class) "expectedCode" (string-downcase (string code)))
*mergemap-controls*)
c))
(defun mm-negative-tests ()
(let* ((text (document (mm-directive "child.xtm"))) (child (mm-child-iri)) (calls 0)
(resolver (lambda (&rest args) (declare (ignore args)) (incf calls) nil)))
(mm-error "missing-resolver" text 'xtm-unsupported :resource-resolver-required)
(mm-error "declined-resource" text 'topic-maps.xtm:xtm-resource-error :resource-unavailable :resolver resolver)
(check "mm-error:resolver-decline-called-once" (= 1 calls))
(let* ((denied (make-condition 'mm-resolver-denied))
(c (mm-error "denied-resource" text 'topic-maps.xtm:xtm-resource-error :resource-resolver-failure
:resolver (lambda (&rest args) (declare (ignore args)) (error denied)))))
(check "mm-error:resolver-denial-original-cause-EQ" (eq denied (topic-maps.xtm:error-cause c))))
(dolist (spec '(("not bytes" "k") (#(256) "k") (#(-1) "k") (#(1 2) 42) ((1 2) "k")))
(mm-error (format nil "invalid-result:~S" spec) text 'topic-maps.xtm:xtm-resource-error :invalid-resource-result
:resolver (lambda (&rest args) (declare (ignore args)) (values (first spec) (second spec)))))
(dolist (row (list (list "bad-XML" (bytes "") 'xtm-xml-error :xml-not-well-formed)
(list "bad-UTF8" (concatenate '(vector (unsigned-byte 8)) (bytes "") #(195 40) (bytes "")) 'xtm-xml-error :xml-not-well-formed)
(list "empty-octets" (make-array 0 :element-type '(unsigned-byte 8)) 'xtm-xml-error :xml-not-well-formed)
(list "DOCTYPE" (bytes (concatenate 'string "" (document ""))) 'xtm-xml-error :doctype-forbidden)
(list "bad-version" (bytes "") 'xtm-rejection :invalid-version)
(list "bad-namespace" (bytes "") 'xtm-rejection :invalid-namespace)
(list "unknown-structure" (bytes (document "")) 'xtm-rejection :unexpected-element)
(list "anyType-unimplemented" (bytes (document (datatype-body (datatype-resource "http://www.w3.org/2001/XMLSchema#anyType" "V")))) 'xtm-unsupported :resource-data-datatype)
(list "occurrence-XML-still-unsupported" (bytes (document "V")) 'xtm-unsupported :unsupported-construct)))
(destructuring-bind (label raw class code) row
(mm-error label text class code :expected-doc child :expected-key "child-source"
:resolver (lambda (&rest args) (declare (ignore args)) (values raw "child-source")))))
(setf calls 0)
(dolist (row '(("fragment" "" :mergemap-fragment)
("empty-fragment" "" :mergemap-fragment)
("escaped-fragment" "" :mergemap-fragment)
("bad-percent" "" :invalid-percent-escape)
("bad-percent-UTF8" "" :invalid-percent-utf8)
("missing-href" "" :missing-attribute)
("extra-attribute" "" :unexpected-attribute)
("nonempty-element" "" :unexpected-child)
("non-whitespace" "x" :unexpected-text)
("after-topic" "" :element-order)
("identity-after-import" "" :element-order)))
(mm-error (first row) (document (second row)) 'xtm-rejection (third row) :resolver resolver))
(check "mm-error:invalid-syntax-before-any-resolution" (zerop calls))
(mm-error "depth-zero-policy" text 'xtm-unsupported :resource-depth-limit :depth 0 :resolver resolver)
(mm-error "immediate-cycle-policy" (document (mm-directive "")) 'xtm-unsupported :cyclic-mergemap :resolver resolver)
(check "mm-error:root-cycle-and-depth-policy-before-fetch" (zerop calls))
(let ((c (mm-error "indirect-cycle-policy" text 'xtm-unsupported :cyclic-mergemap
:expected-doc child :expected-key "loop-child"
:resolver (lambda (&rest args) (declare (ignore args)) (incf calls)
(values (bytes (document (mm-directive *document*))) "loop-child")))))
(check "mm-error:indirect-cycle-one-fetch-no-normative-PASS"
(and (= 1 calls) (null (find "xtm2/in/mergemap-loop.xtm" *cases* :test #'equal :key #'topic-maps.test-foundation:test-case-id))
(eq :cyclic-mergemap (error-code c)))))
(mm-error "acyclic-depth-policy" text 'xtm-unsupported :resource-depth-limit :depth 1
:expected-doc child :expected-key "depth-child"
:resolver (lambda (&rest args) (declare (ignore args))
(values (bytes (document (mm-directive "grand.xtm"))) "depth-child"))))
;; Generic vector octets are specialized only in storage, never text-decoded.
(let ((child (mm-child-iri)))
(mm-call "generic-octet-vector" (document (mm-directive "child.xtm"))
(list (list child (map 'vector #'identity (bytes (document ""))) nil))
(lambda (map imports calls) (declare (ignore imports calls))
(check "mm:generic-octets-fallback-key" (not (null (mm-local map child "a"))))))))
(defun mm-import-conflict-tests ()
(dolist (kind '("identifier" "reifier"))
(let* ((saved (symbol-function 'import-map-content)) (native nil) (target nil) (source nil) (tb nil) (sb nil)
(body (if (equal kind "identifier")
""
""))
(parent (if (equal kind "identifier") (document body) (map-reifier-xml "#r" body)))
(child-raw (bytes (document (if (equal kind "identifier")
""
(format nil "N" *document*)))))
(c nil))
(unwind-protect
(progn
(setf (symbol-function 'import-map-content)
(lambda (a b)
(setf target a source b tb (mm-state a) sb (mm-state b))
(handler-case (funcall saved a b) (error (e) (setf native e) (error e)))))
(setf c (mm-error (concatenate 'string "native-import-conflict:" kind) parent
'topic-maps.xtm:xtm-resource-error :mergemap-import-failure
:resolver (lambda (&rest args) (declare (ignore args)) (values child-raw "conflicting-child")))))
(setf (symbol-function 'import-map-content) saved))
(check (concatenate 'string "mm-error:native-import-cause-and-atomic-graphs:" kind)
(and (eq native (topic-maps.xtm:error-cause c))
(if (equal kind "identifier")
(and (typep native 'item-identifier-error) (eq :duplicate-item-identifier (item-identifier-error-code native)))
(and (typep native 'reification-error) (eq :reifier-conflict (reification-error-code native))))
(equal tb (mm-state target)) (equal sb (mm-state source)))))))
(defun mm-original-observations ()
(let* ((id "xtm2/in/mergemap-itemid.xtm")
(*document* (concatenate 'string "https://xtm-tests.example.invalid/cd165b150176c1d6842b37be9cc9051b40d4996b/" id))
(raw (file-bytes (corpus-path id))) (child (mm-child-iri "mergemap-itemid.sub"))
(child-raw (file-bytes (corpus-path "xtm2/in/mergemap-itemid.sub")))
(expected (file-bytes (corpus-path "xtm2/baseline/mergemap-itemid.xtm.cxtm")))
(map (mm-call "original:mergemap-itemid" raw (list (list child child-raw "xtm2/in/mergemap-itemid.sub"))
(lambda (map imports calls)
(check "mm-original:exact-resource-and-map-item-identity-separation"
(and (= 148 (length raw)) (= 151 (length child-raw))))
(check "mm-original:only-two-document-local-topics-no-map-metadata"
(and (equal calls (list (list child :mergemap *document* "http://psi.topicmaps.org/iso13250/xtm")))
(= 2 (length (topic-map-topics map))) (null (topic-map-associations map))
(null (item-identifiers map)) (null (item-reifier map))
(not (eq (by-id map "topic") (mm-local map child "topic")))
(equal (list (concatenate 'string child "#the-topic-map")) (item-identifiers (first (first imports)))))))))
(actual (mm-cxtm map)) (text (babel:octets-to-string expected :encoding :utf-8))
(topic-start (search "~%") (subseq text topic-start))))
(check "mm-original:exact-baseline-difference-is-root-map-II-only"
(and (= 314 (length expected)) (not (equalp actual expected))
(equal without-map-metadata (babel:octets-to-string actual :encoding :utf-8))))
(check "mm-original:registered-status-remains-NOT-RUN"
(null (find id *cases* :key #'topic-maps.test-foundation:test-case-id :test #'equal)))
(push (mm-fields "id" id "documentIRI" *document* "sourceBytes" (length raw)
"sourceHex" (format nil "~{~2,'0X~}" (coerce raw 'list)) "sourceText" (babel:octets-to-string raw :encoding :utf-8)
"childIRI" child "childBytes" (length child-raw) "childHex" (format nil "~{~2,'0X~}" (coerce child-raw 'list))
"model" (mm-model map) "targetMapItemIdentifiers" (coerce (item-identifiers map) 'vector)
"sourceMapItemIdentifiers" (vector (concatenate 'string child "#the-topic-map"))
"actualCXTM" (babel:octets-to-string actual :encoding :utf-8) "expectedCXTM" text
"actualBytes" (length actual) "expectedBytes" (length expected) "firstDifferentByte" (mismatch actual expected)
"condition" nil "byteExact" :false "onlyBaselineRootMapItemIdentifiersDiffer" :true
"registeredStatus" "not-run" "registeredAsPASS" :false) *mergemap-originals*))
(let* ((id "xtm2/in/mergemap-loop.xtm")
(*document* (concatenate 'string "https://xtm-tests.example.invalid/cd165b150176c1d6842b37be9cc9051b40d4996b/" id))
(child (mm-child-iri "mergemap-loop.sub")) (calls 0)
(c (mm-error "original-cycle-policy-not-normative-PASS" (file-bytes (corpus-path id))
'xtm-unsupported :cyclic-mergemap :expected-doc child :expected-key "xtm2/in/mergemap-loop.sub"
:resolver (lambda (iri &rest args) (declare (ignore args)) (incf calls)
(assert (equal child iri))
(values (file-bytes (corpus-path "xtm2/in/mergemap-loop.sub")) "xtm2/in/mergemap-loop.sub")))))
(check "mm-original:cycle-finite-one-fetch-no-registration" (and (= 1 calls) (null (find id *cases* :key #'topic-maps.test-foundation:test-case-id :test #'equal))))
(push (mm-fields "id" id "documentIRI" *document* "condition" (mm-condition c)
"registeredStatus" "not-run" "registeredAsPASS" :false "normativeCycleDecision" nil "resolverCalls" calls) *mergemap-originals*)))
(defun mergemap-tests ()
(setf *mergemap-controls* nil *mergemap-originals* nil)
(mm-positive-tests) (mm-rich-test) (mm-nested-supported-features) (mm-negative-tests) (mm-import-conflict-tests) (mm-original-observations)
(setf *mergemap-controls* (nreverse *mergemap-controls*) *mergemap-originals* (nreverse *mergemap-originals*)))