(cout nl nl "Testing SXML-tree-trans.scm" nl)
(cout nl "Testing replace-range" nl)
(let* ((tree
'(root
(n1 (n11) "s12" (n13))
"s2"
(n2 (n21) "s22")
(n3
(n31 (n311))
"s32"
(n33 (n331) "s332" (n333))
"s34")))
(test
(lambda (pred-begin pred-end expected)
(let ((computed
(car (replace-range pred-begin pred-end (list tree)))))
(assert (equal? computed expected)))))
)
(cout "The tree under experimentation" nl)
(pp tree)
(newline)
(test
(lambda (node)
(and (equal? node "s2") '()))
(lambda (node) (list node))
'(root (n1 (n11) "s12" (n13))
(n2 (n21) "s22")
(n3 (n31 (n311)) "s32" (n33 (n331) "s332" (n333)) "s34")))
(test
(lambda (node)
(and (equal? node "s2") '("s2-new")))
(lambda (node) (list node))
'(root (n1 (n11) "s12" (n13))
"s2-new"
(n2 (n21) "s22")
(n3 (n31 (n311)) "s32" (n33 (n331) "s332" (n333)) "s34")))
(test
(lambda (node)
(and (equal? node "s2") '("s2-new" (n-new "s"))))
(lambda (node) (list node))
'(root (n1 (n11) "s12" (n13))
"s2-new" (n-new "s")
(n2 (n21) "s22")
(n3 (n31 (n311)) "s32" (n33 (n331) "s332" (n333)) "s34")))
(test
(lambda (node)
(and (equal? node "s2") '()))
(lambda (node) #f)
'(root (n1 (n11) "s12" (n13))))
(test
(lambda (node)
(and (pair? node) (eq? 'n1 (car node)) '()))
(lambda (node) #f)
'(root))
(test
(lambda (node)
(and (pair? node)
(eq? 'n1 (car node))
(list node '(n1* "s12*"))))
(lambda (node)
(and (pair? node)
(eq? 'n33 (car node))
(list node)))
'(root
(n1 (n11) "s12" (n13))
(n1* "s12*")
(n3
(n33 (n331) "s332" (n333))
"s34")))
)
(cout nl nl "All tests passed" nl)