X-Git-Url: https://dreyeck.freedombox.rocks/gitweb/topic-maps.git/blobdiff_plain/1c0b92c68fe1114b926d4405b553dfb096d2f425..85dca09c41c7d4a8ecea00cc2b474f74b2dbe6fa:/tests/xtm-variant-reification.lisp
diff --git a/tests/xtm-variant-reification.lisp b/tests/xtm-variant-reification.lisp
index 2540659..e806a26 100644
--- a/tests/xtm-variant-reification.lisp
+++ b/tests/xtm-variant-reification.lisp
@@ -237,7 +237,7 @@
(variant-reifier-error-control (first row) (format nil "~A" (variant-name-xml nil (second row))) 'xtm-rejection (third row)))
(variant-reifier-error-control "XML" "N" 'xtm-xml-error :xml-not-well-formed)
(variant-reifier-error-control "occurrence-reification-excluded"
- "O" 'xtm-unsupported :unsupported-construct)
+ "O" 'xtm-unsupported :resource-data-datatype)
(dolist (row '(("variant-II-reifier-II" "NV")
("name-II-reifier-II" "NV")
("map-II-reifier-II" "NV")))
@@ -280,3 +280,129 @@
(defun variant-reifier-tests ()
(variant-reifier-value-tests) (variant-reifier-merge-tests) (variant-reifier-syntax-conflict-tests))
+
+;; Slice 22B: the unchanged duplicate-Name original uses the same executor,
+;; Case Records and model serializers as the two Slice-21O originals above.
+(defun variant-reifier-followup-original-contract ()
+ (let* ((id "xtm2/in/variant-duplicate-reifier2.xtm")
+ (*document* (concatenate 'string "https://xtm-tests.example.invalid/cd165b150176c1d6842b37be9cc9051b40d4996b/" id))
+ (label "variant-reifier-original:variant-duplicate-reifier2")
+ (raw (file-bytes (corpus-path id))) (copy (copy-seq raw))
+ (baseline (corpus-path "xtm2/baseline/variant-duplicate-reifier2.xtm.cxtm"))
+ (expected (file-bytes baseline))
+ (case (topic-maps.test-foundation:make-test-case :id id :category :valid :source-pathname (corpus-path id)
+ :document-iri *document* :expected-outcome :cxtm-equal :expected-baseline baseline
+ :clauses '("XTM 2.0 4.3.2,4.10-4.13,4.16" "TMDM 5.4-5.5,6.3-6.4" "CXTM 3,4")))
+ (map nil) (actual nil) (condition nil) (root nil) (calls 0) (same nil)
+ (names nil) (pairs nil) (proof nil))
+ (check (concatenate 'string label ":not-previously-registered")
+ (not (find id *cases* :key #'topic-maps.test-foundation:test-case-id :test #'equal)))
+ (setf *cases* (append *cases* (list case)))
+ (handler-case
+ (progn
+ ;; Passive observers retain actual handles from this public import.
+ ;; Restore every function even if XML, reader or model execution fails.
+ (let ((parse (symbol-function 'topic-maps.xml:parse-octets))
+ (read-name (symbol-function 'topic-maps.xtm::read-name))
+ (normalize (symbol-function 'topic-maps.tmdm::normalize-variants)))
+ (unwind-protect
+ (progn
+ (setf (symbol-function 'topic-maps.xml:parse-octets)
+ (lambda (source handler) (incf calls) (setf same (eq raw source))
+ (setf root (funcall parse source handler))))
+ (setf (symbol-function 'topic-maps.xtm::read-name)
+ (lambda (node owner result)
+ (let ((name (funcall read-name node owner result))) (push name names) name)))
+ (setf (symbol-function 'topic-maps.tmdm::normalize-variants)
+ (lambda (result)
+ (let ((held (all-variants result)))
+ (when (= 2 (length held)) (push (copy-list held) pairs)))
+ (funcall normalize result)))
+ (setf map (deserialize-octets raw :document-iri *document* :source-key id)))
+ (setf (symbol-function 'topic-maps.xml:parse-octets) parse
+ (symbol-function 'topic-maps.xtm::read-name) read-name
+ (symbol-function 'topic-maps.tmdm::normalize-variants) normalize)))
+ (check (concatenate 'string label ":qualified-parser-once-original-octets-eq") (and (= calls 1) same))
+ (let* ((source-topics (topic-maps.xtm::elements root)) (source-topic (first source-topics))
+ (source-names (topic-maps.xtm::elements source-topic))
+ (owner (by-id map "topic")) (name (first (topic-names owner)))
+ (v (first (all-variants map))) (r (by-id map "reifier"))
+ (theme (by-id map "command")) (type (by-si map (default-name-type-identifier)))
+ (held (first pairs)))
+ (check (concatenate 'string label ":543-byte-original-two-names-two-reified-variants")
+ (and (= 543 (length raw)) (= 1 (length source-topics))
+ (equal "topic" (topic-maps.xtm::attr source-topic "id")) (= 2 (length source-names))
+ (every (lambda (n)
+ (let* ((kids (topic-maps.xtm::elements n)) (variant (second kids))
+ (vkids (topic-maps.xtm::elements variant)))
+ (and (equal "name" (topic-maps.xtm::node-name n)) (null (topic-maps.xtm::node-attributes n))
+ (equal '("value" "variant") (mapcar #'topic-maps.xtm::node-name kids))
+ (equal '("Topic") (topic-maps.xtm::node-children (first kids)))
+ (equal "#reifier" (topic-maps.xtm::attr variant "reifier"))
+ (= 1 (length (topic-maps.xtm::node-attributes variant)))
+ (equal '("scope" "resourceData") (mapcar #'topic-maps.xtm::node-name vkids))
+ (= 1 (length (topic-maps.xtm::elements (first vkids))))
+ (equal "#command" (topic-maps.xtm::attr (first (topic-maps.xtm::elements (first vkids))) "href"))
+ (null (topic-maps.xtm::node-attributes (second vkids)))
+ (equal '("TOPIC!") (topic-maps.xtm::node-children (second vkids)))))) source-names)))
+ (check (concatenate 'string label ":one-native-name-variant-parent-type-scope-eq")
+ (and (= 4 (length (topic-map-topics map))) (null (topic-map-associations map))
+ (= 1 (length (name-reifier-names map))) (= 1 (length (all-variants map)))
+ (every (lambda (topic) (eq map (topic-parent topic))) (topic-map-topics map))
+ (eq owner (topic-name-parent name)) (eq name (canonical-topic-name name))
+ (eq type (topic-name-type name)) (equal "Topic" (topic-name-value name)) (null (topic-name-scope name))
+ (eq name (variant-parent v)) (eq v (canonical-variant v))
+ (scope-eq-p (list theme) (variant-scope v)) (variant-reifier-current-p map)))
+ (check (concatenate 'string label ":verbatim-value-string-datatype-and-canonical-reifier-inverse-eq")
+ (and (equal "TOPIC!" (variant-value v)) (equal (string-datatype) (variant-datatype v))
+ (eq r (canonical-topic r)) (eq r (item-reifier v)) (eq v (topic-reified r))
+ (null (item-reifier map)) (null (item-reifier name))
+ (every (lambda (topic) (null (topic-reified topic))) (list owner theme type))))
+ (check (concatenate 'string label ":complete-separated-identifiers")
+ (and (null (item-identifiers map)) (null (item-identifiers name)) (null (item-identifiers v))
+ (null (item-identifiers type)) (equal (list (default-name-type-identifier)) (topic-subject-identifiers type))
+ (null (topic-subject-locators type))
+ (every (lambda (pair)
+ (and (equal (list (concatenate 'string *document* "#" (cdr pair))) (item-identifiers (car pair)))
+ (null (topic-subject-identifiers (car pair))) (null (topic-subject-locators (car pair)))))
+ (list (cons owner "topic") (cons theme "command") (cons r "reifier")))
+ (every (lambda (topic) (and (null (topic-occurrences topic)) (null (topic-roles-played topic))))
+ (topic-map-topics map))))
+ (check (concatenate 'string label ":retained-pre-normalization-variant-and-name-handles-canonical-eq")
+ (and (= 2 (length names)) (every (lambda (old) (eq name (canonical-topic-name old))) names)
+ (= 1 (length pairs)) (= 2 (length held)) (not (eq (first held) (second held)))
+ (every (lambda (old) (eq v (canonical-variant old))) held)
+ (some (lambda (old) (not (eq v old))) held)
+ (every (lambda (old) (and (eq name (variant-parent old)) (eq r (item-reifier old))
+ (eq (canonical-variant old) (topic-reified r)))) held)))
+ (setf proof (topic-maps.test-foundation::fields
+ "sourceNameCalls" (length names) "sameRawNameHandleEQ" (if (eq (first names) (second names)) :true :false)
+ "preNormalizationPairs" (length pairs) "distinctRetainedVariantHandles" (length held)
+ "retainedNameCanonicalEQ" :true "retainedVariantCanonicalEQ" :true
+ "variantReplacementObserved" :true "canonicalParentScopeReifierInverseEQ" :true))
+ (setf actual (variant-reifier-pure "duplicate-name-original" map (append held names (list owner r theme type))))
+ (check (concatenate 'string label ":original-source-and-baseline-preserved")
+ (and (equalp raw copy) (= 702 (length expected)) (equalp expected (file-bytes baseline))))
+ (let ((other (deserialize-octets raw :document-iri *document* :source-key "independent:duplicate-name-variant-reifier")))
+ (check (concatenate 'string label ":source-key-independent-model-and-cxtm")
+ (and (equalp (variant-reifier-model-data map) (variant-reifier-model-data other))
+ (equalp actual (topic-maps.cxtm:canonicalize-octets other :base-locator *document*)))))))
+ (error (c) (setf condition c)))
+ (record-original-result case actual expected condition)
+ (setf *variant-reifier-outputs* (append *variant-reifier-outputs* (list
+ (topic-maps.test-foundation::fields "id" id "documentIRI" *document* "sourceKey" id
+ "sourceBytes" (length raw) "sourceHex" (format nil "~{~2,'0X~}" (coerce raw 'list))
+ "sourceText" (babel:octets-to-string raw :encoding :utf-8) "sourceNameCount" 2 "sourceVariantCount" 2
+ "primaryQualifiedParserCalls" calls "nativeHandleObservation" proof
+ "model" (when map (variant-reifier-model-data map)) "condition" (map-reifier-condition-data condition)
+ "actualCXTM" (when actual (babel:octets-to-string actual :encoding :utf-8))
+ "expectedCXTM" (babel:octets-to-string expected :encoding :utf-8)
+ "actualBytes" (when actual (length actual)) "expectedBytes" (length expected)
+ "firstDifferentByte" (when actual (mismatch actual expected))
+ "status" (string-downcase (string (topic-maps.test-foundation:test-case-status case)))))))
+ (when condition (error condition))
+ (check (concatenate 'string label ":byte-exact") (equalp actual expected))
+ (check "variant-reifier-followup:71-unique-records-exactly-one-additional-positive"
+ (and (= 71 (length *cases*)) (= 63 (count :valid *cases* :key #'topic-maps.test-foundation:test-case-category))
+ (= 8 (count :invalid *cases* :key #'topic-maps.test-foundation:test-case-category))
+ (= 71 (length (remove-duplicates *cases* :key #'topic-maps.test-foundation:test-case-id :test #'equal)))))))