]> code.delx.au - gnu-emacs/blob - test/lisp/textmodes/css-mode-tests.el
Merge from origin/emacs-25
[gnu-emacs] / test / lisp / textmodes / css-mode-tests.el
1 ;;; css-mode-tests.el --- Test suite for CSS mode -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2016 Free Software Foundation, Inc.
4
5 ;; Author: Simen Heggestøyl <simenheg@gmail.com>
6 ;; Keywords: internal
7
8 ;; This file is part of GNU Emacs.
9
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
14
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 (require 'css-mode)
28 (require 'ert)
29 (require 'seq)
30
31 (ert-deftest css-test-property-values ()
32 ;; The `float' property has a flat value list.
33 (should
34 (equal (sort (css--property-values "float") #'string-lessp)
35 '("left" "none" "right")))
36
37 ;; The `list-style' property refers to several other properties.
38 (should
39 (equal (sort (css--property-values "list-style") #'string-lessp)
40 (sort (seq-uniq
41 (append (css--property-values "list-style-type")
42 (css--property-values "list-style-position")
43 (css--property-values "list-style-image")))
44 #'string-lessp)))
45
46 ;; The `position' property is tricky because it's also the name of a
47 ;; value class.
48 (should
49 (equal (sort (css--property-values "position") #'string-lessp)
50 '("absolute" "fixed" "relative" "static")))
51
52 ;; The `background-position' property should refer to the `position'
53 ;; value class, not the property of the same name.
54 (should
55 (equal (css--property-values "background-position")
56 (css--value-class-lookup 'position)))
57
58 ;; Check that the `color' property doesn't cause infinite recursion
59 ;; because it refers to the value class of the same name.
60 (should (= (length (css--property-values "color")) 18)))
61
62 (ert-deftest css-test-property-value-cache ()
63 "Test that `css--property-value-cache' is in use."
64 (should-not (gethash "word-wrap" css--property-value-cache))
65 (let ((word-wrap-values (css--property-values "word-wrap")))
66 (should (equal (gethash "word-wrap" css--property-value-cache)
67 word-wrap-values))))
68
69 (ert-deftest css-test-property-values-no-duplicates ()
70 "Test that `css--property-values' returns no duplicates."
71 ;; The `flex' property is prone to duplicate values; if they aren't
72 ;; removed, it'll contain at least two instances of `auto'.
73 (should
74 (equal (sort (css--property-values "flex") #'string-lessp)
75 '("auto" "calc()" "content" "none"))))
76
77 (ert-deftest css-test-value-class-lookup ()
78 (should
79 (equal (sort (css--value-class-lookup 'position) #'string-lessp)
80 '("bottom" "calc()" "center" "left" "right" "top"))))
81
82 (provide 'css-mode-tests)
83 ;;; css-mode-tests.el ends here