File: test-defun-font-lock.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 (111 lines) | stat: -rw-r--r-- 3,217 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
108
109
110
111
(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"))


(ert-deftest lua-font-lock-defuns ()
  (should-lua-font-lock-equal
   ;; Let's start with some basic stuff
   "function foo() end"
   '(("function" keyword "foo" function-name "end" keyword)))

  (should-lua-font-lock-equal
   ;; Check all defun variants, check embedded defuns
   "\
function foo()
  function bar() end
  local function baz() end
  qux = function() end
  local quux = function() end
end"
   '(("function" keyword "foo" function-name)
     ("function" keyword "bar" function-name "end" keyword)
     ("local" keyword "function" keyword "baz" function-name "end" keyword)
     ("qux" function-name "function" keyword "end" keyword)
     ("local" keyword "quux" function-name "function" keyword "end" keyword)
     ("end" keyword))))

(ert-deftest lua-font-lock-defuns-inside-table ()
  ;; Check defuns within table definition
  (should-lua-font-lock-equal
   "\
somefunc {
  function() end,
  foobar = function() end,
  [\"quxquux\"] = function() end
}"
   '(nil
     ("function" keyword "end" keyword)
     ("foobar" function-name "function" keyword "end" keyword)
     ("\"quxquux\"" string "function" keyword "end" keyword)
     nil)))

(ert-deftest lua-gh-issue59 ()
  (should-lua-font-lock-equal
   "\
local foo = function()
   ;
end
-- and
local function foo()
   ;
end"
   '(("local" keyword "foo" function-name "function" keyword)
     nil
     ("end" keyword)
     ("-- " comment-delimiter "and" comment)
     ("local" keyword "function" keyword "foo" function-name)
     nil
     ("end" keyword))))

(ert-deftest lua-funcnames-with-underscore ()
  (should-lua-font-lock-equal
   ;; Check all defun variants, check embedded defuns
   "\
function foo()
  function bar_bar() end
  local function baz_baz() end
  qux_qux = function() end
  local quux_quux = function() end
end"
   '(("function" keyword "foo" function-name)
     ("function" keyword "bar_bar" function-name "end" keyword)
     ("local" keyword "function" keyword "baz_baz" function-name "end" keyword)
     ("qux_qux" function-name "function" keyword "end" keyword)
     ("local" keyword "quux_quux" function-name "function" keyword "end" keyword)
     ("end" keyword)))  )

(ert-deftest lua-font-lock-labels ()
  (should-lua-font-lock-equal
    "\
goto foo
::foo::"
   '(("goto" keyword "foo" constant)
     ("::foo::" constant)))

  (should-lua-font-lock-equal
    "\
local foo = 'test' ::f12o::
goto f12o"
   '(("local" keyword "foo" variable-name "'test'" string "::f12o::" constant)
     ("goto" keyword "f12o" constant)))

  ;; With spaces after and before "::"
  (should-lua-font-lock-equal
    "\
goto foo
:: foo ::"
   '(("goto" keyword "foo" constant)
     (":: foo ::" constant)))

  ;; Don't font lock labels when substring "goto" appears as a suffix
  ;; of another variable
  (should-lua-font-lock-equal
    "\
JUNKgoto foo
:: foo ::"
   '(nil ;; don't font lock "foo"
     (":: foo ::" constant))))