1 ;;; From srecode-fields:
3 (require 'srecode
/fields
)
5 (defvar srecode-field-utest-text
6 "This is a test buffer.
8 It is filled with some text."
11 (defun srecode-field-utest ()
12 "Test the srecode field manager."
14 (if (featurep 'xemacs
)
15 (message "There is no XEmacs support for SRecode Fields.")
16 (srecode-field-utest-impl)))
18 (defun srecode-field-utest-impl ()
19 "Implementation of the SRecode field utest."
21 (find-file "/tmp/srecode-field-test.txt")
24 (goto-char (point-min))
25 (insert srecode-field-utest-text
)
26 (set-buffer-modified-p nil
)
28 ;; Test basic field generation.
29 (let ((srecode-field-archive nil
)
35 (setq f
(srecode-field "Test"
40 (when (or (not (slot-boundp f
'overlay
)) (not (oref f overlay
)))
41 (error "Field test: Overlay info not created for field"))
43 (when (and (overlay-p (oref f overlay
))
44 (not (overlay-get (oref f overlay
) 'srecode-init-only
)))
45 (error "Field creation overlay is not tagged w/ init flag"))
47 (srecode-overlaid-activate f
)
49 (when (or (not (overlay-p (oref f overlay
)))
50 (overlay-get (oref f overlay
) 'srecode-init-only
))
51 (error "New field overlay not created during activation"))
53 (when (not (= (length srecode-field-archive
) 1))
54 (error "Field test: Incorrect number of elements in the field archive"))
55 (when (not (eq f
(car srecode-field-archive
)))
56 (error "Field test: Field did not auto-add itself to the field archive"))
58 (when (not (overlay-get (oref f overlay
) 'keymap
))
59 (error "Field test: Overlay keymap not set"))
61 (when (not (string= "is" (srecode-overlaid-text f
)))
62 (error "Field test: Expected field text 'is', not %s"
63 (srecode-overlaid-text f
)))
68 (when (slot-boundp f
'overlay
)
69 (error "Field test: Overlay not deleted after object delete"))
72 ;; Test basic region construction.
73 (let* ((srecode-field-archive nil
)
77 (srecode-field "Test1" :name
"TEST-1" :start
5 :end
10)
78 (srecode-field "Test2" :name
"TEST-2" :start
15 :end
20)
79 (srecode-field "Test3" :name
"TEST-3" :start
25 :end
30)
81 (srecode-field "Test4" :name
"TEST-4" :start
35 :end
35))
84 (when (not (= (length srecode-field-archive
) 4))
85 (error "Region Test: Found %d fields. Expected 4"
86 (length srecode-field-archive
)))
88 (setq reg
(srecode-template-inserted-region "REG"
92 (srecode-overlaid-activate reg
)
94 ;; Make sure it was cleared.
95 (when srecode-field-archive
96 (error "Region Test: Did not clear field archive"))
99 (when (not (eq (point) 5))
100 (error "Region Test: Did not reposition on first field"))
103 (when (not (eq (srecode-active-template-region) reg
))
104 (error "Region Test: Active region not set"))
108 (if (string= (object-name-string T
) "Test4")
110 (when (not (srecode-empty-region-p T
))
111 (error "Field %s is not empty"
114 (when (not (= (srecode-region-size T
) 5))
115 (error "Calculated size of %s was not 5"
119 ;; Make sure things stay up after a 'command'.
120 (srecode-field-post-command)
121 (when (not (eq (srecode-active-template-region) reg
))
122 (error "Region Test: Active region did not stay up"))
124 ;; Test field movement.
125 (when (not (eq (srecode-overlaid-at-point 'srecode-field
)
127 (error "Region Test: Field %s not under point"
128 (object-name (nth 0 fields
))))
132 (when (not (eq (srecode-overlaid-at-point 'srecode-field
)
134 (error "Region Test: Field %s not under point"
135 (object-name (nth 1 fields
))))
139 (when (not (eq (srecode-overlaid-at-point 'srecode-field
)
141 (error "Region Test: Field %s not under point"
142 (object-name (nth 0 fields
))))
144 ;; Move cursor out of the region and have everything cleaned up.
146 (srecode-field-post-command)
147 (when (srecode-active-template-region)
148 (error "Region Test: Active region did not clear on move out"))
151 (when (slot-boundp T
'overlay
)
152 (error "Overlay did not clear off of of field %s"
159 ;; Test variable linkage.
160 (let* ((srecode-field-archive nil
)
161 (f1 (srecode-field "Test1" :name
"TEST" :start
6 :end
8))
162 (f2 (srecode-field "Test2" :name
"TEST" :start
28 :end
30))
163 (f3 (srecode-field "Test3" :name
"NOTTEST" :start
35 :end
40))
164 (reg (srecode-template-inserted-region "REG" :start
4 :end
40))
166 (srecode-overlaid-activate reg
)
168 (when (not (string= (srecode-overlaid-text f1
)
169 (srecode-overlaid-text f2
)))
170 (error "Linkage Test: Init strings are not ="))
171 (when (string= (srecode-overlaid-text f1
)
172 (srecode-overlaid-text f3
))
173 (error "Linkage Test: Init string on dissimilar fields is now the same"))
178 (when (not (string= (srecode-overlaid-text f1
)
179 (srecode-overlaid-text f2
)))
180 (error "Linkage Test: mid-insert strings are not ="))
181 (when (string= (srecode-overlaid-text f1
)
182 (srecode-overlaid-text f3
))
183 (error "Linkage Test: mid-insert string on dissimilar fields is now the same"))
188 (when (not (string= (srecode-overlaid-text f1
) "iast"))
189 (error "Linkage Test: tail-insert failed to captured added char"))
190 (when (not (string= (srecode-overlaid-text f1
)
191 (srecode-overlaid-text f2
)))
192 (error "Linkage Test: tail-insert strings are not ="))
193 (when (string= (srecode-overlaid-text f1
)
194 (srecode-overlaid-text f3
))
195 (error "Linkage Test: tail-insert string on dissimilar fields is now the same"))
200 (when (not (string= (srecode-overlaid-text f1
) "biast"))
201 (error "Linkage Test: tail-insert failed to captured added char"))
202 (when (not (string= (srecode-overlaid-text f1
)
203 (srecode-overlaid-text f2
)))
204 (error "Linkage Test: tail-insert strings are not ="))
205 (when (string= (srecode-overlaid-text f1
)
206 (srecode-overlaid-text f3
))
207 (error "Linkage Test: tail-insert string on dissimilar fields is now the same"))
213 (set-buffer-modified-p nil
)
215 (message " All field tests passed.")
218 ;;; From srecode-document:
220 (require 'srecode
/doc
)
222 (defun srecode-document-function-comment-extract-test ()
223 "Test old comment extraction.
224 Dump out the extracted dictionary."
227 (srecode-load-tables-for-mode major-mode
)
228 (srecode-load-tables-for-mode major-mode
'document
)
230 (if (not (srecode-table))
231 (error "No template table found for mode %s" major-mode
))
233 (let* ((temp (srecode-template-get-table (srecode-table)
237 (fcn-in (semantic-current-tag)))
240 (error "No templates for function comments"))
242 ;; Try to figure out the tag we want to use.
243 (when (or (not fcn-in
)
244 (not (semantic-tag-of-class-p fcn-in
'function
)))
245 (error "No tag of class 'function to insert comment for"))
247 (let ((lextok (semantic-documentation-comment-preceeding-tag fcn-in
'lex
))
251 (error "No comment to attempt an extraction"))
253 (let ((s (semantic-lex-token-start lextok
))
254 (e (semantic-lex-token-end lextok
))
257 (pulse-momentary-highlight-region s e
)
259 ;; Extract text from the existing comment.
260 (setq extract
(srecode-extract temp s e
))
262 (with-output-to-temp-buffer "*SRECODE DUMP*"
263 (princ "EXTRACTED DICTIONARY FOR ")
264 (princ (semantic-tag-name fcn-in
))
265 (princ "\n--------------------------------------------\n")
266 (srecode-dump extract
))))))