File: test-fill.el

package info (click to toggle)
lua-mode 20250310~git.2f6b8d7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 428 kB
  • sloc: lisp: 3,186; makefile: 40; sh: 21
file content (107 lines) | stat: -rw-r--r-- 3,524 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
;; -*- flycheck-disabled-checkers: (emacs-lisp-checkdoc) ; lexical-binding:t -*-
(load (concat (file-name-directory (or load-file-name (buffer-file-name)
                                       default-directory))
              "utils.el") nil 'nomessage 'nosuffix)


(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"
  (xit "fills single-line comment"
    (expect-filled-as '("<>-- foo bar baz qux")
                      '("-- foo bar"
                        "-- baz qux")
                      "-- foo bar"))
  (xit "fills comment after code"
    (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 ]]")))
  (xit "does not spill comments into code (issue #25)"
    (expect-filled-as '("<>"
                        "-- foo bar baz qux"
                        "foo_func()")
                      '(""
                        "-- 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]]")

    )
  )