blob: d66d53001930282fe12698e3d5e48f673a43c6d2 [file] [log] [blame]
Haojian Wu0e1a50e2016-10-05 10:04:13 +00001;;; clang-include-fixer-test.el --- unit tests for clang-include-fixer.el -*- lexical-binding: t; -*-
2
3;;; Commentary:
4
5;; Unit tests for clang-include-fixer.el.
6
7;;; Code:
8
Manuel Klimek8e5f5ff2016-10-25 11:30:28 +00009(require 'clang-include-fixer)
10
Haojian Wu0e1a50e2016-10-05 10:04:13 +000011(require 'cc-mode)
12(require 'ert)
13
14(ert-deftest clang-include-fixer--insert-line ()
15 "Unit test for `clang-include-fixer--insert-line'."
16 (with-temp-buffer
17 (insert "aa\nab\nac\nad\n")
18 (let ((from (current-buffer)))
19 (with-temp-buffer
20 (insert "aa\nac\nad\n")
21 (let ((to (current-buffer)))
22 (should (clang-include-fixer--insert-line from to))
23 (should (equal (buffer-string) "aa\nab\nac\nad\n")))))
24 (should (equal (buffer-string) "aa\nab\nac\nad\n"))))
25
Manuel Klimekc38cd692017-02-23 16:02:53 +000026(ert-deftest clang-include-fixer--insert-line-diff-on-empty-line ()
27 "Unit test for `clang-include-fixer--insert-line'."
28 (with-temp-buffer
29 (insert "aa\nab\n\nac\nad\n")
30 (let ((from (current-buffer)))
31 (with-temp-buffer
32 (insert "aa\n\nac\nad\n")
33 (let ((to (current-buffer)))
34 (should (clang-include-fixer--insert-line from to))
35 (should (equal (buffer-string) "aa\nab\n\nac\nad\n")))))
36 (should (equal (buffer-string) "aa\nab\n\nac\nad\n"))))
37
Haojian Wu0e1a50e2016-10-05 10:04:13 +000038(ert-deftest clang-include-fixer--symbol-at-point ()
39 "Unit test for `clang-include-fixer--symbol-at-point'."
40 (with-temp-buffer
41 (insert "a+bbb::cc")
42 (c++-mode)
43 (goto-char (point-min))
44 (should (equal (clang-include-fixer--symbol-at-point) "a"))
45 (forward-char)
46 ;; Emacs treats the character immediately following a symbol as part of the
47 ;; symbol.
48 (should (equal (clang-include-fixer--symbol-at-point) "a"))
49 (forward-char)
50 (should (equal (clang-include-fixer--symbol-at-point) "bbb::cc"))
51 (goto-char (point-max))
52 (should (equal (clang-include-fixer--symbol-at-point) "bbb::cc"))))
53
Haojian Wud7b45bc2017-03-06 14:49:26 +000054(ert-deftest clang-include-fixer--highlight ()
55 (with-temp-buffer
56 (insert "util::Status foo;\n")
57 (setq buffer-file-coding-system 'utf-8-unix)
58 (should (equal nil (clang-include-fixer--highlight
59 '((Range . ((Offset . 0) (Length . 0)))))))
60 (let ((overlay (clang-include-fixer--highlight
61 '((Range . ((Offset . 1) (Length . 12)))))))
62 (should (equal 2 (overlay-start overlay)))
63 (should (equal 14 (overlay-end overlay))))))
64
Haojian Wu0e1a50e2016-10-05 10:04:13 +000065;;; clang-include-fixer-test.el ends here