diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2021-08-24 19:40:36 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2021-08-24 19:40:36 +0200 |
commit | 9b56ebd22e3267cedc839e11ee31d69928214ce5 (patch) | |
tree | 2ae82115a4de42cc37c37dc3a9392976928302a4 | |
parent | Add tests for iCal unknown key warnings. (diff) | |
download | calp-9b56ebd22e3267cedc839e11ee31d69928214ce5.tar.gz calp-9b56ebd22e3267cedc839e11ee31d69928214ce5.tar.xz |
Allow partial change and removal of XML Namespaces.
Changing the error to a returnu allows a partial namespace change map,
which can sometimes be usefull (and should hopefully not lead to any
issues here).
Changing assoc-ref to assoc allows the removal of namespaces, since
assoc-ref can't differentiate between a match with #f in its cdr, and no
match.
(assoc-ref '((a . #f)) 'a) ⇒ #f
(assoc-ref '((a . #f)) 'b) ⇒ #f
-rw-r--r-- | module/sxml/namespace.scm | 5 | ||||
-rw-r--r-- | tests/xml-namespace.scm | 30 |
2 files changed, 33 insertions, 2 deletions
diff --git a/module/sxml/namespace.scm b/module/sxml/namespace.scm index 57250b93..19211227 100644 --- a/module/sxml/namespace.scm +++ b/module/sxml/namespace.scm @@ -34,8 +34,9 @@ (define (nssymb key) (define namespace (if (list? namespace-map) - (or (assoc-ref namespace-map key) - (error "No mapping for namespace" key)) + (cond ((assoc key namespace-map) + => cdr) + (else key)) namespace-map)) (cond diff --git a/tests/xml-namespace.scm b/tests/xml-namespace.scm new file mode 100644 index 00000000..74053fd8 --- /dev/null +++ b/tests/xml-namespace.scm @@ -0,0 +1,30 @@ +(((sxml namespace) + move-to-namespace + )) + + +(test-equal "Move unnamespaced to namespace" + '(NEW:test) + (move-to-namespace '(test) '((#f . NEW)))) + +(test-equal "Swap namespaces" + '(b:a (a:b)) + (move-to-namespace '(a:a (b:b)) '((a . b) (b . a)))) + +(test-equal "Remove all namespaces" + '(a (b)) + (move-to-namespace '(a:a (b:b)) #f)) + +(test-equal "Move everything to one namespace" + '(c:a (c:b)) + (move-to-namespace '(a:a (b:b)) 'c)) + +(test-equal "Partial namespace change" + '(c:a (b:b)) + (move-to-namespace '(a:a (b:b)) + '((a . c)))) + +(test-equal "Remove specific namespace" + '(a:a (b)) + (move-to-namespace '(a:a (b:b)) + '((b . #f)))) |