sxml.transform.test 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. ;;;; sxml.transform.test -*- scheme -*-
  2. ;;;;
  3. ;;;; Copyright (C) 2010 Free Software Foundation, Inc.
  4. ;;;; Copyright (C) 2001,2002,2003,2004 Oleg Kiselyov <oleg at pobox dot com>
  5. ;;;;
  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.
  10. ;;;;
  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.
  15. ;;;;
  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
  19. ;;; Commentary:
  20. ;;
  21. ;; Unit tests for (sxml transform).
  22. ;;
  23. ;;; Code:
  24. (define-module (test-suite sxml-transform)
  25. #:use-module (test-suite lib)
  26. #:use-module (sxml transform))
  27. (let* ((tree '(root (n1 (n11) "s12" (n13))
  28. "s2"
  29. (n2 (n21) "s22")
  30. (n3 (n31 (n311))
  31. "s32"
  32. (n33 (n331) "s332" (n333))
  33. "s34"))))
  34. (define (test pred-begin pred-end expected)
  35. (pass-if expected
  36. (equal? expected (car (replace-range pred-begin pred-end (list tree))))))
  37. ;; Remove one node, "s2"
  38. (test
  39. (lambda (node)
  40. (and (equal? node "s2") '()))
  41. (lambda (node) (list node))
  42. '(root (n1 (n11) "s12" (n13))
  43. (n2 (n21) "s22")
  44. (n3 (n31 (n311)) "s32" (n33 (n331) "s332" (n333)) "s34")))
  45. ;; Replace one node, "s2" with "s2-new"
  46. (test
  47. (lambda (node)
  48. (and (equal? node "s2") '("s2-new")))
  49. (lambda (node) (list node))
  50. '(root (n1 (n11) "s12" (n13))
  51. "s2-new"
  52. (n2 (n21) "s22")
  53. (n3 (n31 (n311)) "s32" (n33 (n331) "s332" (n333)) "s34")))
  54. ;; Replace one node, "s2" with "s2-new" and its brother (n-new "s")
  55. (test
  56. (lambda (node)
  57. (and (equal? node "s2") '("s2-new" (n-new "s"))))
  58. (lambda (node) (list node))
  59. '(root (n1 (n11) "s12" (n13))
  60. "s2-new" (n-new "s")
  61. (n2 (n21) "s22")
  62. (n3 (n31 (n311)) "s32" (n33 (n331) "s332" (n333)) "s34")))
  63. ;; Remove everything from "s2" onward
  64. (test
  65. (lambda (node)
  66. (and (equal? node "s2") '()))
  67. (lambda (node) #f)
  68. '(root (n1 (n11) "s12" (n13))))
  69. ;; Remove everything from "n1" onward
  70. (test
  71. (lambda (node)
  72. (and (pair? node) (eq? 'n1 (car node)) '()))
  73. (lambda (node) #f)
  74. '(root))
  75. ;; Replace from n1 through n33
  76. (test
  77. (lambda (node)
  78. (and (pair? node)
  79. (eq? 'n1 (car node))
  80. (list node '(n1* "s12*"))))
  81. (lambda (node)
  82. (and (pair? node)
  83. (eq? 'n33 (car node))
  84. (list node)))
  85. '(root
  86. (n1 (n11) "s12" (n13))
  87. (n1* "s12*")
  88. (n3
  89. (n33 (n331) "s332" (n333))
  90. "s34"))))