]> dreyeck.freedombox.rocks Git - topic-maps.git/blob - tests/xtm-occurrence-reifier-native.lisp
perf(tmdm): index association normalization merge candidates
[topic-maps.git] / tests / xtm-occurrence-reifier-native.lisp
1 (in-package #:topic-maps.xtm.tests)
2
3 (defvar *occurrence-reifier-native* nil)
4 (defun orr-native-tests ()
5 ;; The same native TMDM checks run before the Reader change and in ASDF.
6 ;; These manually built API probes are never original corpus executions.
7 (setf *occurrence-reifier-native* nil)
8 (dolist (both '(nil t))
9 (let* ((label (if both "two-reifiers" "one-reifier"))
10 (map (make-topic-map)) (p (intern-topic map :item-identifier "urn:p"))
11 (q (intern-topic map :item-identifier "urn:q")) (type (intern-topic map :item-identifier "urn:type"))
12 (s (intern-topic map :item-identifier "urn:scope"))
13 (a (add-occurrence p type "V" :scope (list s))) (b (add-occurrence q type "V" :scope (list s)))
14 (r (intern-topic map :item-identifier "urn:r")) (u (intern-topic map :item-identifier "urn:u")))
15 (add-item-identifier a "urn:o1") (add-item-identifier b "urn:o2")
16 (check (format nil "occurrence-reifier-native:~A:assign-and-inverse" label)
17 (and (eq a (set-item-reifier a r)) (eq r (item-reifier a)) (eq a (topic-reified r))))
18 (when both (set-item-reifier b u))
19 (merge-topics p q)
20 (let ((current (canonical-occurrence a)))
21 (check (format nil "occurrence-reifier-native:~A:equal-occurrences-old-handles-and-II-union" label)
22 (and (eq current (canonical-occurrence b)) (not (eq a current)) (not (eq b current))
23 (= 1 (length (all-occurrences map))) (eq (canonical-topic p) (occurrence-parent current))
24 (same-identifiers-p '("urn:o1" "urn:o2") (item-identifiers current))
25 (eq (canonical-topic r) (item-reifier current)) (eq current (topic-reified r))
26 (equal "V" (occurrence-value current)) (equal (string-datatype) (occurrence-datatype current))
27 (equal (list s) (occurrence-scope current)) (ik-current-p map)))
28 (when both
29 (check "occurrence-reifier-native:two-reifiers:Topics-merge-identifiers-and-inverse"
30 (and (eq (canonical-topic r) (canonical-topic u)) (eq current (topic-reified u))
31 (same-identifiers-p '("urn:r" "urn:u") (item-identifiers (item-reifier current))))))
32 (push (mm-fields "label" label "kind" "native-TMDM-probe-not-original-contract" "model" (ik-model map)
33 "oldOccurrenceHandlesResolveEQ" :true "reifierTopicsMerged" (if both :true :false)) *occurrence-reifier-native*))))
34 (let* ((map (make-topic-map)) (p (intern-topic map :item-identifier "urn:p"))
35 (type (intern-topic map :item-identifier "urn:type"))
36 (a (add-occurrence p type "A")) (b (add-occurrence p type "B"))
37 (r (intern-topic map :item-identifier "urn:r")) (u (intern-topic map :item-identifier "urn:u")))
38 (set-item-reifier a r) (set-item-reifier b u)
39 (dolist (row (list (list "assignment-to-different-Occurrence" (lambda () (set-item-reifier b r)))
40 (list "late-Reifier-Topic-merge" (lambda () (merge-topics r u)))))
41 (let* ((before (ik-state map)) (c (condition-from (second row))))
42 (check (format nil "occurrence-reifier-native:~A:exact-atomic-conflict" (first row))
43 (and (eq (type-of c) 'reification-error) (eq :reifier-conflict (reification-error-code c))
44 (equal before (ik-state map)) (eq a (topic-reified r)) (eq b (topic-reified u)) (ik-current-p map)))
45 (push (mm-fields "label" (first row) "kind" "native-TMDM-probe-not-original-contract"
46 "condition" (mm-condition c) "nativeOperationUnchanged" :true) *occurrence-reifier-native*)))
47 (add-item-identifier a "urn:occurrence-item")
48 (let* ((before (ik-state map)) (c (condition-from (lambda () (intern-topic map :item-identifier "urn:occurrence-item")))))
49 (check "occurrence-reifier-native:II-not-Reifier-Topic-identity:atomic-native-conflict"
50 (and (typep c 'item-identifier-error) (eq :duplicate-item-identifier (item-identifier-error-code c))
51 (equal before (ik-state map))))
52 (push (mm-fields "label" "own-II-versus-Reifier-Topic" "kind" "native-TMDM-probe-not-original-contract"
53 "condition" (mm-condition c) "nativeOperationUnchanged" :true) *occurrence-reifier-native*)))
54 (let* ((map (make-topic-map)) (p (intern-topic map :item-identifier "urn:p"))
55 (type (intern-topic map :item-identifier "urn:type")) (o (add-occurrence p type "V"))
56 (r (intern-topic map :item-identifier "urn:shared-Reifier")))
57 (set-item-reifier map r)
58 (let* ((before (ik-state map)) (c (condition-from (lambda () (set-item-reifier o r)))))
59 (check "occurrence-reifier-native:map-versus-Occurrence:specific-atomic-original-cause"
60 (and (eq (type-of c) 'reification-error) (eq :reifier-conflict (reification-error-code c))
61 (equal "Topic already reifies a different information item." (topic-maps.tmdm::reification-error-detail c))
62 (equal before (ik-state map)) (eq map (topic-reified r)) (null (item-reifier o))))
63 (push (mm-fields "label" "map-versus-Occurrence" "kind" "native-TMDM-probe-not-original-contract"
64 "condition" (mm-condition c) "nativeOperationUnchanged" :true) *occurrence-reifier-native*)))
65 (setf *occurrence-reifier-native* (nreverse *occurrence-reifier-native*)))