summaryrefslogtreecommitdiffstats
path: root/emacs.d/nxhtml/tests/nxhtmltest-suites.el
blob: 5af8ab8135225993ba55f861f717758ad9241620 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
;;; nxhtmltest-suites.el --- Test suites for mumamo / nXhtml
;;
;; Author: Lennart Borgman (lennart O borgman A gmail O com)
;; Created: 2008-07-08T20:17:36+0200 Tue
;; Version: 0.12
;; Last-Updated: 2008-09-01T01:13:28+0200 Sun
;; URL:
;; Keywords:
;; Compatibility:
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:
;;
;; Defines `nxhtmltest-run'.  When (getenv "nxhtmltest-run-Q")
;; returns non-nil also runs this function.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Change log:
;;
;; Added code from Christian Ohler for writing ert tests.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; 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, 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; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Code:

;;(eval-when-compile (require 'cl))
(eval-when-compile (require 'cl))
(eval-when-compile (require 'rng-valid))
(eval-when-compile (require 'rngalt))
(require 'mumamo)
(require 'mumamo-fun)
(require 'nxhtml)
(require 'nxhtml-mumamo)
(when (fboundp 'nxml-mode)
  (require 'rng-valid)
  (require 'rngalt))

(setq debug-on-error t)

(defvar nxhtmltest-ert-default-selector "nxhtml-ert-"
  "Set this to run a single test with `nxhtmltest-run-Q'.")

(defvar nxhtmltest-bin
  (file-name-directory (if load-file-name load-file-name buffer-file-name)))

(pushnew nxhtmltest-bin load-path)
(require 'nxhtmltest-helpers)
;;(require 'ert)

(defvar nxhtmltest-files-root
  (let* ((this-dir nxhtmltest-bin)
         (root (expand-file-name "in/" this-dir)))
    (unless (file-accessible-directory-p root)
          (error (if (file-exists-p root)
                     "Can't read files in test directory %s"
                   "Can't find test directory %s")
                 root))
    root))

(let ((distr-in "c:/EmacsW32/nxhtml/tests/in/"))
  (when (file-directory-p distr-in)
    (setq nxhtmltest-files-root distr-in)))

;; (setq nxhtmltest-update-method
;;       ;;'font-lock-wait
;;       'font-lock-run-timers
;;       ;;'font-lock-fontify-buffer
;;       )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Define tests using ert.el

(ert-deftest nxhtml-ert-bug531328 ()
  "Test of eRuby chunks with nothing between."
  (ert-with-temp-buffer-include-file "bug531328.rhtml"
    (add-hook 'ert-simulate-command-post-hook
              'nxhtmltest-should-no-mumamo-errors
              nil t)
    (ert-simulate-command '(eruby-html-mumamo-mode) t)
    (nxhtmltest-get-fontification-method)
    (nxhtmltest-fontify-default-way 2 "trans")
    (ert-simulate-command '(goto-char 12) t)
    (ert-should (eq major-mode 'ruby-mode))
    ))

(ert-deftest nxhtml-ert-indent-bug-johan-2010-02-17()
  "Test of eRuby indentation.
Got a bug report by mail on the emacs-on-rails list."
  (ert-with-temp-buffer-include-file "bug-johan-2010-02-17.erb"
    (add-hook 'ert-simulate-command-post-hook
              'nxhtmltest-should-no-mumamo-errors
              nil t)
    (ert-simulate-command '(eruby-html-mumamo-mode) t)
    (nxhtmltest-fontify-default-way 2 "trans")
    (ert-simulate-command '(mark-whole-buffer) t)
    (ert-simulate-command '(indent-for-tab-command) t)
    (nxhtmltest-goto-line 1)  (ert-should (= 0 (current-indentation)))
    (nxhtmltest-goto-line 2)  (ert-should (= 2 (current-indentation)))
    (nxhtmltest-goto-line 3)  (ert-should (= 0 (current-indentation)))
    ))

(ert-deftest nxhtml-ert-indent-bug-johan-2010-02-12()
  "Test of eRuby indentation.
Got a bug report by mail on the emacs-on-rails list."
  (ert-with-temp-buffer-include-file "bug-johan-2010-02-12.rhtml"
    (add-hook 'ert-simulate-command-post-hook
              'nxhtmltest-should-no-mumamo-errors
              nil t)
    (ert-simulate-command '(eruby-html-mumamo-mode) t)
    (nxhtmltest-fontify-default-way 2 "trans")
    (ert-simulate-command '(mark-whole-buffer) t)
    (ert-simulate-command '(indent-for-tab-command) t)
    (nxhtmltest-goto-line 12)  (ert-should (= 2 (current-indentation)))
    ))

;;(setq nxhtmltest-ert-default-selector "nxhtml-ert-indent-rr-min8")
(ert-deftest nxhtml-ert-indent-rr-min8 ()
  "Test of indentation bug.
As per Richard Riley's bug report 2009-10-08.  Last line gave an
error."
  (ert-with-temp-buffer-include-file "rr-min8.php"
    (add-hook 'ert-simulate-command-post-hook
              'nxhtmltest-should-no-mumamo-errors
              nil t)
    (ert-simulate-command '(nxhtml-mumamo-mode) t)
    (nxhtmltest-fontify-default-way 2 "trans")
    (ert-simulate-command '(mark-whole-buffer) t)
    (ert-simulate-command '(indent-for-tab-command) t)))

;;(setq nxhtmltest-ert-default-selector "nxhtml-ert-bug-400415")
(ert-deftest nxhtml-ert-bug-400415-foo2 ()
  "Test for changes before in-here-doc using 400415.
See URL `https://bugs.launchpad.net/nxhtml/+bug/400415'. This is
not the bug reported there however."
  (ert-with-temp-buffer-include-file "bug400415-foo2.php"
    (add-hook 'ert-simulate-command-post-hook
              'nxhtmltest-should-no-mumamo-errors
              nil t)
    (ert-simulate-command '(nxhtml-mumamo-mode) t)
    (nxhtmltest-fontify-default-way 2 "trans")
    (ert-simulate-command '(goto-char 74) t)
    (ert-should (eq major-mode 'sql-mode))
    (ert-simulate-command '(goto-char 23) t)
    (ert-simulate-command '(backward-delete-char-untabify 1) t)
    (ert-simulate-command '(goto-char 74) t)
    (ert-should (eq major-mode 'sql-mode))
    ))

(ert-deftest nxhtml-ert-bug-300946-index ()
  "Test for bug 300946 in Launchpad.
See URL `https://bugs.launchpad.net/nxhtml/+bug/300946'.  This is
a test for the file attached by Chris on 2008-12-02."
  (ert-with-temp-buffer-include-file "bug-300946-index.html"
    (add-hook 'ert-simulate-command-post-hook
              'nxhtmltest-should-no-mumamo-errors
              nil t)
    (ert-simulate-command '(nxhtml-mumamo-mode) t)
    (font-lock-mode 1)
    ))

(ert-deftest nxhtml-ert-indent-bug290364 ()
  "Test for bug 290364 in Launchpad.
See URL `https://bugs.launchpad.net/nxhtml/+bug/290364'.

Note: If this test fails Emacs loops.  Therefore the whole test
is included in a when clause so you can avoid it easily."
  ;;(when t
    (ert-with-temp-buffer-include-file "bug-290364.php"
      (add-hook 'ert-simulate-command-post-hook
                'nxhtmltest-should-no-mumamo-errors
                nil t)
      (ert-simulate-command '(nxhtml-mumamo-mode) t)
      (font-lock-mode 1)
      ))
;)

(ert-deftest nxhtml-ert-indent-bug271497 ()
  "Test for bug 271497 in Launchpad.
This is a bug in Emacs 22. It should work in Emacs 23 though.
See URL `https://bugs.launchpad.net/nxhtml/+bug/271497'."
  (ert-with-temp-buffer-include-file "bug271497.txt"
    (add-hook 'ert-simulate-command-post-hook
              'nxhtmltest-should-no-mumamo-errors
              nil t)
    (load-file (ert-get-test-file-name "bug271497.el"))
    (ert-simulate-command '(bug271497-mumamo) t)
    ;;(font-lock-mode 1)
    (nxhtmltest-fontify-default-way 2 "trans")
    (ert-simulate-command '(goto-char 42) t)
    (message "after goto-char 42")
    (let ((ac42 after-change-functions)
          ac88)
      (ert-simulate-command '(goto-char 88) t)
      (message "after goto-char 88")
      (setq ac88 after-change-functions)
      (ert-should (not (equal ac88 ac42))))))

(ert-deftest nxhtml-ert-indent-question43320 ()
  "Test for question 43320 in Launchpad.
See URL `https://answers.launchpad.net/nxhtml/+question/43320'.

Note: This fails in Emacs 22, but should work in Emacs 23."
;; I did see some problem here:

;; - nXhtml 081222 + unpatched Emacs 081219 => ok
;; - nXhtml 081222 + unpatched Emacs 081124 => ok
;; - nXhtml 081222 + patched Emacs 081219 => ok

;; - nXhtml 081222 + patched Emacs 081124 => ok, but it fails if I
;;   use `nxhtmltest-run-Q'! I e, it fails if the autostart.el from
;;   the nxhtml dir in 081222 is used - but not if the copy in
;;   c:/EmacsW32 is used??? Which turned out to be if the old
;;   php-mode was used ...

  (ert-with-temp-buffer-include-file "question43320.html"
    (add-hook 'ert-simulate-command-post-hook
              'nxhtmltest-should-no-mumamo-errors
              nil t)
    (ert-simulate-command '(nxhtml-mumamo-mode) t)
    (font-lock-mode 1)
    (nxhtmltest-goto-line 25)  (ert-should (/= 14 (current-indentation)))
    (put 'mumamo-submode-indent-offset-0 'permanent-local t)
    (put 'mumamo-submode-indent-offset 'permanent-local t)
    ;;
    ;;(set (make-local-variable 'mumamo-submode-indent-offset-0) nil)
    (set (make-local-variable 'mumamo-submode-indent-offset-0) 0)
    (set (make-local-variable 'mumamo-submode-indent-offset) nil)
    ;;(set (make-local-variable 'mumamo-submode-indent-offset) 2)
    (ert-simulate-command '(mark-whole-buffer) t)
    (ert-simulate-command '(indent-for-tab-command) t)
    (nxhtmltest-goto-line 8)   (ert-should (= 8 (current-indentation)))
    (nxhtmltest-goto-line 9)   (ert-should (= 0 (current-indentation)))
    (nxhtmltest-goto-line 15)  (ert-should (= 8 (current-indentation)))
    (nxhtmltest-goto-line 16)  (ert-should (= 8 (current-indentation)))
    (nxhtmltest-goto-line 22)  (ert-should (= 6 (current-indentation)))
    (nxhtmltest-goto-line 25)  (ert-should (= 4 (current-indentation)))
    (nxhtmltest-goto-line 8) (indent-line-to 0)
    ;;(message "before indent-for-tab-command")
    (ert-simulate-command '(indent-for-tab-command) t)
    ;;(message "after indent-for-tab-command")
    (ert-should (= 8 (current-indentation)))
    ;;
    (set (make-local-variable 'mumamo-submode-indent-offset-0) 0)
    (set (make-local-variable 'mumamo-submode-indent-offset) 2)
    (ert-simulate-command '(mark-whole-buffer) t)
    (ert-simulate-command '(indent-for-tab-command) t)
    (nxhtmltest-goto-line 8)   (ert-should (= 8 (current-indentation)))
    (nxhtmltest-goto-line 9)   (ert-should (= 10 (current-indentation)))
    (nxhtmltest-goto-line 15)  (ert-should (= 8 (current-indentation)))
    (nxhtmltest-goto-line 16)  (ert-should (= 8 (current-indentation)))
    (nxhtmltest-goto-line 22)  (ert-should (= 16 (current-indentation)))
    (nxhtmltest-goto-line 25)  (ert-should (= 14 (current-indentation)))
    ))

(ert-deftest nxhtml-ert-only-php-no-end ()
  "Check for nXml error."
  (ert-with-temp-buffer-include-file "no-php-end-4.php"
    (nxhtml-mumamo-mode)
    (run-hooks 'after-change-major-mode-hook)
    (run-hooks 'post-command-hook)
    (nxhtmltest-fontify-default-way 2 "trans")
    (rng-validate-mode 1)
    ;;(rngalt-validate)
    (ert-should (eq rng-validate-mode t))
    (nxhtmltest-should-no-mumamo-errors)
    (nxhtmltest-should-no-nxml-errors)
    (goto-char 324)
    (message "before insert, after-change-functions local=%s" after-change-functions)
    (insert "\n")
    (nxhtmltest-should-no-mumamo-errors)
    (nxhtmltest-should-no-nxml-errors)))

(ert-deftest nxhtml-ert-xhtml-1.0-transitional ()
  "Test XHTML 1.0 Transitional with `nxhtml-mumamo-mode'.
NOTICE: This test SHOULD FAIL because there is currently no rng
schema for transitional. The schema for strict is used instead
and the file is invalid then."
  (ert-with-temp-buffer-include-file "lg-080813-label.html"
    (nxhtml-mumamo-mode)
    (nxhtmltest-fontify-default-way 2 "trans")
    (rng-validate-mode 1)
    (rngalt-validate)
    (ert-should (eq rng-validate-mode t))
    (nxhtmltest-should-no-mumamo-errors)
;;;     (ert-should
;;;      (not (eq (get-char-property 398 'category)
;;;               'rng-error)))
    (ert-should
     (eq (get-text-property 398 'face)
         'font-lock-function-name-face))
    (ert-should-not
     (= 0 rng-error-count))
    ))

(ert-deftest nxhtml-ert-genshi-valid-in-genshi ()
  (ert-with-temp-buffer-include-file "genshi-auto-mode.html"
    (message "\n")
    (genshi-nxhtml-mumamo-mode)
    (font-lock-mode 1)
    (mumamo-post-command)
    (ert-should (eq font-lock-mode t))
    (ert-should (eq major-mode 'nxhtml-genshi-mode))
    (ert-should
     (memq mumamo-multi-major-mode '(genshi-nxhtml-mumamo-mode
                                     genshi-html-mumamo-mode)))
    (nxhtmltest-fontify-default-way 2 "sheit")
    (rng-validate-mode 1)
    (rngalt-validate)
    (ert-should (eq rng-validate-mode t))
    (nxhtmltest-should-no-mumamo-errors)
    (ert-should
      (= 0 rng-error-count))))

(ert-deftest nxhtml-ert-genshi-invalid-in-nxhtml ()
  (ert-with-temp-buffer-include-file "genshi-auto-mode.html"
    (message "\n")
    (nxhtml-mumamo-mode)
    (nxhtmltest-fontify-default-way 2 "sheit")
    (font-lock-mode 1)
    (mumamo-post-command)
    (rng-validate-mode 1)
    (rngalt-validate)
    (ert-should (eq rng-validate-mode t))
    (nxhtmltest-should-no-mumamo-errors)
    (ert-should
      (= 2 rng-error-count))))

(ert-deftest nxhtml-ert-genshi-magic-mode ()
  "Test if genshi file is recognized."
  (let ((file1 (ert-get-test-file-name "genshi-auto-mode.html"))
        buf1)
    ;; Ensure we open the files
    (setq buf1 (find-buffer-visiting file1))
    (when buf1 (kill-buffer buf1))
    ;; Open file 1
    (setq buf1 (find-file file1))
    (nxhtmltest-fontify-default-way 2 "mod")
    (nxhtmltest-should-no-mumamo-errors)
    (ert-should
     (with-current-buffer buf1
       (memq mumamo-multi-major-mode '(genshi-nxhtml-mumamo-mode
                                       genshi-html-mumamo-mode))))
    (kill-buffer buf1)))

(ert-deftest nxhtml-ert-genshi-auto-mode ()
  "Test if file extension .ghtml is recognized."
  (let ((file1 (ert-get-test-file-name "genshi-HelloWorldPage.ghtml"))
        buf1)
    ;; Ensure we open the files
    (setq buf1 (find-buffer-visiting file1))
    (when buf1 (kill-buffer buf1))
    ;; Open file 1
    (setq buf1 (find-file file1))
    (nxhtmltest-fontify-default-way 2 "mod")
    (nxhtmltest-should-no-mumamo-errors)
    (ert-should
     (with-current-buffer buf1
       (memq mumamo-multi-major-mode '(genshi-nxhtml-mumamo-mode
                                       genshi-html-mumamo-mode))))
    (kill-buffer buf1)))

(ert-deftest nxhtml-ert-opened-modified ()
  "Test if buffer get modified when opening a file."
  (let ((file1 (ert-get-test-file-name "cvd-080805-ac.php"))
        (file2 (ert-get-test-file-name "cvd-080805-cc.php"))
        buf1
        buf2)
    ;; Ensure we open the files
    (setq buf1 (find-buffer-visiting file1))
    (when buf1 (kill-buffer buf1))
    (setq buf2 (find-buffer-visiting file2))
    (when buf2 (kill-buffer buf2))
    ;; Open file 1
    (setq buf1 (find-file file1))
    (nxhtmltest-fontify-default-way 2 "mod")
    (nxhtmltest-should-no-mumamo-errors)
    ;; Open file 2
    (setq buf2 (find-file file2))
    (nxhtmltest-fontify-default-way 2 "mod")
    (nxhtmltest-should-no-mumamo-errors)
    (ert-should
     (not (or (buffer-modified-p buf1)
              (buffer-modified-p buf2))))
    (kill-buffer buf1)
    (kill-buffer buf2)))

(ert-deftest nxhtml-ert-wiki-strange-hili-080629 ()
  "From a report on EmacsWiki."
  (ert-with-temp-buffer-include-file "wiki-strange-hili-080629.html"
    ;;(ert-should (not font-lock-mode))
    (nxhtml-mumamo-mode)
    ;;(ert-should (not font-lock-mode))
    (nxhtmltest-fontify-default-way 2 "hili")
    (goto-char 44)
    (nxhtmltest-should-no-mumamo-errors)
    (message "face at 44=%s" (get-text-property 44 'face))
    (ert-should
     (eq (get-text-property 44 'face)
         'font-lock-function-name-face))))

(ert-deftest nxhtml-ert-indent-wiki-080708-ind-problem ()
  (ert-with-temp-buffer-include-file "wiki-080708-ind-problem.rhtml"
    (require 'ruby-mode nil t)
    (if (not (featurep 'ruby-mode))
        ;; Fix-me: ert should maybe have some way to just display
        ;; informational messages?
        (error "ruby-mode not available, skipping test")
      ;;(ert-should (not font-lock-mode))
      (eruby-nxhtml-mumamo-mode)
      ;;(ert-should (not font-lock-mode))
      (nxhtmltest-fontify-default-way 2 "ind")
      (mark-whole-buffer)
      (indent-for-tab-command)
      (nxhtmltest-goto-line 3)
      (nxhtmltest-should-no-mumamo-errors)
      (ert-should (= (current-indentation) 0)))))

(ert-deftest nxhtml-ert-indent-wiki-080708-ind-problem-a ()
  "From a report on EmacsWiki.
NOTICE: This SHOULD FAIL. There is currently no support for the
kind of indentation needed here.

Notice 2: For some reason I sometimes get the error overlayp, nil
here."
  (ert-with-temp-buffer-include-file "wiki-080708-ind-problem.rhtml"
    (require 'ruby-mode nil t)
    (if (not (featurep 'ruby-mode))
        (error "ruby-mode not available, skipping test")
      ;;(ert-should (not font-lock-mode))
      (eruby-nxhtml-mumamo-mode)
      ;;(ert-should (not font-lock-mode))
      (nxhtmltest-fontify-default-way 2 "ind")
      (insert "  ")
      (mark-whole-buffer)
      (indent-for-tab-command)
      (nxhtmltest-goto-line 3)
      ;; Test
      (nxhtmltest-should-no-mumamo-errors)
      (ert-should-not (= (current-indentation) 2)))))

(ert-deftest nxhtml-ert-sheit-2007-12-26 ()
  (ert-with-temp-buffer-include-file "sheit-2007-12-26.php"
    ;;(ert-should (not font-lock-mode))
    (nxhtml-mumamo-mode)
    ;;(ert-should (not font-lock-mode))
    (nxhtmltest-fontify-default-way 2 "sheit")
    (nxhtmltest-should-no-mumamo-errors)
    (ert-should
     (and
      (eq (get-text-property 21 'face)
          'font-lock-comment-face)
      (eq (get-text-property 22 'face)
          'font-lock-comment-face)
      (eq (get-text-property 35 'face)
          'font-lock-comment-face)))))


;; Now some tests with a big file. Jumping backwards can fail.

(defun nxhtml-ert-nxhtml-changes-jump-back-2 (pos)
  ;;(ert-should (not font-lock-mode))
  (nxhtml-mumamo-mode)
  (run-hooks 'post-command-hook)
  ;;(ert-should (not font-lock-mode))
  (goto-char (- (point-max) (- 64036 63869)))
  (nxhtmltest-fontify-default-way 2)
  (nxhtmltest-should-no-mumamo-errors)
  (ert-should
   (eq (get-text-property (point) 'face)
       'font-lock-variable-name-face))
  (message "here 1")
  (goto-char pos)
  (nxhtmltest-fontify-default-way 2)
  (nxhtmltest-should-no-mumamo-errors)
  (message "here 2")
  (ert-should
   (eq (get-text-property (point) 'face)
       'font-lock-function-name-face)))

;; Fix-me: forgot to copy nxhtml-changes.html. I can't find any
;; similar error now.
;;
;; (ert-deftest nxhtml-ert-nxhtml-changes-jump-back-7014-2 ()
;;   "this is a docstring.
;; wonder how that works now ..."
;;   (ert-with-temp-buffer-include-file "../../nxhtml/doc/nxhtml-changes.html"
;;     (nxhtml-ert-nxhtml-changes-jump-back-2 7014)))

;; (ert-deftest nxhtml-ert-nxhtml-changes-jump-back-10488-2 ()
;;   (ert-with-temp-buffer-include-file "../../nxhtml/doc/nxhtml-changes.html"
;;     (nxhtml-ert-nxhtml-changes-jump-back-2 10488)))

;; (ert-deftest nxhtml-ert-nxhtml-changes-jump-2 ()
;;   (ert-with-temp-buffer-include-file "../../nxhtml/doc/nxhtml-changes.html"
;;     ;;(ert-should (not font-lock-mode))
;;     (nxhtml-mumamo-mode)
;;     ;;(ert-should (not font-lock-mode))
;;     (goto-char 10420)
;;     (nxhtmltest-fontify-default-way 2 "jump-2")
;;     (nxhtmltest-should-no-mumamo-errors)
;;     (ert-should
;;      (eq (get-text-property (point) 'face)
;;          'font-lock-variable-name-face))))

;;; Indentation tests

(ert-deftest nxhtml-ert-php-indent-bug-1 ()
  "Test indentation in php only file.
The indentation on line 7 should be 0."
  (ert-with-temp-buffer-include-file "only-php.php"
    (nxhtml-mumamo-mode)
    ;; No fontification needed for indentation.
    (nxhtmltest-goto-line 7)
    (indent-for-tab-command)
    (nxhtmltest-should-no-mumamo-errors)
    (ert-should
     (= 0
        (current-indentation)))))

;;; Scroll tests

;; (ert-deftest nxhtml-ert-scroll-jump-test ()
;;   "Test if `scroll-conservatively' eq 1 works."
;;   (ert-with-temp-buffer-include-file "../../nxhtml/doc/nxhtml-changes.html"
;;     (ert-should (not font-lock-mode))
;;     (nxhtml-mumamo-mode)
;;     (ert-should (not font-lock-mode))
;;     (nxhtmltest-fontify-default-way 2 "jump-2")
;;     (let ((scroll-conservatively 1)
;;           (ws (list (window-start)))
;;           (xi (loop for ii from 1 to 100 by 1
;;                     do
;;                     (next-line)
;;                     (sit-for 0.01)
;;                     collect (list (window-start)
;;                                   (let ((here (point)))
;;                                     (goto-char (window-start))
;;                                     (prog1 (line-end-position)
;;                                       (goto-char here)))
;;                                   (point))
;;                     ))
;;           (jumps 0)
;;           prev-win-start
;;           prev-win-start-le
;;           )
;;       (loop for xx in xi
;;             do
;;             (message "xx=%s" xx)
;;             (let ((win-start (nth 0 xx))
;;                   (win-start-le (nth 1 xx))
;;                   (cur-point (nth 2 xx)))
;;               (unless (or (not prev-win-start)
;;                           (= prev-win-start win-start)
;;                           (= (1+ prev-win-start-le) win-start))
;;                 (setq jumps (1+ jumps)))
;;               (setq prev-win-start win-start)
;;               (setq prev-win-start-le win-start-le)
;;               )
;;             )
;;       (ert-should (= 0 jumps))
;;       )))

;;(defvar ert-error-on-test-redefinition nil)

;;; End of test definitions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun nxhtmltest-run-ert (selector)
  "Run test with ert library."
  (unless selector (setq selector nxhtmltest-ert-default-selector))
  (setq ert-test-files-root nxhtmltest-files-root)
  (if noninteractive
      (ert-run-tests-batch selector)
    (ert-kill-temp-test-buffers)
    (ert-run-tests-interactively selector)
    (other-window 1)
    (ert-list-temp-test-buffers)))

;;;###autoload
(defun nxhtmltest-run-indent ()
  "Run indentation tests."
  (interactive)
  (setq ert-test-files-root nxhtmltest-files-root)
  (let ((selector "nxhtml-ert-indent-"))
    (ert-kill-temp-test-buffers)
    (nxhtmltest-get-fontification-method)
    (ert-run-tests-interactively selector))
  (other-window 1)
  (ert-list-temp-test-buffers))

;;;###autoload
(defun nxhtmltest-run ()
  "Run all tests defined for nXhtml.
Currently there are only tests using ert.el defined.

Note that it is currently expected that the following tests will
fail (they corresponds to known errors in nXhtml/Emacs):

  `nxhtml-ert-nxhtml-changes-jump-back-10549'
  `nxhtml-ert-nxhtml-changes-jump-back-7014'
"
  (interactive)
  (setq message-log-max t)
  (when (called-interactively-p)
    (nxhtmltest-get-fontification-method))
  (nxhtmltest-run-ert nil))

(when (getenv "nxhtmltest-run-Q")
  (nxhtmltest-run))

(provide 'nxhtmltest-suites)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; nxhtmltest-suites.el ends here