blob: 92b0f40ce2dded3bed106a04e2dc6fe91464a711 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
;; -*- scheme -*-
;; guile-lib
;; Copyright (C) 2004, 2009 Andy Wingo <wingo at pobox dot com>
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2 of
;; the License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, contact:
;;
;; Free Software Foundation Voice: +1-617-542-5942
;; 59 Temple Place - Suite 330 Fax: +1-617-542-2652
;; Boston, MA 02111-1307, USA gnu@gnu.org
;;; Commentary:
;;
;; Unit tests for (sxml transform).
;;
;;; Code:
(define-module (test-suite sxml-transform)
#:use-module (test-suite lib)
#:use-module (sxml transform))
(let* ((tree '(root (n1 (n11) "s12" (n13))
"s2"
(n2 (n21) "s22")
(n3 (n31 (n311))
"s32"
(n33 (n331) "s332" (n333))
"s34"))))
(define (test pred-begin pred-end expected)
(pass-if expected
(equal? expected (car (replace-range pred-begin pred-end (list tree))))))
;; Remove one node, "s2"
(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")))
;; Replace one node, "s2" with "s2-new"
(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")))
;; Replace one node, "s2" with "s2-new" and its brother (n-new "s")
(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")))
;; Remove everything from "s2" onward
(test
(lambda (node)
(and (equal? node "s2") '()))
(lambda (node) #f)
'(root (n1 (n11) "s12" (n13))))
;; Remove everything from "n1" onward
(test
(lambda (node)
(and (pair? node) (eq? 'n1 (car node)) '()))
(lambda (node) #f)
'(root))
;; Replace from n1 through n33
(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"))))
|