redisplay-testsuite.el 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. ;;; redisplay-testsuite.el --- Test suite for redisplay.
  2. ;; Copyright (C) 2009-2012 Free Software Foundation, Inc.
  3. ;; Author: Chong Yidong <cyd@stupidchicken.com>
  4. ;; Keywords: internal
  5. ;; Human-Keywords: internal
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs 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
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; Type M-x test-redisplay RET to generate the test buffer.
  19. ;;; Code:
  20. (defun test-insert-overlay (text &rest props)
  21. (let ((opoint (point))
  22. overlay)
  23. (insert text)
  24. (setq overlay (make-overlay opoint (point)))
  25. (while props
  26. (overlay-put overlay (car props) (cadr props))
  27. (setq props (cddr props)))))
  28. (defun test-redisplay-1 ()
  29. (insert "Test 1: Displaying adjacent and overlapping overlays:\n\n")
  30. (insert " Expected: gnu emacs\n")
  31. (insert " Results: ")
  32. (test-insert-overlay "n" 'before-string "g" 'after-string "u ")
  33. (test-insert-overlay "ma" 'before-string "e" 'after-string "cs")
  34. (insert "\n\n")
  35. (insert " Expected: gnu emacs\n")
  36. (insert " Results: ")
  37. (test-insert-overlay "u" 'before-string "gn")
  38. (test-insert-overlay "ma" 'before-string " e" 'after-string "cs")
  39. (insert "\n\n")
  40. (insert " Expected: gnu emacs\n")
  41. (insert " Results: ")
  42. (test-insert-overlay "XXX" 'display "u "
  43. 'before-string "gn" 'after-string "em")
  44. (test-insert-overlay "a" 'after-string "cs")
  45. (insert "\n\n")
  46. (insert " Expected: gnu emacs\n")
  47. (insert " Results: ")
  48. (test-insert-overlay "u " 'before-string "gn" 'after-string "em")
  49. (test-insert-overlay "XXX" 'display "a" 'after-string "cs")
  50. (insert "\n\n"))
  51. (defun test-redisplay-2 ()
  52. (insert "Test 2: Mouse highlighting. Move your mouse over the letters XXX:\n\n")
  53. (insert " Expected: "
  54. (propertize "xxxXXXxxx" 'face 'highlight)
  55. "...---...\n Test: ")
  56. (test-insert-overlay "XXX" 'before-string "xxx" 'after-string "xxx"
  57. 'mouse-face 'highlight )
  58. (test-insert-overlay "---" 'before-string "..." 'after-string "...")
  59. (insert "\n\n Expected: "
  60. (propertize "xxxXXX" 'face 'highlight)
  61. "...---...\n Test: ")
  62. (test-insert-overlay "XXX" 'before-string "xxx" 'mouse-face 'highlight)
  63. (test-insert-overlay "---" 'before-string "..." 'after-string "...")
  64. (insert "\n\n Expected: "
  65. (propertize "XXX" 'face 'highlight)
  66. "...---...\n Test: ")
  67. (test-insert-overlay "..." 'display "XXX" 'mouse-face 'highlight)
  68. (test-insert-overlay "---" 'before-string "..." 'after-string "...")
  69. (insert "\n\n Expected: "
  70. (propertize "XXXxxx" 'face 'highlight)
  71. "...\n Test: ")
  72. (test-insert-overlay "..." 'display "XXX" 'after-string "xxx"
  73. 'mouse-face 'highlight)
  74. (test-insert-overlay "error" 'display "...")
  75. (insert "\n\n Expected: "
  76. "---..."
  77. (propertize "xxxXXX" 'face 'highlight)
  78. "\n Test: ")
  79. (test-insert-overlay "xxx" 'display "---" 'after-string "...")
  80. (test-insert-overlay "error" 'before-string "xxx" 'display "XXX"
  81. 'mouse-face 'highlight)
  82. (insert "\n\n Expected: "
  83. "...---..."
  84. (propertize "xxxXXXxxx" 'face 'highlight)
  85. "\n Test: ")
  86. (test-insert-overlay "---" 'before-string "..." 'after-string "...")
  87. (test-insert-overlay "XXX" 'before-string "xxx" 'after-string "xxx"
  88. 'mouse-face 'highlight)
  89. (insert "\n\n Expected: "
  90. "..."
  91. (propertize "XXX" 'face 'highlight)
  92. "...\n Test: ")
  93. (test-insert-overlay "---"
  94. 'display (propertize "XXX" 'mouse-face 'highlight)
  95. 'before-string "..."
  96. 'after-string "...")
  97. (insert "\n\n Expected: "
  98. (propertize "XXX\n" 'face 'highlight)
  99. "\n Test: ")
  100. (test-insert-overlay "XXX\n" 'mouse-face 'highlight)
  101. (insert "\n\n"))
  102. (defun test-redisplay-3 ()
  103. (insert "Test 3: Overlay with before/after strings and images:\n\n")
  104. (let ((img-data "#define x_width 8
  105. #define x_height 8
  106. static unsigned char x_bits[] = {0xff, 0x81, 0xbd, 0xa5, 0xa5, 0xbd, 0x81, 0xff };"))
  107. ;; Control
  108. (insert " Expected: AB"
  109. (propertize "X" 'display `(image :data ,img-data :type xbm))
  110. "CD\n")
  111. ;; Overlay with before, after, and image display string.
  112. (insert " Result 1: ")
  113. (let ((opoint (point)))
  114. (insert "AXD\n")
  115. (let ((ov (make-overlay (1+ opoint) (+ 2 opoint))))
  116. (overlay-put ov 'before-string "B")
  117. (overlay-put ov 'after-string "C")
  118. (overlay-put ov 'display
  119. `(image :data ,img-data :type xbm))))
  120. ;; Overlay with before and after string, and image text prop.
  121. (insert " Result 2: ")
  122. (let ((opoint (point)))
  123. (insert "AXD\n")
  124. (let ((ov (make-overlay (1+ opoint) (+ 2 opoint))))
  125. (overlay-put ov 'before-string "B")
  126. (overlay-put ov 'after-string "C")
  127. (put-text-property (1+ opoint) (+ 2 opoint) 'display
  128. `(image :data ,img-data :type xbm))))
  129. ;; Overlays with adjacent before and after strings, and image text
  130. ;; prop.
  131. (insert " Result 3: ")
  132. (let ((opoint (point)))
  133. (insert "AXD\n")
  134. (let ((ov1 (make-overlay opoint (1+ opoint)))
  135. (ov2 (make-overlay (+ 2 opoint) (+ 3 opoint))))
  136. (overlay-put ov1 'after-string "B")
  137. (overlay-put ov2 'before-string "C")
  138. (put-text-property (1+ opoint) (+ 2 opoint) 'display
  139. `(image :data ,img-data :type xbm))))
  140. ;; Three overlays.
  141. (insert " Result 4: ")
  142. (let ((opoint (point)))
  143. (insert "AXD\n\n")
  144. (let ((ov1 (make-overlay opoint (1+ opoint)))
  145. (ov2 (make-overlay (+ 2 opoint) (+ 3 opoint)))
  146. (ov3 (make-overlay (1+ opoint) (+ 2 opoint))))
  147. (overlay-put ov1 'after-string "B")
  148. (overlay-put ov2 'before-string "C")
  149. (overlay-put ov3 'display `(image :data ,img-data :type xbm))))))
  150. (defun test-redisplay ()
  151. (interactive)
  152. (let ((buf (get-buffer "*Redisplay Test*")))
  153. (if buf
  154. (kill-buffer buf))
  155. (pop-to-buffer (get-buffer-create "*Redisplay Test*"))
  156. (erase-buffer)
  157. (test-redisplay-1)
  158. (test-redisplay-2)
  159. (test-redisplay-3)
  160. (goto-char (point-min))))