1 ;;;; sxml.transform.test -*- scheme -*-
3 ;;;; Copyright (C) 2010 Free Software Foundation, Inc.
4 ;;;; Copyright (C) 2001,2002,2003,2004 Oleg Kiselyov <oleg at pobox dot com>
6 ;;;; This library is free software; you can redistribute it and/or
7 ;;;; modify it under the terms of the GNU Lesser General Public
8 ;;;; License as published by the Free Software Foundation; either
9 ;;;; version 3 of the License, or (at your option) any later version.
11 ;;;; This library is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ;;;; Lesser General Public License for more details.
16 ;;;; You should have received a copy of the GNU Lesser General Public
17 ;;;; License along with this library; if not, write to the Free Software
18 ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 ;; Unit tests for (sxml transform).
26 (define-module (test-suite sxml-transform)
27 #:use-module (test-suite lib)
28 #:use-module (sxml transform))
30 (let* ((tree '(root (n1 (n11) "s12" (n13))
35 (n33 (n331) "s332" (n333))
37 (define (test pred-begin pred-end expected)
39 (equal? expected (car (replace-range pred-begin pred-end (list tree))))))
41 ;; Remove one node, "s2"
44 (and (equal? node "s2") '()))
45 (lambda (node) (list node))
46 '(root (n1 (n11) "s12" (n13))
48 (n3 (n31 (n311)) "s32" (n33 (n331) "s332" (n333)) "s34")))
50 ;; Replace one node, "s2" with "s2-new"
53 (and (equal? node "s2") '("s2-new")))
54 (lambda (node) (list node))
55 '(root (n1 (n11) "s12" (n13))
58 (n3 (n31 (n311)) "s32" (n33 (n331) "s332" (n333)) "s34")))
60 ;; Replace one node, "s2" with "s2-new" and its brother (n-new "s")
63 (and (equal? node "s2") '("s2-new" (n-new "s"))))
64 (lambda (node) (list node))
65 '(root (n1 (n11) "s12" (n13))
68 (n3 (n31 (n311)) "s32" (n33 (n331) "s332" (n333)) "s34")))
70 ;; Remove everything from "s2" onward
73 (and (equal? node "s2") '()))
75 '(root (n1 (n11) "s12" (n13))))
77 ;; Remove everything from "n1" onward
80 (and (pair? node) (eq? 'n1 (car node)) '()))
84 ;; Replace from n1 through n33
89 (list node '(n1* "s12*"))))
95 (n1 (n11) "s12" (n13))
98 (n33 (n331) "s332" (n333))