Remove non-free old and crusty clearcase pkg
[packages] / xemacs-packages / semantic / semantic-utest.el
1 ;;; semantic-utest.el --- Tests for semantic's parsing system.
2
3 ;;; Copyright (C) 2003, 2004, 2007 Eric M. Ludlam
4
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
6 ;; X-RCS: $Id: semantic-utest.el,v 1.1 2007-11-26 15:10:44 michaels Exp $
7
8 ;; This file is not part of GNU Emacs.
9
10 ;; Semantic is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; This software is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
24
25 ;;; Commentary:
26 ;;
27 ;; Semantic's parsing and partial parsing system is pretty complex.
28 ;; These unit tests attempt to emulate semantic's partial reparsing
29 ;; and full reparsing system, and anything else I may feel the urge
30 ;; to write a test for.
31
32 (require 'semantic)
33
34 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
35 ;; Data for C tests
36
37 (defvar semantic-utest-C-buffer-contents
38   "/* Test file for C language for Unit Tests */
39
40 #include <stdio.h>
41 #include \"sutest.h\"
42
43 struct mystruct1 {
44   int slot11;
45   char slot12;
46   float slot13;
47 };
48
49 int var1;
50
51 float funp1(char arg11, char arg12);
52
53 char fun2(int arg_21, int arg_22) /*1*/
54 {
55   struct mystruct1 *ms1 = malloc(sizeof(struct mystruct1));
56
57   char sv = calc_sv(var1);
58
59   if (var1 == 0) {
60      sv = 1;
61   } else if (arg_21 == 0) {
62      sv = 2;
63   } else if (arg_22 == 0) {
64      sv = 3;
65   } else {
66      sv = 4;
67   }
68
69   printf(\"SV = %d\\n\", sv);
70
71   /* Memory Leak */
72   ms1.slot1 = sv;
73
74   return 'A' + sv;
75 }
76 "
77   "Contents of a C buffer initialized by this unit test.
78 Be sure to change `semantic-utest-C-name-contents' when you
79 change this variable.")
80
81 (defvar semantic-utest-C-h-buffer-contents
82   "/* Test file for C language header file for Unit Tests */
83
84 int calc_sv(int);
85
86 "
87   "Contents of a C header file buffer initialized by this unit test.")
88
89
90 (defvar semantic-utest-C-filename "/tmp/sutest.c"
91   "File to open and erase during this test for C.")
92
93 (defvar semantic-utest-C-filename-h 
94   (concat (file-name-sans-extension semantic-utest-C-filename)
95           ".h")
96   "Header file filename for C")
97
98
99 (defvar semantic-utest-C-name-contents
100   '(("stdio.h" include
101      (:system-flag t)
102      nil (overlay 48 66 "sutest.c"))
103     ("sutest.h" include nil nil (overlay 67 86 "sutest.c"))
104     ("mystruct1" type
105      (:members
106       (("slot11" variable
107         (:type "int")
108         (reparse-symbol classsubparts)
109         (overlay 109 120 "sutest.c"))
110        ("slot12" variable
111         (:type "char")
112         (reparse-symbol classsubparts)
113         (overlay 123 135 "sutest.c"))
114        ("slot13" variable
115         (:type "float")
116         (reparse-symbol classsubparts)
117         (overlay 138 151 "sutest.c")))
118       :type "struct")
119      nil (overlay 88 154 "sutest.c"))
120     ("var1" variable
121      (:type "int")
122      nil (overlay 156 165 "sutest.c"))
123     ("funp1" function
124      (:prototype-flag t :arguments
125                       (("arg11" variable
126                         (:type "char")
127                         (reparse-symbol arg-sub-list)
128                         (overlay 179 190 "sutest.c"))
129                        ("arg12" variable
130                         (:type "char")
131                         (reparse-symbol arg-sub-list)
132                         (overlay 191 202 "sutest.c")))
133                       :type "float")
134      nil (overlay 167 203 "sutest.c"))
135     ("fun2" function
136      (:arguments
137       (("arg_21" variable
138         (:type "int")
139         (reparse-symbol arg-sub-list)
140         (overlay 215 226 "sutest.c"))
141        ("arg_22" variable
142         (:type "int")
143         (reparse-symbol arg-sub-list)
144         (overlay 227 238 "sutest.c")))
145       :type "char")
146      nil (overlay 205 566 "sutest.c")))
147   "List of expected tag names for C.")
148
149
150 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
151 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
152 ;; Data for Python tests
153
154 (defvar semantic-utest-Python-buffer-contents
155 "
156 def fun1(a,b,c):
157   return a
158
159 def fun2(a,b,c): #1
160   return b
161
162 "
163
164
165 )
166 ;  "pyhon test case. notice that python is indentation sensitive
167
168
169 (defvar semantic-utest-Python-name-contents
170   '(("fun1" function
171      (:arguments
172       (("a" variable nil
173         (reparse-symbol function_parameters)
174         (overlay 10 11 "tst.py"))
175        ("b" variable nil
176         (reparse-symbol function_parameters)
177         (overlay 12 13 "tst.py"))
178        ("c" variable nil
179         (reparse-symbol function_parameters)
180         (overlay 14 15 "tst.py"))))
181      nil (overlay 1 31 "tst.py"))
182     ("fun2" function
183      (:arguments
184       (("a" variable nil
185         (reparse-symbol function_parameters)
186         (overlay 41 42 "tst.py"))
187        ("b" variable nil
188         (reparse-symbol function_parameters)
189         (overlay 43 44 "tst.py"))
190        ("c" variable nil
191         (reparse-symbol function_parameters)
192         (overlay 45 46 "tst.py"))))
193      nil (overlay 32 65 "tst.py")))
194   
195   "List of expected tag names for Python.")
196
197
198
199 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
200 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
201 ;; Data for Java tests
202
203 (defvar semantic-utest-Java-buffer-contents
204 "
205 class JavaTest{
206   void fun1(int a,int b){
207     return a;
208   }
209
210   void fun2(int a,int b){ //1
211     return b;
212   }
213
214 }
215 "
216 )
217
218 (defvar semantic-utest-Java-name-contents
219   '(("JavaTest" type
220      (:members
221       (("fun1" function
222         (:arguments
223          (("a" variable
224            (:type "int")
225            (reparse-symbol formal_parameters)
226            (overlay 30 35 "JavaTest.java"))
227           ("b" variable
228            (:type "int")
229            (reparse-symbol formal_parameters)
230            (overlay 36 41 "JavaTest.java")))
231          :type "void")
232         (reparse-symbol class_member_declaration)
233         (overlay 20 61 "JavaTest.java"))
234        ("fun2" function
235         (:arguments
236          (("a" variable
237            (:type "int")
238            (reparse-symbol formal_parameters)
239            (overlay 75 80 "JavaTest.java"))
240           ("b" variable
241            (:type "int")
242            (reparse-symbol formal_parameters)
243            (overlay 81 86 "JavaTest.java")))
244          :type "void")
245         (reparse-symbol class_member_declaration)
246         (overlay 65 110 "JavaTest.java")))
247       :type "class")
248      nil (overlay 2 113 "JavaTest.java")))
249   "List of expected tag names for Java."
250   )
251
252
253 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
254 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
255 ;; Data for Javascript tests
256
257 (defvar semantic-utest-Javascript-buffer-contents
258 "
259 function fun1(a, b){
260     return a;
261   }
262
263 function fun2(a,b){ //1
264     return b;
265   }
266 "
267 )
268
269
270 (defvar semantic-utest-Javascript-name-contents
271   '(("fun1" function
272      (:arguments
273       (("a" variable nil
274         (reparse-symbol FormalParameterList)
275         (overlay 15 16 "tst.js"))
276        ("b" variable nil
277         (reparse-symbol FormalParameterList)
278         (overlay 18 19 "tst.js"))))
279      nil (overlay 1 39 "tst.js"))
280     ("fun2" function
281      (:arguments
282       (("a" variable nil
283         (reparse-symbol FormalParameterList)
284         (overlay 55 56 "tst.js"))
285        ("b" variable nil
286         (reparse-symbol FormalParameterList)
287         (overlay 57 58 "tst.js"))))
288      nil (overlay 41 82 "tst.js")))
289
290   "List of expected tag names for Javascript.")
291
292
293
294 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
295 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
296 ;; Data for Makefile tests
297
298 (defvar semantic-utest-Makefile-buffer-contents
299 "
300 t1:
301     echo t1
302
303 t2:t1 #1
304     echo t2
305
306
307 "
308 )
309
310
311 (defvar semantic-utest-Makefile-name-contents
312   '(("t1" function nil nil (overlay 1 9 "Makefile"))
313     ("t2" function
314      (:arguments
315       ("t1"))
316      nil (overlay 18 28 "Makefile")))
317   "List of expected tag names for Makefile.")
318
319
320 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
321 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
322 ;; Data for Scheme tests
323
324 (defvar semantic-utest-Scheme-buffer-contents
325   "
326  (define fun1 2)
327
328  (define fun2 3  ;1
329               )
330 ")
331
332 (defvar semantic-utest-Scheme-name-contents
333   '(("fun1" variable
334      (:default-value ("2"))
335      nil (overlay 3 18 "tst.scm"))
336     ("fun2" variable
337      (:default-value ("3"))
338      nil (overlay 21 55 "tst.scm")))
339   )
340
341 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
342 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
343 ;; Data for Html tests
344
345 (defvar semantic-utest-Html-buffer-contents
346   "
347 <html>
348   <body>
349     <h1>hello</h1>
350   </body><!--1-->
351 </html>
352 "
353   )
354
355 (defvar semantic-utest-Html-name-contents
356   '(("hello" section
357      (:members
358       (("hello" section nil nil (overlay 21 24 "tst.html"))))
359      nil (overlay 10 15 "tst.html")))
360   )
361
362
363 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
364 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
365 ;; Data for Csharp C# tests
366
367 (defvar semantic-utest-Csharp-buffer-contents
368 "
369 class someClass {
370   int fun1(int a, int b) {
371     return a; }
372   int fun2(int a, int b) {
373     return b; }
374 }
375 ")
376
377 (defvar semantic-utest-Csharp-name-contents
378   '(("someClass" type
379      (:members
380       (("fun1" function
381         (:arguments
382          (("a" variable
383            (:type "int")
384            (reparse-symbol formal_parameters)
385            (overlay 30 35 "tst.cs"))
386           ("b" variable
387            (:type "int")
388            (reparse-symbol formal_parameters)
389            (overlay 37 42 "tst.cs")))
390          :type "int")
391         (reparse-symbol class_member_declaration)
392         (overlay 21 61 "tst.cs"))
393        ("fun2" function
394         (:arguments
395          (("a" variable
396            (:type "int")
397            (reparse-symbol formal_parameters)
398            (overlay 73 78 "tst.cs"))
399           ("b" variable
400            (:type "int")
401            (reparse-symbol formal_parameters)
402            (overlay 80 85 "tst.cs")))
403          :type "int")
404         (reparse-symbol class_member_declaration)
405         (overlay 64 104 "tst.cs")))
406       :type "class")
407      nil (overlay 1 106 "tst.cs")))
408   )
409
410
411 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
412 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
413
414
415
416 (defun semantic-utest-makebuffer (filename contents)
417   (let ((buff (find-file-noselect filename)))
418     (set-buffer buff)
419     (erase-buffer)
420     (insert contents)
421     ;(semantic-fetch-tags) ;JAVE could this go here?
422     buff
423     )
424   )
425
426 (defun semantic-utest-C ()
427   "Run semantic's C unit test."
428   (interactive)
429   (save-excursion
430     (let ((buff  (semantic-utest-makebuffer semantic-utest-C-filename   semantic-utest-C-buffer-contents))
431           (buff2 (semantic-utest-makebuffer semantic-utest-C-filename-h semantic-utest-C-h-buffer-contents))
432           )
433       (semantic-fetch-tags)
434       (set-buffer buff)
435       
436       ;; Turn off a range of modes
437       (semantic-idle-scheduler-mode -1)
438
439       ;; Turn on some modes
440       (semantic-highlight-edits-mode 1)
441
442       ;; Update tags, and show it.
443       (semantic-fetch-tags)
444       (switch-to-buffer buff)
445       (sit-for 0)
446       
447       ;; Run the tests.
448       (message "First parsing test.")
449       (semantic-utest-verify-names semantic-utest-C-name-contents)
450
451       (message "Invalid tag test.")
452       (semantic-utest-last-invalid semantic-utest-C-name-contents '("fun2") "/\\*1\\*/" "/* Deleted this line */")
453       (semantic-utest-verify-names semantic-utest-C-name-contents)
454
455       ;; Clean up
456       ;; (kill-buffer buff)
457       ;; (kill-buffer buff2)
458       ))
459   (message "All C tests passed.")
460   )
461
462
463
464
465 (defun semantic-utest-generic (testname filename contents name-contents names-removed killme insertme)
466   "generic unit test according to template, should work for languages withouth .h files, python javascript java."
467   (save-excursion
468     (let ((buff  (semantic-utest-makebuffer filename  contents))
469           )
470       ;; Turn off a range of modes
471       (semantic-idle-scheduler-mode -1)
472
473       ;; Turn on some modes
474       (semantic-highlight-edits-mode 1)
475
476       ;; Update tags, and show it.
477       (semantic-fetch-tags)
478       (switch-to-buffer buff)
479       (sit-for 0)
480       
481       ;; Run the tests.
482       (message "First parsing test %s." testname)
483       (semantic-utest-verify-names name-contents)
484
485       (message "Invalid tag test %s." testname)
486       (semantic-utest-last-invalid name-contents names-removed killme insertme)
487       (semantic-utest-verify-names name-contents)
488
489       ;; Clean up
490       ;; (kill-buffer buff)
491       ;; (kill-buffer buff2)
492       ))
493   (message "All %s tests passed." testname)
494   )
495
496 (defun semantic-utest-Python()
497   (interactive)
498   (semantic-utest-generic "Python" "/tmp/pytest.py" semantic-utest-Python-buffer-contents  semantic-utest-Python-name-contents   '("fun2") "#1" "#deleted line")  )
499
500
501 (defun semantic-utest-Javascript()
502   (interactive)
503   (semantic-utest-generic "Javascript" "/tmp/javascripttest.js" semantic-utest-Javascript-buffer-contents  semantic-utest-Javascript-name-contents   '("fun2") "//1" "//deleted line")
504   )
505
506 (defun semantic-utest-Java()
507   (interactive)
508   (semantic-utest-generic "Java" "/tmp/JavaTest.java" semantic-utest-Java-buffer-contents  semantic-utest-Java-name-contents   '("fun2") "//1" "//deleted line")
509   )
510
511 (defun semantic-utest-Makefile()
512   (interactive)
513   (semantic-utest-generic "Makefile" "/tmp/Makefile" semantic-utest-Makefile-buffer-contents  semantic-utest-Makefile-name-contents   '("fun2") "#1" "#deleted line")
514   )
515
516 (defun semantic-utest-Scheme()
517   (interactive)
518   (semantic-utest-generic "Scheme" "/tmp/tst.scm" semantic-utest-Scheme-buffer-contents  semantic-utest-Scheme-name-contents   '("fun2") ";1" ";deleted line")
519   )
520
521
522 (defun semantic-utest-Html()
523   (interactive)
524   (semantic-utest-generic "HTML" "/tmp/tst.html" semantic-utest-Html-buffer-contents  semantic-utest-Html-name-contents   '("fun2") "<!--1-->" "<!--deleted line-->")
525   )
526
527 ;look at http://mfgames.com/linux/csharp-mode
528 (defun semantic-utest-Csharp() ;; hmm i dont even know how to edit a scharp file. need a csharp mode implementation i suppose
529   (interactive)
530   (semantic-utest-generic "C#" "/tmp/csharptest.cs" semantic-utest-Csharp-buffer-contents  semantic-utest-Csharp-name-contents   '("fun2") "//1" "//deleted line")
531   )
532
533 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
534 ;; stubs
535
536 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
537 ; stuff for Erlang
538 ;;-module(hello).
539 ;-export([hello_world/0]).
540 ;
541 ;hello_world()->
542 ;    io:format("Hello World ~n"). 
543 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
544 (defun semantic-utest-Erlang()
545   (interactive)
546   (semantic-utest-generic "Erlang" "/tmp/tst.erl" semantic-utest-Erlang-buffer-contents  semantic-utest-Erlang-name-contents   '("fun2") "//1" "//deleted line")
547   )
548
549 ;texi is also supported
550 (defun semantic-utest-Texi()
551   (interactive)
552   (semantic-utest-generic "texi" "/tmp/tst.texi" semantic-utest-Texi-buffer-contents  semantic-utest-Texi-name-contents   '("fun2") "//1" "//deleted line")
553   )
554
555 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
556
557 (defun semantic-utest-main()
558   (interactive)
559   "call all utests"
560   (semantic-utest-C)
561   (semantic-utest-Python)
562   (semantic-utest-Java) 
563   (semantic-utest-Javascript)
564   (semantic-utest-Makefile)
565   (semantic-utest-Scheme)
566   ;(semantic-utest-Html)
567   ;(semantic-utest-Csharp)
568   )
569
570 ;;; Buffer contents validation
571 ;;
572 (defun semantic-utest-match-attributes (attr1 attr2 skipnames)
573   "Compare attribute lists ATTR1 and ATTR2.
574 Argument SKIPNAMES is a list of names that may be child nodes to skip."
575   (let ((res t))
576     (while (and res attr1 attr2)
577
578       ;; Compare
579       (setq res
580             (cond ((and (listp (car attr1))
581                         (semantic-tag-p (car (car attr1))))
582                    ;; Compare the list of tags...
583                    (semantic-utest-taglists-equivalent-p
584                     (car attr2) (car attr1) skipnames)
585                    )
586                   (t
587                    (equal (car attr1) (car attr2)))))
588       
589       (if (not res)
590           (error "TAG INTERNAL DIFF: %S %S"
591                  (car attr1) (car attr2)))
592
593       (setq attr1 (cdr attr1)
594             attr2 (cdr attr2)))
595     res))
596
597 (defun semantic-utest-equivalent-tag-p (tag1 tag2 skipnames)
598   "Determine if TAG1 and TAG2 are the same.
599 SKIPNAMES includes lists of possible child nodes that should be missing."
600   (and (equal (semantic-tag-name tag1) (semantic-tag-name tag2))
601        (semantic-tag-of-class-p tag1 (semantic-tag-class tag2))
602        (semantic-utest-match-attributes
603         (semantic-tag-attributes tag1) (semantic-tag-attributes tag2)
604         skipnames)
605        ))
606
607 (defun semantic-utest-taglists-equivalent-p (table names skipnames)
608   "Compare TABLE and NAMES, where skipnames allow list1 to be different.
609 SKIPNAMES is a list of names that should be skipped in the NAMES list."
610   (let ((SN skipnames))
611     (while SN
612       (setq names (remove (car SN) names))
613       (setq SN (cdr SN))))
614   (while (and names table)
615     (if (not (semantic-utest-equivalent-tag-p (car names)
616                                               (car table)
617                                               skipnames))
618         (error "Expected %s, found %s"
619                (semantic-format-tag-prototype (car names))
620                (semantic-format-tag-prototype (car table))))
621     (setq names (cdr names)
622           table (cdr table)))
623   (when names (error "Items forgotten: %S" names))
624   (when table (error "Items extra: %S" table))
625   t)
626
627 (defun semantic-utest-verify-names (name-contents &optional skipnames)
628   "Verify the names of the test buffer from NAME-CONTENTS.
629 Argument SKIPNAMES is a list of names that should be skipped
630 when analyzing the file.
631
632 JAVE this thing would need to be recursive to handle java and csharp"
633   (let ((names name-contents)
634         (table (semantic-fetch-tags))
635         )
636     (semantic-utest-taglists-equivalent-p table names skipnames)
637     ))
638
639 ;;;;;;;;;;;;;;;;;;;;;;;;
640 ; JAVE redefine a  new validation function
641 ; is not quite as good as the old one yet
642 (defun semantic-utest-verify-names-jave (name-contents &optional skipnames)
643   "JAVE version of `semantic-utest-verify-names'.
644 NAME-CONTENTS is a sample of the tags buffer to test against.
645 SKIPNAMES is a list of names to remove from NAME-CONTENTS"
646  (assert (semantic-utest-verify-names-2 name-contents (semantic-fetch-tags))
647          nil "failed test")
648 )
649
650 (defun semantic-utest-verify-names-2 (l1 l2)
651   (cond   ( (and (consp l1) (equal (car l1) 'overlay))
652             (overlayp l2))
653           ((not (consp l1))
654            (equal l1 l2))
655           ((consp l1)
656            (and (semantic-utest-verify-names-2 (car l1) (car l2)) (semantic-utest-verify-names-2 (cdr l1) (cdr l2))))
657           (t (error "internal error"))))
658
659
660
661
662
663 ;;; Kill indicator line
664 ;;
665 (defvar semantic-utest-last-kill-text nil
666   "The text from the last kill.")
667
668 (defvar semantic-utest-last-kill-pos nil
669   "The position of the last kill.")
670
671 (defun semantic-utest-kill-indicator ( killme insertme)
672   "Kill the line with KILLME on it and insert INSERTME in its place."
673   (goto-char (point-min))
674 ;  (re-search-forward (concat "/\\*" indicator "\\*/")); JAVE this isnt generic enough for different lagnuages
675   (re-search-forward killme)
676   (beginning-of-line)
677   (setq semantic-utest-last-kill-pos (point))
678   (setq semantic-utest-last-kill-text
679         (buffer-substring (point) (point-at-eol)))
680   (delete-region (point) (point-at-eol))
681   (insert insertme)
682   (sit-for 0)
683 )
684
685 (defun semantic-utest-unkill-indicator ()
686   "Unkill the last indicator."
687   (goto-char semantic-utest-last-kill-pos)
688   (delete-region (point) (point-at-eol))
689   (insert semantic-utest-last-kill-text)
690   (sit-for 0)
691   )
692
693 ;;;  EDITING TESTS
694 ;;
695
696 (defun semantic-utest-last-invalid (name-contents names-removed killme insertme)
697   "Make the last fcn invalid."
698   (semantic-utest-kill-indicator killme insertme)
699 ;  (semantic-utest-verify-names name-contents names-removed); verify its gone ;new validator doesnt handle skipnames yet
700   (semantic-utest-unkill-indicator);put back killed stuff
701   )
702
703
704
705
706 ;"#<overlay from \\([0-9]+\\) to \\([0-9]+\\) in \\([^>]*\\)>"
707 ;#<overlay from \([0-9]+\) to \([0-9]+\) in \([^>]*\)>
708 ;(overlay \1 \2 "\3")
709
710
711 ;; JAVE
712 ;; these are some unit tests for cedet that I got from Eric and modified a bit for:
713 ;;   python
714 ;;   javascript
715 ;;   java
716 ;; I tried to generalize the structure of the tests a bit to make it easier to add languages
717
718 ;; Mail from Eric:
719 ;; Many items in the checklist look like:
720
721 ;;       M-x global-semantic-highlight-edits-mode RET
722 ;;       - Edit a file.  See the highlight of newly inserted text.
723 ;;       - Customize `semantic-edits-verbose-flag' to be non-nil.
724 ;;       - Wait for the idle scheduler, it should clean up the edits.
725 ;;         - observe messages from incremental parser.  Do they relate
726 ;;        to the edits?
727 ;;       - M-x bovinate RET - verify your changes are reflected.
728
729 ;; It's all about watching the behavior.  Timers go off, things get
730 ;; cleaned up, you type in new changes, etc.  An example I tried to
731 ;; do is below, but covers only 1 language, and not very well at that.
732 ;; I seem to remember seeing a unit test framework going by one of the
733 ;; lists.  I'm not sure if that would help.
734
735 ;; Another that might be automatable:
736
737 ;;       M-x semantic-analyze-current-context RET
738 ;;        - Do this in different contexts in your language
739 ;;          files.   Verify that reasonable results are returned
740 ;;          such as identification of assignments, function arguments, etc.
741
742 ;; Anyway, those are some ideas.  Any effort you put it will be helpful!
743
744 ;; Thanks
745 ;; Eric
746
747 ;; -----------
748
749
750