[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode 56691b8 338/468: Add tests for preserving point l
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode 56691b8 338/468: Add tests for preserving point location when filling |
Date: |
Thu, 5 Aug 2021 04:59:05 -0400 (EDT) |
branch: elpa/lua-mode
commit 56691b8ffd790715dc82fbf21329483f105bc264
Author: immerrr <immerrr+lua@gmail.com>
Commit: immerrr <immerrr+lua@gmail.com>
Add tests for preserving point location when filling
---
test/test-fill.el | 101 +++++++++++++++++++++++++++++++++++++++++++++---------
test/utils.el | 15 ++++++++
2 files changed, 99 insertions(+), 17 deletions(-)
diff --git a/test/test-fill.el b/test/test-fill.el
index 8b93d10..75089f8 100644
--- a/test/test-fill.el
+++ b/test/test-fill.el
@@ -4,32 +4,35 @@
"utils.el") nil 'nomessage 'nosuffix)
-
-(defun expect-filled-as (strs etalon)
- (expect
- (lua-buffer-strs
- (let ((fill-column 10))
- (lua-insert-goto-<>
- strs)
- (execute-kbd-macro (kbd "M-q"))))
- :to-equal
- etalon))
+(defun expect-filled-as (strs etalon &optional look-at)
+ (let ((result-str (lua-buffer-strs
+ (let ((fill-column 10))
+ (lua-insert-goto-<> strs)
+ (execute-kbd-macro (kbd "M-q"))
+ (when look-at
+ (expect (point) :to-precede look-at))))))
+ (expect result-str :to-equal etalon)))
(describe "Test fill-paragraph"
- (it "filling single-line comment"
+ (it "fills single-line comment"
(expect-filled-as '("<>-- foo bar baz qux")
'("-- foo bar"
- "-- baz qux")))
- (it "filling comment after code"
+ "-- baz qux")
+ "-- foo bar"))
+ (it "fills comment after code"
(expect-filled-as '("<>foo -- bar baz")
'("foo -- bar"
" -- baz")))
- (xit "filling multiline comment"
- (expect-filled-as '("<>--[[ foo bar baz ]]")
- '("--[[ foo bar"
- " baz ]]")))
+ (xit "fills multiline comment"
+ ;; Right now it ends up with something like this:
+ ;;
+ ;; --[[ ab c
+ ;; --d ]]
+ (expect-filled-as '("<>--[[ ab c d ]]")
+ '("--[[ ab c"
+ " d ]]")))
(it "does not spill comments into code (issue #25)"
(expect-filled-as '("<>"
"-- foo bar baz qux"
@@ -38,3 +41,67 @@
"-- foo bar"
"-- baz qux"
"foo_func()"))))
+
+
+(describe "Test fill-paragraph preserves point position"
+ (it "doesn't move point if nothing has changed"
+ (expect-filled-as '("<>-- foo bar")
+ '("-- foo bar")
+ "-- foo bar")
+
+ (expect-filled-as '("-- <>foo bar")
+ '("-- foo bar")
+ "foo bar")
+
+ (expect-filled-as '("-- foo <>bar")
+ '("-- foo bar")
+ "bar"))
+
+ (it "doesn't move point in refilled region"
+ (expect-filled-as '("--<> foo bar baz qux")
+ '("-- foo bar"
+ "-- baz qux")
+ " foo bar\n")
+
+ (expect-filled-as '("-- <>foo bar baz qux")
+ '("-- foo bar"
+ "-- baz qux")
+ "foo bar\n")
+
+ (expect-filled-as '("-- <> foo bar baz qux")
+ '("-- foo"
+ "-- bar"
+ "-- baz"
+ "-- qux")
+ " foo\n")
+
+ (expect-filled-as '("-- foo bar <>baz qux")
+ '("-- foo bar"
+ "-- baz qux")
+ "baz qux")
+ (expect-filled-as '("-- foo bar<> baz qux")
+ '("-- foo bar"
+ "-- baz qux")
+ "\n-- baz qux")
+
+ (expect-filled-as '("-- foo bar baz qux<>")
+ '("-- foo bar"
+ "-- baz qux")
+ "$")
+ )
+
+ (it "doesn't move point if nothing has changed (multi-line)"
+ (expect-filled-as '("--[[ a <>b]]")
+ '("--[[ a b]]")
+ "b]]")
+
+ (expect-filled-as '("--[[ a<>"
+ " b"
+ "]]")
+ '("--[[ a"
+ " b"
+ "]]")
+ "\n b\n]]")
+
+ )
+ )
diff --git a/test/utils.el b/test/utils.el
index 65256f2..c2f4c8e 100644
--- a/test/utils.el
+++ b/test/utils.el
@@ -32,6 +32,21 @@ Fontification check failed on line %d for:
(to-be-fontified-as text faces))
+(buttercup-define-matcher :to-precede (pos regexp)
+ (save-excursion
+ (goto-char pos)
+ (let* ((precedes (looking-at regexp))
+ (substr-begin (min (point-max) pos))
+ (substr-end (min (point-max) (+ pos 100)))
+ (found-after (format "%S" (buffer-substring-no-properties
+ substr-begin substr-end ))))
+ (goto-char substr-end)
+ (when (eobp) (setq found-after (concat found-after " (end-of-buffer)")))
+ (cons precedes (format "Expected %s to see after point at %s: %S.
Found: %s"
+ (if precedes "NOT" "")
+ pos regexp found-after)))))
+
+
(defun get-str-faces (str)
"Find contiguous spans of non-default faces in STR.
- [nongnu] elpa/lua-mode 3e8d475 275/468: Fixed broken local variable assignments, (continued)
- [nongnu] elpa/lua-mode 3e8d475 275/468: Fixed broken local variable assignments, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 1d804f6 279/468: Drop pre-Emacs23 support macros, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d6f7e0b 287/468: lua-documentation-function: New custom variable., Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode f2e5c4b 299/468: Merge pull request #90 from Schnouki/lua53, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 625ed2f 281/468: Move credits to AUTHORS, cleanup Commentary section a bit, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 0b41d44 319/468: Merge master into stable, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode ea7e35c 321/468: Escape tabs in lua-make-lua-string, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 33097fe 329/468: Merge pull request #123 from zonuexe/fix/auto-mode-alist, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode e6faecc 328/468: Use \\' instead of $, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 5640afe 332/468: Merge pull request #128 from immerrr/update-makefile-and-travis-yml, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 56691b8 338/468: Add tests for preserving point location when filling,
Philip Kaludercic <=
- [nongnu] elpa/lua-mode 6daec31 342/468: utils: update to new buttercup matcher definition logic (#138), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a80d912 350/468: Fix a minor bug in lua-kill-process, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 5a90655 355/468: correct spelling mistake, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode aca4014 356/468: utils: update to new buttercup matcher definition logic (#138), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode e8281dc 362/468: Fix a minor bug in lua-kill-process, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 1f04654 379/468: travis: enable testing on osx, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode eb93be5 380/468: Merge pull request #158 from immerrr/enable-testing-on-osx, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 4cdee31 388/468: Use proper lexical-bindings instead of lexical-let*, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 5dfc5be 399/468: Merge pull request #168 from immerrr/index-requires-as-imenu-items, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a3a71b1 400/468: Merge pull request #151 from edam/indent-nested-blocks, Philip Kaludercic, 2021/08/05