66 lines · plain
1;;; 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 9(require 'clang-include-fixer)10 11(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-buffer17 (insert "aa\nab\nac\nad\n")18 (let ((from (current-buffer)))19 (with-temp-buffer20 (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 26(ert-deftest clang-include-fixer--insert-line-diff-on-empty-line ()27 "Unit test for `clang-include-fixer--insert-line'."28 (with-temp-buffer29 (insert "aa\nab\n\nac\nad\n")30 (let ((from (current-buffer)))31 (with-temp-buffer32 (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 38(ert-deftest clang-include-fixer--symbol-at-point ()39 "Unit test for `clang-include-fixer--symbol-at-point'."40 (with-temp-buffer41 (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 the47 ;; 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 54(ert-deftest clang-include-fixer--highlight ()55 (with-temp-buffer56 (insert "util::Status foo;\n")57 (setq buffer-file-coding-system 'utf-8-unix)58 (should (equal nil (clang-include-fixer--highlight59 '((Range . ((Offset . 0) (Length . 0)))))))60 (let ((overlay (clang-include-fixer--highlight61 '((Range . ((Offset . 1) (Length . 12)))))))62 (should (equal 2 (overlay-start overlay)))63 (should (equal 14 (overlay-end overlay))))))64 65;;; clang-include-fixer-test.el ends here66