(in-package #:topic-maps.ctm.tests) (defvar *last-scope-checks* nil) (defvar *scope-observations* nil) (defvar *scope-order-witness* nil) (defun scope-checks () *last-scope-checks*) (defun scope-of (item) (etypecase item (topic-maps.tmdm:topic-name (topic-maps.tmdm:topic-name-scope item)) (topic-maps.tmdm:occurrence (topic-maps.tmdm:occurrence-scope item)) (topic-maps.tmdm:association (topic-maps.tmdm:association-scope item)))) (defun raw-scope (item) (etypecase item (topic-maps.tmdm:topic-name (topic-maps.tmdm::%topic-name-scope item)) (topic-maps.tmdm:occurrence (topic-maps.tmdm::%occurrence-scope item)) (topic-maps.tmdm:association (topic-maps.tmdm::%association-scope item)))) (defun (setf raw-scope) (value item) (etypecase item (topic-maps.tmdm:topic-name (setf (topic-maps.tmdm::%topic-name-scope item) value)) (topic-maps.tmdm:occurrence (setf (topic-maps.tmdm::%occurrence-scope item) value)) (topic-maps.tmdm:association (setf (topic-maps.tmdm::%association-scope item) value)))) (defun current-scoped-item (item) (etypecase item (topic-maps.tmdm:topic-name (topic-maps.tmdm:canonical-topic-name item)) (topic-maps.tmdm:occurrence (topic-maps.tmdm:canonical-occurrence item)) (topic-maps.tmdm:association (topic-maps.tmdm:canonical-association item)))) (defun scoped-items (map) (append (mapcan #'topic-names (topic-map-topics map)) (all-occurrences map) (topic-maps.tmdm:topic-map-associations map))) (defun new-scoped-item (kind map owner type themes) (ecase kind (:name (topic-maps.tmdm:add-name owner "Name" :type type :scope themes)) (:occurrence (topic-maps.tmdm:add-occurrence owner type "Value" :scope themes)) (:association (topic-maps.tmdm:make-association map type (list (list type owner)) :scope themes)))) (defun scope-ref-invariants (map) (every (lambda (item) (let ((scope (raw-scope item))) (and (= (length scope) (length (remove-duplicates scope :test #'eq))) (every (lambda (theme) (and (eq theme (topic-maps.tmdm:canonical-topic theme)) (member theme (topic-map-topics map) :test #'eq) (eq map (topic-parent theme)))) scope)))) (scoped-items map))) (defun scope-handle-state (handles) (mapcar (lambda (item) (list item (current-scoped-item item) (copy-list (raw-scope item)) (copy-list (raw-scope (current-scoped-item item))))) handles)) (defun scope-observation (map) (let ((topics (topic-map-topics map))) (labels ((ordinal (topic) (1+ (position topic topics :test #'eq))) (item (object kind parent type &optional value datatype roles) (topic-maps.test-foundation::fields "kind" kind "parent" parent "typeTopicOrdinal" (ordinal type) "value" value "datatype" datatype "scopeTopicOrdinals" (topic-maps.test-foundation::json-array (mapcar #'ordinal (scope-of object))) "roles" (topic-maps.test-foundation::json-array roles)))) (topic-maps.test-foundation::fields "topics" (topic-maps.test-foundation::json-array (loop for topic in topics collect (topic-maps.test-foundation::fields "ordinal" (ordinal topic) "itemIdentifiers" (topic-maps.test-foundation::json-array (topic-item-identifiers topic)) "subjectIdentifiers" (topic-maps.test-foundation::json-array (topic-subject-identifiers topic)) "subjectLocators" (topic-maps.test-foundation::json-array (topic-subject-locators topic))))) "items" (topic-maps.test-foundation::json-array (append (loop for owner in topics append (append (loop for n in (topic-names owner) collect (item n "name" (ordinal (topic-name-parent n)) (topic-name-type n) (topic-name-value n))) (loop for o in (topic-maps.tmdm:topic-occurrences owner) collect (item o "occurrence" (ordinal (topic-maps.tmdm:occurrence-parent o)) (topic-maps.tmdm:occurrence-type o) (topic-maps.tmdm:occurrence-value o) (topic-maps.tmdm:occurrence-datatype o))))) (loop for a in (topic-maps.tmdm:topic-map-associations map) collect (item a "association" (if (eq map (topic-maps.tmdm:association-parent a)) "map" "wrong") (topic-maps.tmdm:association-type a) nil nil (loop for r in (topic-maps.tmdm:association-roles a) collect (topic-maps.test-foundation::fields "parentIsAssociation" (if (eq a (topic-maps.tmdm:association-role-parent r)) :true :false) "playerTopicOrdinal" (ordinal (topic-maps.tmdm:association-role-player r)) "typeTopicOrdinal" (ordinal (topic-maps.tmdm:association-role-type r)))))))))))) (defun scope-original-cases () (setf *scope-observations* nil) (dolist (file '("name-scope" "occurrence-scope" "association-scope")) (let* ((id (format nil "ctm/in/~A.ctm" file)) (case (first (topic-maps.test-foundation:select-cases *cxtm-corpus* :id id))) (doc (topic-maps.test-foundation:test-case-document-iri case)) (map (deserialize-file (topic-maps.test-foundation:test-case-source-pathname case) :document-iri doc :source-name id)) (item (first (scoped-items map))) (themes (list (local-topic map "theme1" doc) (local-topic map "theme2" doc))) (before (map-state map)) (actual (topic-maps.cxtm:canonicalize-octets map :base-locator doc)) (expected (binary-file (topic-maps.test-foundation:test-case-expected-baseline case))) (difference (mismatch actual expected))) (check (concatenate 'string id ":theme-object-identity") (and (every #'identity themes) (= 2 (length (scope-of item))) (every (lambda (theme) (member theme (scope-of item) :test #'eq)) themes))) (check (concatenate 'string id ":required-items-only") (and (= (if (search "association" file) 5 4) (length (topic-map-topics map))) (= 1 (length (scoped-items map))))) (check (concatenate 'string id ":raw-scope-references") (scope-ref-invariants map)) (check (concatenate 'string id ":parent-type-player-identity") (cond ((search "association" file) (let ((role (first (topic-maps.tmdm:association-roles item)))) (and (eq map (topic-maps.tmdm:association-parent item)) (eq (local-topic map "assoctype" doc) (topic-maps.tmdm:association-type item)) (eq item (topic-maps.tmdm:association-role-parent role)) (eq (local-topic map "roletype" doc) (topic-maps.tmdm:association-role-type role)) (eq (local-topic map "topic" doc) (topic-maps.tmdm:association-role-player role))))) ((search "occurrence" file) (and (eq (local-topic map "topic" doc) (topic-maps.tmdm:occurrence-parent item)) (eq (local-topic map "occtype" doc) (topic-maps.tmdm:occurrence-type item)))) (t (and (eq (local-topic map "topic" doc) (topic-name-parent item)) (equal (list (default-name-type-identifier)) (topic-subject-identifiers (topic-name-type item))))))) (check (concatenate 'string id ":byte-exact-cxtm") (null difference)) (check (concatenate 'string id ":pure-canonicalization") (equal before (map-state map))) (topic-maps.test-foundation:record-result case (if difference :cxtm-mismatch :cxtm-match)) (setf (topic-maps.test-foundation:test-case-clauses case) '("CTM 3.3.7" "CTM 3.3.9" "CTM 3.10-3.13" "TMDM 4.3" "TMDM 5.3.3-5.7" "TMDM 6.1-6.6" "CXTM 3.6" "CXTM 3.8-3.9" "CXTM 3.12" "CXTM 4.4-4.11")) (setf *cxtm-results* (append *cxtm-results* (list (list :id id :base doc :actual (cxtm map doc) :expected (uiop:read-file-string (topic-maps.test-foundation:test-case-expected-baseline case) :external-format :utf-8) :match (null difference) :bytes (length actual))))) (push (topic-maps.test-foundation::fields "id" id "documentIRI" doc "ctmSource" (uiop:read-file-string (topic-maps.test-foundation:test-case-source-pathname case) :external-format :utf-8) "actualObjects" (scope-observation map)) *scope-observations*) (format t "~&SCOPE-CXTM ~A: ~A (~D bytes)~%" id (topic-maps.test-foundation:test-case-status case) (length actual)))) (setf *scope-observations* (nreverse *scope-observations*))) (defun scope-api-tests () (dolist (kind '(:name :occurrence :association)) (let* ((map (topic-maps.tmdm:make-topic-map)) (owner (api-topic map "owner")) (type (api-topic map "type")) (a (api-topic map "a")) (b (api-topic map "b")) (input (list a b a)) (empty (new-scoped-item kind map owner type nil)) (one (new-scoped-item kind map owner type (list a))) (two (new-scoped-item kind map owner type input)) (duplicate (new-scoped-item kind map owner type (list b a b)))) (check (format nil "scope-api:~A:empty-single-multiple" kind) (and (null (scope-of empty)) (= 1 (length (scope-of one))) (= 2 (length (scope-of two))))) (check (format nil "scope-api:~A:equal-sets-merge" kind) (eq (current-scoped-item two) (current-scoped-item duplicate))) (check (format nil "scope-api:~A:unequal-scopes-distinct" kind) (and (= 3 (length (scoped-items map))) (not (eq (current-scoped-item empty) (current-scoped-item one))))) (setf (first input) owner) (let ((output (scope-of two))) (setf (first output) type)) (check (format nil "scope-api:~A:defensive-copy" kind) (and (member a (scope-of two) :test #'eq) (member b (scope-of two) :test #'eq) (not (member owner (scope-of two) :test #'eq)) (not (member type (scope-of two) :test #'eq)))) (let* ((foreign-map (topic-maps.tmdm:make-topic-map)) (foreign (api-topic foreign-map "foreign")) (cycle (list a)) (state (map-state map))) (setf (cdr cycle) cycle) (loop for bad in (list a (vector a) (cons a b) cycle (list "theme") (list a foreign)) for code in '(:invalid-scope :invalid-scope :invalid-scope :invalid-scope :invalid-theme :foreign-theme) for index from 0 do (let ((condition (handler-case (progn (new-scoped-item kind map owner type bad) nil) (topic-maps.tmdm:scope-error (c) c)))) (check (format nil "scope-api:~A:invalid-argument:~D" kind index) (and condition (eq code (topic-maps.tmdm:scope-error-code condition)) (equal state (map-state map))))))) (check (format nil "scope-api:~A:canonical-reference-invariants" kind) (scope-ref-invariants map)))) ;; Invalid scope must not synthesize a default type before rejecting the call. (let* ((map (topic-maps.tmdm:make-topic-map)) (owner (api-topic map "owner")) (before (map-state map))) (check "scope-api:default-name-invalid-before-any-mutation" (and (handler-case (progn (topic-maps.tmdm:add-default-name owner "Bad" :scope '("not a Topic")) nil) (topic-maps.tmdm:scope-error () t)) (equal before (map-state map))))) ;; Existing identifier uniqueness must distinguish unequal Occurrence scopes. (let* ((map (topic-maps.tmdm:make-topic-map)) (owner (api-topic map "owner")) (type (api-topic map "type")) (a (api-topic map "a")) (b (api-topic map "b"))) (topic-maps.tmdm:add-occurrence owner type "Value" :scope (list a) :item-identifiers '("urn:o")) (let ((state (map-state map))) (check "scope-api:occurrence-identifier-collision-before-mutation" (and (eq :duplicate-item-identifier (topic-maps.tmdm:occurrence-error-code (occurrence-condition (lambda () (topic-maps.tmdm:add-occurrence owner type "Value" :scope (list b) :item-identifiers '("urn:o")))))) (equal state (map-state map))))))) (defun scope-merge-tests () ;; Merging two themes reduces {a,b} to {c}, making two formerly distinct items equal. (dolist (kind '(:name :occurrence :association)) (dolist (reverse '(nil t)) (let* ((map (topic-maps.tmdm:make-topic-map)) (owner (api-topic map "owner")) (type (api-topic map "type")) (a (api-topic map "a")) (b (api-topic map "b")) (z (api-topic map "z")) (one (new-scoped-item kind map owner type (list a))) (two (new-scoped-item kind map owner type (list a b))) (three (new-scoped-item kind map owner type (list a b z))) (roles (when (eq kind :association) (append (topic-maps.tmdm:association-roles one) (topic-maps.tmdm:association-roles two)))) (handles (list one two three)) (theme (if reverse (topic-maps.tmdm:merge-topics b a) (topic-maps.tmdm:merge-topics a b))) (live (current-scoped-item one))) (check (format nil "scope-merge:~A:~A:cardinality-two-to-one" kind reverse) (and (equal (list theme) (scope-of one)) (equal (list theme) (raw-scope live)) (eq theme (topic-maps.tmdm:canonical-topic a)) (eq theme (topic-maps.tmdm:canonical-topic b)))) (check (format nil "scope-merge:~A:~A:duplicate-item-replacement" kind reverse) (and (eq live (current-scoped-item two)) (not (eq live one)) (not (eq live two)) (= 2 (length (scoped-items map))))) (check (format nil "scope-merge:~A:~A:cardinality-three-to-two" kind reverse) (and (= 2 (length (scope-of three))) (member theme (scope-of three) :test #'eq) (member z (scope-of three) :test #'eq) (not (eq live (current-scoped-item three))))) (check (format nil "scope-merge:~A:~A:retained-roles" kind reverse) (every (lambda (r) (let ((current (topic-maps.tmdm:canonical-association-role r))) (and (eq live (topic-maps.tmdm:association-role-parent r)) (member current (topic-maps.tmdm:association-roles live) :test #'eq)))) roles)) (let ((added (new-scoped-item kind map owner type (list b a b)))) (check (format nil "scope-merge:~A:~A:old-theme-handles-on-new-items" kind reverse) (eq (current-scoped-item added) (current-scoped-item one)))) (let ((state (map-state map)) (old (scope-handle-state handles)) (role-state (loop for r in roles collect (list r (topic-maps.tmdm::%association-role-forward r) (topic-maps.tmdm::%association-role-parent r))))) (cxtm map) (cxtm map) (check (format nil "scope-merge:~A:~A:pure-including-retired-handles" kind reverse) (and (equal state (map-state map)) (equal old (scope-handle-state handles)) (equal role-state (loop for r in roles collect (list r (topic-maps.tmdm::%association-role-forward r) (topic-maps.tmdm::%association-role-parent r))))))) (check (format nil "scope-merge:~A:~A:stored-reference-integrity" kind reverse) (scope-ref-invariants map))))) (let* ((map (topic-maps.tmdm:make-topic-map)) (owner (api-topic map "owner")) (type (api-topic map "type")) (a (api-topic map "theme-a")) (b (api-topic map "theme-b")) (one (topic-maps.tmdm:add-occurrence owner type "Value" :scope (list a) :item-identifiers '("urn:o:one"))) (two (topic-maps.tmdm:add-occurrence owner type "Value" :scope (list a b) :item-identifiers '("urn:o:two")))) (topic-maps.tmdm:merge-topics a b) (check "scope-merge:occurrence-identifiers-unioned-without-changing-category" (and (eq (current-scoped-item one) (current-scoped-item two)) (equal '("urn:o:one" "urn:o:two") (sort (topic-maps.tmdm:occurrence-item-identifiers one) #'string<)) (= 1 (length (all-occurrences map))) (notany (lambda (topic) (member "urn:o:one" (topic-item-identifiers topic) :test #'equal)) (topic-map-topics map))))) ;; A theme may simultaneously be Parent, Type, Role Type and Role Player. (dolist (kind '(:name :occurrence :association)) (let* ((map (topic-maps.tmdm:make-topic-map)) (a (api-topic map "a")) (b (api-topic map "b")) (one (new-scoped-item kind map a a (list a))) (two (new-scoped-item kind map a a (list a b))) (roles (when (eq kind :association) (append (topic-maps.tmdm:association-roles one) (topic-maps.tmdm:association-roles two)))) (c (topic-maps.tmdm:merge-topics a b)) (live (current-scoped-item one))) (check (format nil "scope-merge:~A:simultaneous-parent-type-player-theme" kind) (and (eq live (current-scoped-item two)) (equal (list c) (raw-scope live)) (ecase kind (:name (and (eq c (topic-name-parent one)) (eq c (topic-name-type one)))) (:occurrence (and (eq c (topic-maps.tmdm:occurrence-parent one)) (eq c (topic-maps.tmdm:occurrence-type one)))) (:association (and (eq c (topic-maps.tmdm:association-type one)) (every (lambda (r) (and (eq c (topic-maps.tmdm:association-role-type r)) (eq c (topic-maps.tmdm:association-role-player r)) (eq live (topic-maps.tmdm:association-role-parent r)))) roles)))))))) ;; Every permutation of three theme merges exercises transitive forwarding and set collapse. (dolist (order (permutations '(0 1 2))) (let* ((map (topic-maps.tmdm:make-topic-map)) (owner (api-topic map "owner")) (type (api-topic map "type")) (themes (loop for i below 3 collect (api-topic map (format nil "theme:~D" i)))) (items (loop for kind in '(:name :occurrence :association) collect (new-scoped-item kind map owner type themes)))) (topic-maps.tmdm:merge-topics (nth (first order) themes) (nth (second order) themes)) (topic-maps.tmdm:merge-topics (nth (second order) themes) (nth (third order) themes)) (check (format nil "scope-transitive:~S:all-live-references" order) (and (scope-ref-invariants map) (every (lambda (item) (equal (list (topic-maps.tmdm:canonical-topic (first themes))) (scope-of item))) items))))) ;; Scope can alias Parent/Type; default-type interning may itself merge a theme. (let* ((map (topic-maps.tmdm:make-topic-map)) (owner (topic-maps.tmdm:intern-topic map :item-identifier (default-name-type-identifier))) (name (topic-maps.tmdm:add-name owner "Self" :scope (list owner)))) (check "scope-default-type-interning-canonicalizes-parent-type-theme" (let ((c (topic-maps.tmdm:canonical-topic owner))) (and (eq c (topic-name-parent name)) (eq c (topic-name-type name)) (equal (list c) (raw-scope name)) (scope-ref-invariants map)))))) (defun scope-reader-tests () (dolist (text '("a - \"N\"@theme." "a t:\"V\"@theme." "t(r: a)@theme")) (check (concatenate 'string "scope-reader:adjacent-punctuation:" text) (let* ((map (read-text text)) (scope (scope-of (first (scoped-items map))))) (equal (list (local-topic map "theme")) scope)))) (dolist (tail '("- \"N\"" "t:\"V\"")) (let* ((map (read-text (format nil "a ~A@b,a,b; ~A@a,b." tail tail))) (items (scoped-items map))) (check (concatenate 'string "scope-reader:full-scope-before-item-creation:" tail) (and (= 1 (length items)) (= 2 (length (scope-of (first items)))))))) (let ((map (read-text "t(r: a)@b,a,b t(r: a)@a,b"))) (check "scope-reader:association-full-scope-before-duplicate-removal" (= 1 (length (scoped-items map))))) (let* ((map (read-text "t(r: a, s: b)@theme2,theme1")) (a (first (topic-maps.tmdm:topic-map-associations map)))) (check "scope-reader:binary-association-role-and-scope-boundaries" (and (= 2 (length (topic-maps.tmdm:association-roles a))) (= 2 (length (scope-of a))) (scope-ref-invariants map) (search "" (cxtm map))))) (dolist (reference '("theme" "ex:theme" "" "^" "=")) (let* ((map (read-text (format nil "%prefix ex a - t:\"N\"@~A." reference))) (scope (scope-of (first (scoped-items map)))) (theme (first scope))) (check (concatenate 'string "scope-reader:existing-reference-resolver:" reference) (and (= 1 (length scope)) (eq map (topic-parent theme)) (cond ((char= (char reference 0) #\=) (equal '("urn:theme") (topic-subject-locators theme))) ((char= (char reference 0) #\^) (equal '("urn:theme") (topic-item-identifiers theme))) ((string= reference "theme") (eq theme (local-topic map "theme"))) (t (equal '("urn:theme") (topic-subject-identifiers theme)))))))) (let* ((map (read-text (format nil "a - \"N\"@#(x)# Ω,~%# theme comment~%β,Ω."))) (scope (scope-of (first (scoped-items map))))) (check "scope-reader:layout-unicode-and-set-identity" (and (= 2 (length scope)) (member (local-topic map "Ω") scope :test #'eq) (member (local-topic map "β") scope :test #'eq)))) (let* ((map (read-text "%prefix xsd a t: 1@theme; t: 1.0@theme; t: 2000-01-01@theme; t:\"01\"^^xsd:integer@theme.")) (items (all-occurrences map))) (check "scope-reader:literal-and-datatype-boundaries-preserve-values" (and (equal '("1" "1.0" "2000-01-01" "01") (mapcar #'topic-maps.tmdm:occurrence-value items)) (equal (list (topic-maps.tmdm:integer-datatype) (topic-maps.tmdm:decimal-datatype) (topic-maps.tmdm:date-datatype) (topic-maps.tmdm:integer-datatype)) (mapcar #'topic-maps.tmdm:occurrence-datatype items)) (every (lambda (item) (equal (list (local-topic map "theme")) (scope-of item))) items)))) ;; '@' remains legal inside an IRI; never split locator content heuristically. (let* ((map (read-text "a t:@theme.")) (o (first (all-occurrences map)))) (check "scope-reader:iri-content-not-scope-punctuation" (and (string= "https://user@example.invalid/v" (topic-maps.tmdm:occurrence-value o)) (= 1 (length (scope-of o)))))) (dolist (fixture '(("a - \"N\"@." :expected-scope-theme 8) ("a - \"N\"@" :expected-scope-theme 8) ("a - \"N\"@t,." :expected-scope-theme 10) ("a - \"N\"@,t." :expected-scope-theme 8) ("a - \"N\"@\"t\"." :expected-scope-theme 8) ("a t:\"V\"@." :expected-scope-theme 8) ("t(r: a)@" :expected-scope-theme 8) ("a - \"N\"@x:t." :undefined-prefix 8) ("a - \"N\"@~t." :expected-scope-theme 8) ("a - \"N\"@t,~s." :expected-scope-theme 10) ("a @t." :unexpected-token 2) ("t(r: a@t)" :expected-role-separator 6) ("a - \"N\"@t,,s." :expected-scope-theme 10))) (destructuring-bind (text code position) fixture (let ((e (ctm-condition text))) (check (concatenate 'string "scope-diagnostic:" text) (and (eq (type-of e) (if (eq code :undefined-prefix) 'undefined-prefix 'ctm-rejection)) (eq code (error-code e)) (= position (error-position e)) (= 1 (error-line e)) (= (1+ position) (error-column e))))))) (let ((e (ctm-condition (format nil "a - \"N\"@t,~% .")))) (check "scope-diagnostic:line-column-after-comma" (and (eq :expected-scope-theme (error-code e)) (= 2 (error-line e)) (= 2 (error-column e))))) (dolist (text '("a - \"N\"@[-\"embedded\"]." "a - \"N\"@? ." "a - \"N\"@t ~reifier." "a - \"N\"@t (\"variant\"@s ~r)." "def tpl() a - \"N\"@t. end")) (check (concatenate 'string "scope-reader:excluded-remains-unsupported:" text) (typep (ctm-condition text) 'ctm-unsupported)))) (defun scope-order-tests () (let ((reference nil) (topic-maps.cxtm::*base-locator* "https://example.invalid/a/doc.ctm") (topic-maps.cxtm::*locator-cache* (make-hash-table :test #'equal))) ;; Four scopes: empty, {a}, {b}, {a,b}. Cardinality precedes member comparison. (dolist (order (permutations '(0 1 2 3))) (let* ((map (topic-maps.tmdm:make-topic-map)) (owner (api-topic map "owner")) (type (api-topic map "type")) (a (api-topic map "a")) (b (api-topic map "b")) (sets (list nil (list a) (list b) (list b a))) (handles nil)) (dolist (i order) (dolist (kind '(:name :occurrence :association)) (push (new-scoped-item kind map owner type (nth i sets)) handles))) (let* ((before (map-state map)) (old (scope-handle-state handles)) (output (cxtm map))) (when reference (check (format nil "scope-order:~S:construction-independent" order) (string= reference output))) (setf reference output *scope-order-witness* output) (check (format nil "scope-order:~S:scope-key-after-type-and-roles" order) (and (zerop (topic-maps.cxtm::set-order (list a b) (list b a) #'topic-maps.cxtm::topic-order)) (minusp (topic-maps.cxtm::set-order (list b) (list a b) #'topic-maps.cxtm::topic-order)))) (check (format nil "scope-order:~S:pure-and-deterministic" order) (and (string= output (cxtm map)) (equal before (map-state map)) (equal old (scope-handle-state handles)))) (loop for getter in (list #'topic-names #'topic-maps.tmdm:topic-occurrences) for label in '(:names :occurrences) do (check (format nil "scope-order:~S:~A" order label) (equal '(0 1 1 2) (mapcar (lambda (i) (length (scope-of i))) (topic-maps.cxtm::sorted (funcall getter owner) (if (eq getter #'topic-names) #'topic-maps.cxtm::name-order #'topic-maps.cxtm::occurrence-order)))))) (check (format nil "scope-order:~S:association-rolePlayed-integrity" order) (let ((ordered (topic-maps.cxtm::sorted (topic-maps.tmdm:topic-map-associations map) #'topic-maps.cxtm::association-order))) (and (equal '(0 1 1 2) (mapcar (lambda (i) (length (scope-of i))) ordered)) (every (lambda (index) (search (format nil "association.~D.role.1" index) output)) '(1 2 3 4))))))))) (dolist (kind '(:name :occurrence :association)) (let* ((map (topic-maps.tmdm:make-topic-map)) (owner (api-topic map "owner")) (type (api-topic map "type")) (a (api-topic map "a")) (old (api-topic map "old")) (item (new-scoped-item kind map owner type (list a))) (foreign (api-topic (topic-maps.tmdm:make-topic-map) "foreign"))) (topic-maps.tmdm:merge-topics a old) (loop for fixture in (list (list (list old) :invalid-topic-reference) (list (list foreign) :invalid-topic-reference) (list (list (topic-maps.tmdm:canonical-topic a) (topic-maps.tmdm:canonical-topic a)) :invalid-set)) for index from 0 do (let ((saved (raw-scope item))) (unwind-protect (progn (setf (raw-scope item) (first fixture)) (let ((state (map-state map))) (check (format nil "scope-cxtm:~A:invalid-reference:~D:~A" kind index (second fixture)) (and (eq (second fixture) (topic-maps.cxtm:error-code (cxtm-condition (lambda () (cxtm map))))) (equal state (map-state map)))))) (setf (raw-scope item) saved))))))) (defun run-scope-tests () (run-typed-name-tests) (let ((*checks* nil)) (scope-original-cases) (scope-api-tests) (scope-merge-tests) (scope-reader-tests) (scope-order-tests) (check "scope:only-three-imported-transitions" (equal '(:pass 67 :fail 2 :unsupported 0 :not-run 204) (getf (topic-maps.test-foundation:summarize-corpus *cxtm-corpus*) :statuses))) (setf *last-scope-checks* (nreverse *checks*)) (format t "~&SCOPES-PASS: ~D checks; 3 original byte-exact comparisons; 67 PASS, 2 known FAIL, 204 NOT-RUN.~%" (length *last-scope-checks*)) t)) (defun write-scope-report (path) (with-open-file (out path :direction :output :if-exists :supersede :if-does-not-exist :create) (topic-maps.test-foundation::emit-json-value (topic-maps.test-foundation::fields "kind" "scope-evidence" "passed" (length *last-scope-checks*) "failed" 0 "checks" (topic-maps.test-foundation::json-array *last-scope-checks*) "orderingWitnessCXTM" *scope-order-witness* "cases" (topic-maps.test-foundation::json-array *scope-observations*)) out) (terpri out)))