File: test-builtin-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 (74 lines) | stat: -rw-r--r-- 2,130 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
(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-builtins ()
  (should-lua-font-lock-equal
   "\
table.sort(foobar)
   table.sort(foobar)
   table  .sort(foobar)
   table.  sort(foobar)"
   '(("table" builtin "sort" builtin)
     ("table" builtin "sort" builtin)
     ("table" builtin "sort" builtin)
     ("table" builtin "sort" builtin)))

  (should-lua-font-lock-equal
   ;; Neither of these should be highlighted, thing that looks like a builtin
   ;; is in fact a member of some user table.
   "\
foo.table.sort(foobar)
foo.  table.sort(foobar)
foo  .table.sort(foobar)
foo:table.sort(foobar)
foo:  table.sort(foobar)
foo  :table.sort(foobar)

_table.sort(foobar)
   table_.sort(foobar)"
   '(nil nil nil nil nil nil nil nil nil))

  (should-lua-font-lock-equal
   "\
   table  ._sort(foobar)
   table.  sort_(foobar)"
   '(("table" builtin) ("table" builtin)))

  (should-lua-font-lock-equal
   ;; After concatenation operator builtins should be highlighted too.
   "a .. table.concat(foobar, delim)"
   '(("table" builtin "concat" builtin))))


(ert-deftest lua-font-lock-builtin-constants()
  (should-lua-font-lock-equal
   "a = { nil, true, false}"
   '(("nil" constant "true" constant "false" constant)))

  ;; Hint user that builtin constants cannot be used like that
  (should-lua-font-lock-equal
   "a = { foo.true, foo:false }"
   '(("true" constant "false" constant))))


(ert-deftest lua-font-lock-keywords ()
  (should-lua-font-lock-equal
   "do foo(5) end"
   '(("do" keyword "end" keyword)))

  (should-lua-font-lock-equal
   "_do foo(5) end_"
   '(nil))

  ;; Hint user that keywords cannot be used like that
  (should-lua-font-lock-equal
   "do foo(5).end end"
   '(("do" keyword "end" keyword "end" keyword)))
  (should-lua-font-lock-equal
   "do foo(5):end end"
   '(("do" keyword "end" keyword "end" keyword))))