]> dreyeck.freedombox.rocks Git - topic-maps.git/blobdiff - tests/ctm-identity.lisp
feat(tmdm): readers for the TMDM 7.2/7.3 relationships; tests for both default name...
[topic-maps.git] / tests / ctm-identity.lisp
index 2d8b98c72e0eb3da6346c01213c8aa9d057bfb71..5601bca41d28ce6690771cf37529e3c3c61a1b98 100644 (file)
     (let ((condition (rejection (format nil "a.~%  ex:fake."))))
       (check "undefined-prefix-condition-class" (typep condition 'undefined-prefix))
       (check "error-line-column" (and (= 2 (error-line condition)) (= 3 (error-column condition)))))
-    (dolist (text '("a isa person." "relation(role: a)" "def tpl() a. end" "%prefix ex https://example.invalid/ ex:a."
-                    "? - \"anonymous\"." "a @theme." "a - \"name\" @theme." "a - \"\"\"triple\"\"\"."))
-      (check (concatenate 'string "unsupported-not-silently-accepted:" text) (unsupported-p text)))
+    (check "identity-feature-boundary:a isa person."
+           (let ((map (read-text "a isa person.")))
+             (= 1 (length (topic-maps.tmdm:topic-map-associations map)))))
+    (dolist (text '("def tpl() a. end" "%include <other.ctm>"
+                    "? - \"anonymous\" ~r."  "a - \"\"\"triple\"\"\"."))
+      (check (if (search "%include" text) "identity:Include-requires-explicit-resolver"
+                 (concatenate 'string "identity-feature-boundary:" text))
+             (cond ((search "def " text) (null (topic-map-topics (read-text text))))
+                   ((search "%include" text)
+                    (handler-case (progn (read-text text) nil)
+                      (ctm-unsupported (c) (eq :resource-resolver-required (error-code c)))))
+                   ((find #\~ text) (typep (read-text text) 'topic-maps.tmdm:topic-map))
+                   (t (string= "triple" (topic-name-value (first (topic-names (first-topic (read-text text))))))))))
+    (check "scope-on-bare-topic-rejected"
+           (eq :unexpected-token (error-code (rejection "a @theme."))))
+    (check "scoped-name-now-deserialized"
+           (= 1 (length (topic-maps.tmdm:topic-name-scope
+                          (first (topic-names (first-topic (read-text "a - \"name\" @theme."))))))))
+    (check "association-now-deserialized"
+           (= 1 (length (topic-maps.tmdm:topic-map-associations (read-text "relation(role: a)")))))
     (check "empty-document-has-no-accidental-type-topic"
            (null (topic-map-topics (read-text ""))))
     (let ((map (deserialize-file (asdf:system-relative-pathname "topic-maps" "tests/fixtures/ctm/utf8-bom.ctm")
                                         :document-iri "https://example.invalid/absent.ctm") nil)
              (ctm-rejection () nil)
              (file-error () t)))
-    (check "typed-name-explicitly-unsupported" (unsupported-p "a - fullname:\"Name\"."))
-    ;; CTM 3.11 requires a string, even when the optional type is unsupported.
+    (check "typed-name-explicitly-supported" (verify-item-invariants (read-text "a - fullname:\"Name\".")))
+    ;; CTM 3.11 requires a string, with or without an explicit type.
     ;; CTM 3.3.1 permits layout between the type separator and that string.
     (dolist (fixture '(("a - ." ctm-rejection :expected-name-value 4)
-                       ("a -" ctm-rejection :expected-name-value 3)
-                       ("a - type:\"Name\"." ctm-unsupported :typed-name 4)
-                       ("a - type: \"Name\"." ctm-unsupported :typed-name 4)))
+                       ("a -" ctm-rejection :expected-name-value 3)))
       (destructuring-bind (text class code position) fixture
         (let ((condition (handler-case (progn (read-text text) nil)
                            (ctm-error (e) e))))
           (check (concatenate 'string "name-classification-diagnostic:" text)
                  (search (if (eq class 'ctm-rejection) "quoted name value" "Typed names")
                          (princ-to-string condition))))))
+    (dolist (text '("a - type:\"Name\"." "a - type: \"Name\"."))
+      (let* ((map (read-text text)) (owner (first-topic map))
+             (name (first (topic-names owner))) (type (topic-name-type name)))
+        (check (concatenate 'string "name-classification-supported:" text) (typep name 'topic-maps.tmdm:topic-name))
+        (check (concatenate 'string "name-classification-value:" text) (string= "Name" (topic-name-value name)))
+        (check (concatenate 'string "name-classification-parent:" text) (eq owner (topic-name-parent name)))
+        (check (concatenate 'string "name-classification-type:" text)
+               (equal '("https://example.invalid/a/doc.ctm#type") (topic-item-identifiers type)))
+        (check (concatenate 'string "name-classification-no-extra-topic:" text) (= 2 (length (topic-map-topics map))))))
     ;; A type-like token alone must not turn a malformed name into UNSUPPORTED.
     (check "name-type-without-separator-is-rejected"
            (eq :expected-name-type-separator (error-code (rejection "a - type \"Name\"."))))
     (check "typed-name-without-value-is-rejected"
            (eq :expected-name-value (error-code (rejection "a - type:."))))
-    (check "typed-name-layout-remains-unsupported"
-           (unsupported-p (format nil "a - type:~%#( layout )# \"Name\".")))
-    (check "additional-identity-explicitly-unsupported" (unsupported-p "a <https://example.invalid/alias>."))
+    (check "typed-name-layout-supported"
+           (verify-item-invariants (read-text (format nil "a - type:~%#( layout )# \"Name\"."))))
+    (check "additional-identity-now-deserialized"
+           (let* ((map (read-text "a <https://example.invalid/alias>.")) (topic (first-topic map)))
+             (and (= 1 (length (topic-map-topics map)))
+                  (equal (topic-subject-identifiers topic) '("https://example.invalid/alias"))
+                  (equal (topic-item-identifiers topic) '("https://example.invalid/a/doc.ctm#a")))))
     (dolist (ending (list (string #\Return) (format nil "~C~C" #\Return #\Newline)))
       (let ((condition (rejection (concatenate 'string "a." ending "ex:fake."))))
         (check (if (= 1 (length ending)) "cr-error-line" "crlf-error-line")
              (equal (topic-subject-identifiers
                      (first-topic (read-text (format nil "<~A>." (first pair)) "http://a/b/c/d;p?q")))
                     (list (second pair)))))
-    (check "canonicalizer-not-defined" (null (asdf:find-system "topic-maps/cxtm" nil)))
+    (check "reader-does-not-depend-on-canonicalizer"
+           (equal (asdf:system-depends-on (asdf:find-system "topic-maps/ctm"))
+                  '("topic-maps/tmdm")))
     (setf *last-checks* (nreverse *checks*))
     (format t "~&CTM-IDENTITY-SEMANTICS-PASS: ~D checks, 5 imported semantic cases, required prefix rejection; no CXTM equality passes.~%"
             (length *last-checks*))