llvm-project/clang-tools-extra/clang-include-fixer/tool/clang-include-fixer-test.el

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

66 lines
2.3 KiB
EmacsLisp
Raw Normal View History

Overhaul clang-include-fixer.el General overhaul to fix many coding bugs, simplify the code, and improve readability. * Clarify documentation strings of user options. * Say that clang-include-fixer-executable is a file to have auto completion. * Allow user to select available options for clang-include-fixer-input-format. Turn it into a symbol as it's not a free-form string. * Remove clang-include-fixer-query-mode. This option was apparently used to select between two different operation modes, which is not a typical use case for user options. Provide two separate commands instead. * Add a face for the overlay highlighting so that users can customize it. Move user commands to the front so that readers of the code aren't buried in internal functions. * Make process calls asynchronous. This is possible here because clang-include-fixer doesn't change files in place. This means input is no longer blocked while clang-include-fixer is running. * Factor out logic in helper functions to keep functions short. * Add comments where appropriate. * Provide an alternative buffer replacement strategy for the case that a single line was inserted (the normal case in the case of clang-include-fixer). This keeps point, markers, and other buffer information intact. * Use let-alist and association lists instead of property lists to shorten the code. * Instead of highlighting only the first occurrence of a symbol, highlight all occurrences and move point to the closest one. * Detect qualified names at point. * Use filepos-to-bufferpos if available. * Formatting. Patch by Philipp Stephani! llvm-svn: 283306
2016-10-05 18:04:13 +08:00
;;; clang-include-fixer-test.el --- unit tests for clang-include-fixer.el -*- lexical-binding: t; -*-
;;; Commentary:
;; Unit tests for clang-include-fixer.el.
;;; Code:
(require 'clang-include-fixer)
Overhaul clang-include-fixer.el General overhaul to fix many coding bugs, simplify the code, and improve readability. * Clarify documentation strings of user options. * Say that clang-include-fixer-executable is a file to have auto completion. * Allow user to select available options for clang-include-fixer-input-format. Turn it into a symbol as it's not a free-form string. * Remove clang-include-fixer-query-mode. This option was apparently used to select between two different operation modes, which is not a typical use case for user options. Provide two separate commands instead. * Add a face for the overlay highlighting so that users can customize it. Move user commands to the front so that readers of the code aren't buried in internal functions. * Make process calls asynchronous. This is possible here because clang-include-fixer doesn't change files in place. This means input is no longer blocked while clang-include-fixer is running. * Factor out logic in helper functions to keep functions short. * Add comments where appropriate. * Provide an alternative buffer replacement strategy for the case that a single line was inserted (the normal case in the case of clang-include-fixer). This keeps point, markers, and other buffer information intact. * Use let-alist and association lists instead of property lists to shorten the code. * Instead of highlighting only the first occurrence of a symbol, highlight all occurrences and move point to the closest one. * Detect qualified names at point. * Use filepos-to-bufferpos if available. * Formatting. Patch by Philipp Stephani! llvm-svn: 283306
2016-10-05 18:04:13 +08:00
(require 'cc-mode)
(require 'ert)
(ert-deftest clang-include-fixer--insert-line ()
"Unit test for `clang-include-fixer--insert-line'."
(with-temp-buffer
(insert "aa\nab\nac\nad\n")
(let ((from (current-buffer)))
(with-temp-buffer
(insert "aa\nac\nad\n")
(let ((to (current-buffer)))
(should (clang-include-fixer--insert-line from to))
(should (equal (buffer-string) "aa\nab\nac\nad\n")))))
(should (equal (buffer-string) "aa\nab\nac\nad\n"))))
(ert-deftest clang-include-fixer--insert-line-diff-on-empty-line ()
"Unit test for `clang-include-fixer--insert-line'."
(with-temp-buffer
(insert "aa\nab\n\nac\nad\n")
(let ((from (current-buffer)))
(with-temp-buffer
(insert "aa\n\nac\nad\n")
(let ((to (current-buffer)))
(should (clang-include-fixer--insert-line from to))
(should (equal (buffer-string) "aa\nab\n\nac\nad\n")))))
(should (equal (buffer-string) "aa\nab\n\nac\nad\n"))))
Overhaul clang-include-fixer.el General overhaul to fix many coding bugs, simplify the code, and improve readability. * Clarify documentation strings of user options. * Say that clang-include-fixer-executable is a file to have auto completion. * Allow user to select available options for clang-include-fixer-input-format. Turn it into a symbol as it's not a free-form string. * Remove clang-include-fixer-query-mode. This option was apparently used to select between two different operation modes, which is not a typical use case for user options. Provide two separate commands instead. * Add a face for the overlay highlighting so that users can customize it. Move user commands to the front so that readers of the code aren't buried in internal functions. * Make process calls asynchronous. This is possible here because clang-include-fixer doesn't change files in place. This means input is no longer blocked while clang-include-fixer is running. * Factor out logic in helper functions to keep functions short. * Add comments where appropriate. * Provide an alternative buffer replacement strategy for the case that a single line was inserted (the normal case in the case of clang-include-fixer). This keeps point, markers, and other buffer information intact. * Use let-alist and association lists instead of property lists to shorten the code. * Instead of highlighting only the first occurrence of a symbol, highlight all occurrences and move point to the closest one. * Detect qualified names at point. * Use filepos-to-bufferpos if available. * Formatting. Patch by Philipp Stephani! llvm-svn: 283306
2016-10-05 18:04:13 +08:00
(ert-deftest clang-include-fixer--symbol-at-point ()
"Unit test for `clang-include-fixer--symbol-at-point'."
(with-temp-buffer
(insert "a+bbb::cc")
(c++-mode)
(goto-char (point-min))
(should (equal (clang-include-fixer--symbol-at-point) "a"))
(forward-char)
;; Emacs treats the character immediately following a symbol as part of the
;; symbol.
(should (equal (clang-include-fixer--symbol-at-point) "a"))
(forward-char)
(should (equal (clang-include-fixer--symbol-at-point) "bbb::cc"))
(goto-char (point-max))
(should (equal (clang-include-fixer--symbol-at-point) "bbb::cc"))))
(ert-deftest clang-include-fixer--highlight ()
(with-temp-buffer
(insert "util::Status foo;\n")
(setq buffer-file-coding-system 'utf-8-unix)
(should (equal nil (clang-include-fixer--highlight
'((Range . ((Offset . 0) (Length . 0)))))))
(let ((overlay (clang-include-fixer--highlight
'((Range . ((Offset . 1) (Length . 12)))))))
(should (equal 2 (overlay-start overlay)))
(should (equal 14 (overlay-end overlay))))))
Overhaul clang-include-fixer.el General overhaul to fix many coding bugs, simplify the code, and improve readability. * Clarify documentation strings of user options. * Say that clang-include-fixer-executable is a file to have auto completion. * Allow user to select available options for clang-include-fixer-input-format. Turn it into a symbol as it's not a free-form string. * Remove clang-include-fixer-query-mode. This option was apparently used to select between two different operation modes, which is not a typical use case for user options. Provide two separate commands instead. * Add a face for the overlay highlighting so that users can customize it. Move user commands to the front so that readers of the code aren't buried in internal functions. * Make process calls asynchronous. This is possible here because clang-include-fixer doesn't change files in place. This means input is no longer blocked while clang-include-fixer is running. * Factor out logic in helper functions to keep functions short. * Add comments where appropriate. * Provide an alternative buffer replacement strategy for the case that a single line was inserted (the normal case in the case of clang-include-fixer). This keeps point, markers, and other buffer information intact. * Use let-alist and association lists instead of property lists to shorten the code. * Instead of highlighting only the first occurrence of a symbol, highlight all occurrences and move point to the closest one. * Detect qualified names at point. * Use filepos-to-bufferpos if available. * Formatting. Patch by Philipp Stephani! llvm-svn: 283306
2016-10-05 18:04:13 +08:00
;;; clang-include-fixer-test.el ends here