File: test-strings-and-comments.el

package info (click to toggle)
lua-mode 20140514-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 400 kB
  • ctags: 387
  • sloc: lisp: 4,046; makefile: 37; sh: 26
file content (87 lines) | stat: -rw-r--r-- 2,785 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
(require 'ert)
(require 'lua-font-lock-test-helpers
         ;; let's try a bit to help Emacs find the helpers, just in case
         (concat (file-name-directory (or load-file-name (buffer-file-name)
                                          default-directory))
                 "lua-font-lock-test-helpers.el"))

(defmacro should= (lhs rhs)
  `(should (equal ,lhs ,rhs)))

(ert-deftest lua-M-j-works-for-simple-comment ()
  (should= (lua-buffer-strs
            (lua-insert-goto-<> '("-- foobar <>"))
            (execute-kbd-macro (kbd "M-j")))
           '("-- foobar"
             "-- "))

  (should= (lua-buffer-strs
            (lua-insert-goto-<> '("xyzzy -- foobar <>"))
            (execute-kbd-macro (kbd "M-j")))
           '("xyzzy -- foobar"
             "-- "))

  (should= (lua-buffer-strs
            (lua-insert-goto-<> '("xyz<> xyzzy -- foobar"))
            (execute-kbd-macro (kbd "M-j")))
           '("xyz"
             "xyzzy -- foobar")))


(ert-deftest lua-M-j-works-for-longer-comment ()
  (should= (lua-buffer-strs
            (lua-insert-goto-<> '("---- foobar <>"))
            (execute-kbd-macro (kbd "M-j")))
           '("---- foobar"
             "---- "))

  (should= (lua-buffer-strs
            (lua-insert-goto-<> '("xyzzy ---- foobar <>"))
            (execute-kbd-macro (kbd "M-j")))
           '("xyzzy ---- foobar"
             "---- ")))

(ert-deftest lua-M-j-handles-string-and-multiline-comments ()
  (should= (lua-buffer-strs
            (lua-insert-goto-<> '("\"-- \" .. foobar <>"))
            (execute-kbd-macro (kbd "M-j")))
           '("\"-- \" .. foobar"
             ""))

  (should= (lua-buffer-strs
            (lua-insert-goto-<> '("'-- ' .. foobar <>"))
            (execute-kbd-macro (kbd "M-j")))
           '("'-- ' .. foobar"
             ""))

  (should= (lua-buffer-strs
            (lua-insert-goto-<> '("[[-- ]] .. foobar <>"))
            (execute-kbd-macro (kbd "M-j")))
           '("[[-- ]] .. foobar"
             ""))

  (should= (lua-buffer-strs
            (lua-insert-goto-<> '("--[[-- ]] .. foobar <>"))
            (execute-kbd-macro (kbd "M-j")))
           '("--[[-- ]] .. foobar"
             ""))

  (should= (lua-buffer-strs
            (lua-insert-goto-<> '("---[[-- ]] .. foobar <>"))
            (execute-kbd-macro (kbd "M-j")))
           '("---[[-- ]] .. foobar"
             "---")))

(ert-deftest lua-M-j-works-if-comment-is-empty ()
  (should= (lua-buffer-strs
            (lua-insert-goto-<> '("-- <>"))
            (execute-kbd-macro (kbd "M-j")))
           '("--"
             "--"))

  ;; Let's make sure that whitespace is optional.
  (should= (lua-buffer-strs
            (lua-insert-goto-<> '("--<>"))
            (execute-kbd-macro (kbd "M-j")))
           '("--"
             "--")))