]> dreyeck.freedombox.rocks Git - topic-maps.git/blobdiff - tests/xtm-variants.lisp
examples: explore project work through native Topic Maps (slice 22U)
[topic-maps.git] / tests / xtm-variants.lisp
index af323b6f59978b8ce153c56442a2498cd24b7209..dbba2cd738e0549bbfa350723331ffd64f6e22e2 100644 (file)
@@ -38,7 +38,7 @@
         (topic-maps.test-foundation::fields "value" (variant-value v) "datatype" (variant-datatype v)
           "parentName" (1+ (position (variant-parent v) names :test #'eq))
           "scope" (coerce (mapcar (lambda (theme) (1+ (position theme topics :test #'eq))) (variant-scope v)) 'vector)
         (topic-maps.test-foundation::fields "value" (variant-value v) "datatype" (variant-datatype v)
           "parentName" (1+ (position (variant-parent v) names :test #'eq))
           "scope" (coerce (mapcar (lambda (theme) (1+ (position theme topics :test #'eq))) (variant-scope v)) 'vector)
-          "itemIdentifiers" (coerce (item-identifiers v) 'vector) "reifier" nil)) 'vector))))
+          "itemIdentifiers" (coerce (item-identifiers v) 'vector) "reifier" (when (item-reifier v) (1+ (position (item-reifier v) topics :test #'eq))))) 'vector))))
 
 (defun variant-original-model-checks (spec map raw)
   (destructuring-bind (id count name-scope-ids variant-scope-ids source-count) spec
 
 (defun variant-original-model-checks (spec map raw)
   (destructuring-bind (id count name-scope-ids variant-scope-ids source-count) spec
         "sourceText" (document body) "model" (variant-model-data map)
         "actualCXTM" (babel:octets-to-string actual :encoding :utf-8)) *variant-controls*))))
 (defun variant-error-control (label body class code)
         "sourceText" (document body) "model" (variant-model-data map)
         "actualCXTM" (babel:octets-to-string actual :encoding :utf-8)) *variant-controls*))))
 (defun variant-error-control (label body class code)
-  (let* ((key (concatenate 'string "variant-syntax:" label)) (source (document body))
+  (let* ((key (concatenate 'string "variant-syntax:" label)) (source (ss-unsupported-source (document body) code label))
          (c (condition-from (lambda () (deserialize-octets (bytes source) :document-iri *document* :source-key key)))))
     (check (concatenate 'string key ":class-code")
       (and (eq class (type-of c)) (eq code (cond ((typep c 'topic-maps.xtm:xtm-error) (error-code c))
          (c (condition-from (lambda () (deserialize-octets (bytes source) :document-iri *document* :source-key key)))))
     (check (concatenate 'string key ":class-code")
       (and (eq class (type-of c)) (eq code (cond ((typep c 'topic-maps.xtm:xtm-error) (error-code c))
         (and (scope-eq-p (variant-scope (first (all-variants map))) (list (by-id map "s")))
           (same-identifiers-p (item-identifiers (by-id map "s"))
             (append (list (concatenate 'string *document* "#s")) (when (equal kind "itemIdentity") '("https://themes.invalid/map#theme"))))))))))
         (and (scope-eq-p (variant-scope (first (all-variants map))) (list (by-id map "s")))
           (same-identifiers-p (item-identifiers (by-id map "s"))
             (append (list (concatenate 'string *document* "#s")) (when (equal kind "itemIdentity") '("https://themes.invalid/map#theme"))))))))))
-(defun variant-merge-controls ()
+(defun variant-merge-controls (&optional (literal (lambda (themes) (variant-xml "V" themes))) (prefix "variant-merge:") verify)
   (dolist (target '("parent" "variant-theme" "name-theme"))
     (dolist (kind '("subjectIdentifier" "subjectLocator" "itemIdentity"))
   (dolist (target '("parent" "variant-theme" "name-theme"))
     (dolist (kind '("subjectIdentifier" "subjectLocator" "itemIdentity"))
-      (let* ((label (format nil "variant-merge:~A:~A" target kind)) (old-names nil) (old-variants nil) (old-themes nil)
-             (first-v (variant-xml "V" '("extra"))) (second-v first-v) (body nil) (*name-controls* nil))
+      (let* ((label (format nil "~A~A:~A" prefix target kind)) (old-names nil) (old-variants nil) (old-themes nil)
+             (first-v (funcall literal '("extra"))) (second-v first-v) (body nil) (*name-controls* nil))
         (labels ((topic-source (id locator content)
                    (format nil "<topic id='~A'>~A~A</topic>" id
                      (if (equal kind "itemIdentity") "" (format nil "<~A href='~A'/>" kind locator)) content))
         (labels ((topic-source (id locator content)
                    (format nil "<topic id='~A'>~A~A</topic>" id
                      (if (equal kind "itemIdentity") "" (format nil "<~A href='~A'/>" kind locator)) content))
               ((equal target "variant-theme")
                (concatenate 'string
                  (format nil "<topic id='a'>~A</topic>" (variant-name-xml '("base")
               ((equal target "variant-theme")
                (concatenate 'string
                  (format nil "<topic id='a'>~A</topic>" (variant-name-xml '("base")
-                   (concatenate 'string (variant-xml "V" '("x")) (variant-xml "V" '("y"))) "urn:n1"))
+                   (concatenate 'string (funcall literal '("x")) (funcall literal '("y"))) "urn:n1"))
                  (topic-source "x" "urn:one" "") (topic-source "y" "urn:two" "") (bridge "x" "y")))
               (t
                (concatenate 'string (format nil "<topic id='a'>~A~A</topic>"
                  (topic-source "x" "urn:one" "") (topic-source "y" "urn:two" "") (bridge "x" "y")))
               (t
                (concatenate 'string (format nil "<topic id='a'>~A~A</topic>"
                       (if (equal target "variant-theme") '("urn:n1") '("urn:n1" "urn:n2")))
                     (variants-current-p map)))
                 (topic-maps.cxtm:canonicalize-octets map :base-locator *document*)
                       (if (equal target "variant-theme") '("urn:n1") '("urn:n1" "urn:n2")))
                     (variants-current-p map)))
                 (topic-maps.cxtm:canonicalize-octets map :base-locator *document*)
+                (when verify (funcall verify label map))
                 (check (concatenate 'string label ":cxtm-pure-retains-handles") (equal before (variant-state map)))
                 (push (topic-maps.test-foundation::fields "label" label "kind" "staged-native-reader-control"
                   "sourceText" (document body) "model" (variant-model-data map)) *variant-controls*)))))))))
                 (check (concatenate 'string label ":cxtm-pure-retains-handles") (equal before (variant-state map)))
                 (push (topic-maps.test-foundation::fields "label" label "kind" "staged-native-reader-control"
                   "sourceText" (document body) "model" (variant-model-data map)) *variant-controls*)))))))))
     ("bad-href" "<variant><scope><topicRef href='#2bad'/></scope><resourceData>V</resourceData></variant>" :invalid-topic-ref)
     ("resourceRef-missing-href" "<variant><scope><topicRef href='#s'/></scope><resourceRef/></variant>" :missing-attribute)))
     (variant-error-control (first row) (format nil "<topic id='a'><name><value>N</value>~A</name></topic>" (second row)) 'xtm-rejection (third row)))
     ("bad-href" "<variant><scope><topicRef href='#2bad'/></scope><resourceData>V</resourceData></variant>" :invalid-topic-ref)
     ("resourceRef-missing-href" "<variant><scope><topicRef href='#s'/></scope><resourceRef/></variant>" :missing-attribute)))
     (variant-error-control (first row) (format nil "<topic id='a'><name><value>N</value>~A</name></topic>" (second row)) 'xtm-rejection (third row)))
-  (dolist (row '(("resourceRef" "<variant><scope><topicRef href='#s'/></scope><resourceRef href='urn:x'/></variant>" :unsupported-construct)
-    ("itemIdentity" "<variant><itemIdentity href='urn:v'/><scope><topicRef href='#s'/></scope><resourceData>V</resourceData></variant>" :unsupported-construct)
-    ("reifier" "<variant reifier='#r'><scope><topicRef href='#s'/></scope><resourceData>V</resourceData></variant>" :reification)
-    ("datatype" "<variant><scope><topicRef href='#s'/></scope><resourceData datatype='urn:other'>V</resourceData></variant>" :resource-data-datatype)
-    ("embedded-XML" "<variant><scope><topicRef href='#s'/></scope><resourceData><b xmlns='urn:other'>V</b></resourceData></variant>" :resource-data-markup)))
+  (dolist (row '(("resourceData-anyType" "<variant><scope><topicRef href='#s'/></scope><resourceData datatype='http://www.w3.org/2001/XMLSchema#anyType'>42</resourceData></variant>" :resource-resolver-required)
+    ("reified-itemIdentity-excluded-datatype" "<variant reifier='#r'><itemIdentity href='urn:v'/><scope><topicRef href='#s'/></scope><resourceData datatype='http://www.w3.org/2001/XMLSchema#anyType'>42</resourceData></variant>" :resource-resolver-required)
+    ("reifier-excluded-datatype" "<variant reifier='#r'><scope><topicRef href='#s'/></scope><resourceData datatype='http://www.w3.org/2001/XMLSchema#anyType'>42</resourceData></variant>" :resource-resolver-required)
+    ("datatype" "<variant><scope><topicRef href='#s'/></scope><resourceData datatype='http://www.w3.org/2001/XMLSchema#anyType'>V</resourceData></variant>" :resource-resolver-required)
+    ("embedded-XML" "<variant><scope><topicRef href='#s'/></scope><resourceData datatype='http://www.w3.org/2001/XMLSchema#anyType'><b xmlns='urn:other'>V</b></resourceData></variant>" :resource-resolver-required)))
     (variant-error-control (first row) (format nil "<topic id='a'><name><value>N</value>~A</name></topic>" (second row)) 'xtm-unsupported (third row))))
 
 (defun variant-tests ()
     (variant-error-control (first row) (format nil "<topic id='a'><name><value>N</value>~A</name></topic>" (second row)) 'xtm-unsupported (third row))))
 
 (defun variant-tests ()