Give '$' punctuation syntax in make-mode (Bug#24477)
[emacs.git] / test / lisp / xdg-tests.el
blobad5e4a48a26f6126c94b384994c88cc56c92208b
1 ;;; xdg-tests.el --- tests for xdg.el -*- lexical-binding: t -*-
3 ;; Copyright (C) 2017-2018 Free Software Foundation, Inc.
5 ;; Maintainer: emacs-devel@gnu.org
6 ;; Author: Mark Oteiza <mvoteiza@udel.edu>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs 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.
15 ;; GNU Emacs 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.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;;; Code:
27 (require 'ert)
28 (require 'xdg)
30 (defconst xdg-tests-data-dir
31 (expand-file-name "test/data/xdg" source-directory))
33 (ert-deftest xdg-desktop-parsing ()
34 "Test `xdg-desktop-read-file' parsing of .desktop files."
35 (let ((tab1 (xdg-desktop-read-file
36 (expand-file-name "test.desktop" xdg-tests-data-dir)))
37 (tab2 (xdg-desktop-read-file
38 (expand-file-name "test.desktop" xdg-tests-data-dir)
39 "Another Section")))
40 (should (equal (gethash "Name" tab1) "Test"))
41 (should (eq 'default (gethash "Exec" tab1 'default)))
42 (should (equal "frobnicate" (gethash "Exec" tab2))))
43 (should-error
44 (xdg-desktop-read-file
45 (expand-file-name "malformed.desktop" xdg-tests-data-dir)))
46 (let ((tab (xdg-desktop-read-file
47 (expand-file-name "l10n.desktop" xdg-tests-data-dir)))
48 (env (getenv "LC_MESSAGES")))
49 (unwind-protect
50 (progn
51 (setenv "LC_MESSAGES" nil)
52 (should (equal (gethash "Comment" tab) "Cheers"))
53 ;; l10n omitted
54 (setenv "LC_MESSAGES" "sv_SE.UTF-8")
55 (should-not (equal (gethash "Comment" tab) "Skål")))
56 (setenv "LC_MESSAGES" env))))
58 (ert-deftest xdg-desktop-strings-type ()
59 "Test desktop \"string(s)\" type: strings delimited by \";\"."
60 (should (equal (xdg-desktop-strings " a") '("a")))
61 (should (equal (xdg-desktop-strings "a;b") '("a" "b")))
62 (should (equal (xdg-desktop-strings "a;b;") '("a" "b")))
63 (should (equal (xdg-desktop-strings "\\;") '(";")))
64 (should (equal (xdg-desktop-strings ";") '("")))
65 (should (equal (xdg-desktop-strings " ") nil))
66 (should (equal (xdg-desktop-strings "a; ;") '("a" " "))))
68 (ert-deftest xdg-mime-associations ()
69 "Test reading MIME associations from files."
70 (let* ((apps (expand-file-name "mimeapps.list" xdg-tests-data-dir))
71 (cache (expand-file-name "mimeinfo.cache" xdg-tests-data-dir))
72 (fs (list apps cache)))
73 (should (equal (xdg-mime-collect-associations "x-test/foo" fs)
74 '("a.desktop" "b.desktop")))
75 (should (equal (xdg-mime-collect-associations "x-test/bar" fs)
76 '("a.desktop" "c.desktop")))
77 (should (equal (xdg-mime-collect-associations "x-test/baz" fs)
78 '("a.desktop" "b.desktop" "d.desktop")))))
80 ;;; xdg-tests.el ends here