(require :asdf)
(assert (string= "2.5.4" (lisp-implementation-version)))
(setf *compile-verbose* nil *load-verbose* nil)
(asdf:load-asd (merge-pathnames "topic-maps.asd" (uiop:ensure-directory-pathname (uiop:getenv "TOPIC_MAPS_21F_ROOT"))))
(asdf:load-system "topic-maps/xtm/tests")
(in-package :topic-maps.xtm.tests)
(let ((rows nil) (*checks* nil))
(dolist (target '("parent" "theme"))
(dolist (kind '("subjectIdentifier" "subjectLocator" "itemIdentity"))
(let ((names nil) (label (format nil "preflight:~A:~A" target kind)) (*name-controls* nil))
(flet ((theme-source (id locator)
(if (equal kind "itemIdentity") (format nil "" id)
(format nil "<~A href='~A'/>" id kind locator))))
(staged-name-control label
(if (equal target "parent")
(format nil "~AN~AN<~A href='~A'/><~A href='~A'/>"
(if (equal kind "itemIdentity") "" (format nil "<~A href='urn:one'/>" kind))
(if (equal kind "itemIdentity") "" (format nil "<~A href='urn:two'/>" kind))
kind (if (equal kind "itemIdentity") "#a" "urn:one") kind (if (equal kind "itemIdentity") "#b" "urn:two"))
(concatenate 'string "NN"
(theme-source "s1" "urn:one") (theme-source "s2" "urn:two")
(format nil "<~A href='~A'/><~A href='~A'/>"
kind (if (equal kind "itemIdentity") "#s1" "urn:one") kind (if (equal kind "itemIdentity") "#s2" "urn:two"))))
(lambda (map step)
(if (equal target "parent")
(when (<= step 2)
(let ((name (first (topic-names (by-id map (if (= step 1) "a" "b"))))))
(push name names) (add-item-identifier name (format nil "urn:name:~A" step))))
(when (= step 1)
(setf names (topic-names (by-id map "a")))
(add-item-identifier (first names) "urn:name:1") (add-item-identifier (second names) "urn:name:2"))))
(lambda (map)
(let* ((owner (by-id map "a")) (name (first (topic-names owner))))
(check (concatenate 'string label ":retained-eq-and-identifier-union")
(and (= 1 (length (topic-names owner)))
(every (lambda (old) (and (eq name (canonical-topic-name old)) (eq owner (topic-name-parent old))
(same-identifiers-p '("urn:name:1" "urn:name:2") (item-identifiers old)))) names)
(same-identifiers-p '("urn:name:1" "urn:name:2") (item-identifiers name))))))))
(push (first *name-controls*) rows))))
(assert (= 6 (length rows)))
(with-open-file (out (uiop:getenv "TOPIC_MAPS_21F_PREFLIGHT") :direction :output :if-exists :supersede)
(topic-maps.test-foundation::emit-json-value
(topic-maps.test-foundation::fields "kind" "pre-implementation-existing-TMDM-identifier-retention"
"allSixMergesPassed" :true "checks" (coerce (reverse *checks*) 'vector) "controls" (coerce (nreverse rows) 'vector)) out)
(terpri out)))