diff options
| author | Juri Linkov | 2019-02-02 23:23:16 +0200 |
|---|---|---|
| committer | Juri Linkov | 2019-02-02 23:23:16 +0200 |
| commit | 42c8399059bb311c8cfaf9428f0a29032d71011d (patch) | |
| tree | c6f6a6596fffe3339004294e63e309e4a57ab9c9 /test | |
| parent | adc31c6bdcdb52c2bc0240982d3e8ce870af1fab (diff) | |
| download | emacs-42c8399059bb311c8cfaf9428f0a29032d71011d.tar.gz emacs-42c8399059bb311c8cfaf9428f0a29032d71011d.zip | |
* test/lisp/vc/diff-mode-tests.el (diff-mode-test-font-lock): New test.
(diff-mode-test-font-lock-syntax-one-line): New test for one line.
* test/data/vc/diff-mode/hello_world.c:
* test/data/vc/diff-mode/hello_world_1.c:
* test/data/vc/diff-mode/hello_emacs.c:
* test/data/vc/diff-mode/hello_emacs_1.c: New fixtures.
* lisp/vc/diff-mode.el (diff-syntax-fontify): Move remove-overlays
from diff-syntax-fontify-hunk. (Bug#33567)
(diff-syntax-fontify-hunk): Remove VISIT arg from insert-file-contents.
Diffstat (limited to 'test')
| -rw-r--r-- | test/data/vc/diff-mode/hello_emacs.c | 6 | ||||
| -rw-r--r-- | test/data/vc/diff-mode/hello_emacs_1.c | 1 | ||||
| -rw-r--r-- | test/data/vc/diff-mode/hello_world.c | 6 | ||||
| -rw-r--r-- | test/data/vc/diff-mode/hello_world_1.c | 1 | ||||
| -rw-r--r-- | test/lisp/vc/diff-mode-tests.el | 112 |
5 files changed, 126 insertions, 0 deletions
diff --git a/test/data/vc/diff-mode/hello_emacs.c b/test/data/vc/diff-mode/hello_emacs.c new file mode 100644 index 00000000000..c7ed7538c3a --- /dev/null +++ b/test/data/vc/diff-mode/hello_emacs.c | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | int main() | ||
| 3 | { | ||
| 4 | printf("Hello, Emacs!\n"); | ||
| 5 | return 0; | ||
| 6 | } | ||
diff --git a/test/data/vc/diff-mode/hello_emacs_1.c b/test/data/vc/diff-mode/hello_emacs_1.c new file mode 100644 index 00000000000..62145a6b44a --- /dev/null +++ b/test/data/vc/diff-mode/hello_emacs_1.c | |||
| @@ -0,0 +1 @@ | |||
| int main() { printf("Hello, Emacs!\n"); return 0; } \ No newline at end of file | |||
diff --git a/test/data/vc/diff-mode/hello_world.c b/test/data/vc/diff-mode/hello_world.c new file mode 100644 index 00000000000..dcbe06c6012 --- /dev/null +++ b/test/data/vc/diff-mode/hello_world.c | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | int main() | ||
| 3 | { | ||
| 4 | printf("Hello, World!\n"); | ||
| 5 | return 0; | ||
| 6 | } | ||
diff --git a/test/data/vc/diff-mode/hello_world_1.c b/test/data/vc/diff-mode/hello_world_1.c new file mode 100644 index 00000000000..606afb371cb --- /dev/null +++ b/test/data/vc/diff-mode/hello_world_1.c | |||
| @@ -0,0 +1 @@ | |||
| int main() { printf("Hello, World!\n"); return 0; } \ No newline at end of file | |||
diff --git a/test/lisp/vc/diff-mode-tests.el b/test/lisp/vc/diff-mode-tests.el index 4276974c2ac..8e690548f05 100644 --- a/test/lisp/vc/diff-mode-tests.el +++ b/test/lisp/vc/diff-mode-tests.el | |||
| @@ -21,7 +21,10 @@ | |||
| 21 | ;;; Code: | 21 | ;;; Code: |
| 22 | 22 | ||
| 23 | (require 'diff-mode) | 23 | (require 'diff-mode) |
| 24 | (require 'diff) | ||
| 24 | 25 | ||
| 26 | (defconst diff-mode-tests--datadir | ||
| 27 | (expand-file-name "test/data/vc/diff-mode" source-directory)) | ||
| 25 | 28 | ||
| 26 | (ert-deftest diff-mode-test-ignore-trailing-dashes () | 29 | (ert-deftest diff-mode-test-ignore-trailing-dashes () |
| 27 | "Check to make sure we successfully ignore trailing -- made by | 30 | "Check to make sure we successfully ignore trailing -- made by |
| @@ -199,5 +202,114 @@ youthfulness | |||
| 199 | (kill-buffer buf2) | 202 | (kill-buffer buf2) |
| 200 | (delete-directory temp-dir 'recursive)))))) | 203 | (delete-directory temp-dir 'recursive)))))) |
| 201 | 204 | ||
| 205 | (ert-deftest diff-mode-test-font-lock () | ||
| 206 | "Check font-locking of diff hunks." | ||
| 207 | (let ((default-directory diff-mode-tests--datadir) | ||
| 208 | (old "hello_world.c") | ||
| 209 | (new "hello_emacs.c") | ||
| 210 | (diff-buffer (get-buffer-create "*Diff*")) | ||
| 211 | (diff-font-lock-refine t) | ||
| 212 | (diff-font-lock-syntax t) | ||
| 213 | diff-beg) | ||
| 214 | (diff-no-select old new '("-u") 'no-async diff-buffer) | ||
| 215 | (with-current-buffer diff-buffer | ||
| 216 | (font-lock-ensure) | ||
| 217 | (narrow-to-region (progn (diff-hunk-next) | ||
| 218 | (setq diff-beg (diff-beginning-of-hunk))) | ||
| 219 | (diff-end-of-hunk)) | ||
| 220 | |||
| 221 | (should (equal-including-properties | ||
| 222 | (buffer-string) | ||
| 223 | #("@@ -1,6 +1,6 @@ | ||
| 224 | #include <stdio.h> | ||
| 225 | int main() | ||
| 226 | { | ||
| 227 | - printf(\"Hello, World!\\n\"); | ||
| 228 | + printf(\"Hello, Emacs!\\n\"); | ||
| 229 | return 0; | ||
| 230 | } | ||
| 231 | " | ||
| 232 | 0 15 (face diff-hunk-header) | ||
| 233 | 16 36 (face diff-context) | ||
| 234 | 36 48 (face diff-context) | ||
| 235 | 48 51 (face diff-context) | ||
| 236 | 51 52 (face diff-indicator-removed) | ||
| 237 | 52 81 (face diff-removed) | ||
| 238 | 81 82 (face diff-indicator-added) | ||
| 239 | 82 111 (face diff-added) | ||
| 240 | 111 124 (face diff-context) | ||
| 241 | 124 127 (face diff-context)))) | ||
| 242 | |||
| 243 | (should (equal (mapcar (lambda (o) | ||
| 244 | (list (- (overlay-start o) diff-beg) | ||
| 245 | (- (overlay-end o) diff-beg) | ||
| 246 | (append (and (overlay-get o 'diff-mode) | ||
| 247 | `(diff-mode ,(overlay-get o 'diff-mode))) | ||
| 248 | (and (overlay-get o 'face) | ||
| 249 | `(face ,(overlay-get o 'face)))))) | ||
| 250 | (sort (overlays-in (point-min) (point-max)) | ||
| 251 | (lambda (a b) (< (overlay-start a) (overlay-start b))))) | ||
| 252 | '((0 127 (diff-mode fine)) | ||
| 253 | (0 127 (diff-mode syntax)) | ||
| 254 | (17 25 (diff-mode syntax face font-lock-preprocessor-face)) | ||
| 255 | (26 35 (diff-mode syntax face font-lock-string-face)) | ||
| 256 | (37 40 (diff-mode syntax face font-lock-type-face)) | ||
| 257 | (41 45 (diff-mode syntax face font-lock-function-name-face)) | ||
| 258 | (61 78 (diff-mode syntax face font-lock-string-face)) | ||
| 259 | (69 74 (diff-mode fine face diff-refine-removed)) | ||
| 260 | (91 108 (diff-mode syntax face font-lock-string-face)) | ||
| 261 | (99 104 (diff-mode fine face diff-refine-added)) | ||
| 262 | (114 120 (diff-mode syntax face font-lock-keyword-face)))))))) | ||
| 263 | |||
| 264 | (ert-deftest diff-mode-test-font-lock-syntax-one-line () | ||
| 265 | "Check diff syntax highlighting for one line with no newline at end." | ||
| 266 | (let ((default-directory diff-mode-tests--datadir) | ||
| 267 | (old "hello_world_1.c") | ||
| 268 | (new "hello_emacs_1.c") | ||
| 269 | (diff-buffer (get-buffer-create "*Diff*")) | ||
| 270 | (diff-font-lock-refine nil) | ||
| 271 | (diff-font-lock-syntax t) | ||
| 272 | diff-beg) | ||
| 273 | (diff-no-select old new '("-u") 'no-async diff-buffer) | ||
| 274 | (with-current-buffer diff-buffer | ||
| 275 | (font-lock-ensure) | ||
| 276 | (narrow-to-region (progn (diff-hunk-next) | ||
| 277 | (setq diff-beg (diff-beginning-of-hunk))) | ||
| 278 | (diff-end-of-hunk)) | ||
| 279 | |||
| 280 | (should (equal-including-properties | ||
| 281 | (buffer-string) | ||
| 282 | #("@@ -1 +1 @@ | ||
| 283 | -int main() { printf(\"Hello, World!\\n\"); return 0; } | ||
| 284 | \\ No newline at end of file | ||
| 285 | +int main() { printf(\"Hello, Emacs!\\n\"); return 0; } | ||
| 286 | \\ No newline at end of file | ||
| 287 | " | ||
| 288 | 0 11 (face diff-hunk-header) | ||
| 289 | 12 13 (face diff-indicator-removed) | ||
| 290 | 13 65 (face diff-removed) | ||
| 291 | 65 93 (face diff-context) | ||
| 292 | 93 94 (face diff-indicator-added) | ||
| 293 | 94 146 (face diff-added) | ||
| 294 | 146 174 (face diff-context)))) | ||
| 295 | |||
| 296 | (should (equal (mapcar (lambda (o) | ||
| 297 | (list (- (overlay-start o) diff-beg) | ||
| 298 | (- (overlay-end o) diff-beg) | ||
| 299 | (append (and (overlay-get o 'diff-mode) | ||
| 300 | `(diff-mode ,(overlay-get o 'diff-mode))) | ||
| 301 | (and (overlay-get o 'face) | ||
| 302 | `(face ,(overlay-get o 'face)))))) | ||
| 303 | (sort (overlays-in (point-min) (point-max)) | ||
| 304 | (lambda (a b) (< (overlay-start a) (overlay-start b))))) | ||
| 305 | '((0 174 (diff-mode syntax)) | ||
| 306 | (13 16 (diff-mode syntax face font-lock-type-face)) | ||
| 307 | (17 21 (diff-mode syntax face font-lock-function-name-face)) | ||
| 308 | (33 50 (diff-mode syntax face font-lock-string-face)) | ||
| 309 | (53 59 (diff-mode syntax face font-lock-keyword-face)) | ||
| 310 | (94 97 (diff-mode syntax face font-lock-type-face)) | ||
| 311 | (98 102 (diff-mode syntax face font-lock-function-name-face)) | ||
| 312 | (114 131 (diff-mode syntax face font-lock-string-face)) | ||
| 313 | (134 140 (diff-mode syntax face font-lock-keyword-face)))))))) | ||
| 202 | 314 | ||
| 203 | (provide 'diff-mode-tests) | 315 | (provide 'diff-mode-tests) |