diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/data/xdg/test.desktop | 3 | ||||
| -rw-r--r-- | test/data/xdg/wrong.desktop | 2 | ||||
| -rw-r--r-- | test/lisp/xdg-tests.el | 71 |
3 files changed, 76 insertions, 0 deletions
diff --git a/test/data/xdg/test.desktop b/test/data/xdg/test.desktop new file mode 100644 index 00000000000..b6dda62774a --- /dev/null +++ b/test/data/xdg/test.desktop | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | # this is a comment | ||
| 2 | [Desktop Entry] | ||
| 3 | Name=Test | ||
diff --git a/test/data/xdg/wrong.desktop b/test/data/xdg/wrong.desktop new file mode 100644 index 00000000000..e0b4c221cf9 --- /dev/null +++ b/test/data/xdg/wrong.desktop | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | # the first section must be "Desktop Entry" | ||
| 2 | [Why] | ||
diff --git a/test/lisp/xdg-tests.el b/test/lisp/xdg-tests.el new file mode 100644 index 00000000000..e7e122b54ee --- /dev/null +++ b/test/lisp/xdg-tests.el | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | ;;; xdg-tests.el --- tests for xdg.el -*- lexical-binding: t -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2017 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Maintainer: emacs-devel@gnu.org | ||
| 6 | |||
| 7 | ;; Author: Mark Oteiza <mvoteiza@udel.edu> | ||
| 8 | |||
| 9 | ;; This file is part of GNU Emacs. | ||
| 10 | |||
| 11 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 12 | ;; it under the terms of the GNU General Public License as published by | ||
| 13 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 14 | ;; (at your option) any later version. | ||
| 15 | |||
| 16 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 19 | ;; GNU General Public License for more details. | ||
| 20 | |||
| 21 | ;; You should have received a copy of the GNU General Public License | ||
| 22 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | ||
| 23 | |||
| 24 | ;;; Commentary: | ||
| 25 | |||
| 26 | ;;; Code: | ||
| 27 | |||
| 28 | (require 'ert) | ||
| 29 | (require 'xdg) | ||
| 30 | |||
| 31 | (defconst xdg-tests-data-dir | ||
| 32 | (expand-file-name "test/data/xdg" source-directory)) | ||
| 33 | |||
| 34 | (ert-deftest xdg-match-data () | ||
| 35 | "Ensure public functions do not mangle match data." | ||
| 36 | (let ((data '(1 9))) | ||
| 37 | (save-match-data | ||
| 38 | (set-match-data data) | ||
| 39 | (xdg-user-dir "DOCUMENTS") | ||
| 40 | (should (equal (match-data) data)))) | ||
| 41 | (let ((data '(2 9))) | ||
| 42 | (save-match-data | ||
| 43 | (set-match-data data) | ||
| 44 | (xdg-desktop-read-file (expand-file-name "test.desktop" xdg-tests-data-dir)) | ||
| 45 | (should (equal (match-data) data)))) | ||
| 46 | (let ((data '(3 9))) | ||
| 47 | (save-match-data | ||
| 48 | (set-match-data data) | ||
| 49 | (xdg-desktop-strings "a;b") | ||
| 50 | (should (equal (match-data) data))))) | ||
| 51 | |||
| 52 | (ert-deftest xdg-desktop-parsing () | ||
| 53 | "Test `xdg-desktop-read-file' parsing of .desktop files." | ||
| 54 | (let ((tab (xdg-desktop-read-file | ||
| 55 | (expand-file-name "test.desktop" xdg-tests-data-dir)))) | ||
| 56 | (should (equal (gethash "Name" tab) "Test"))) | ||
| 57 | (should-error | ||
| 58 | (xdg-desktop-read-file | ||
| 59 | (expand-file-name "wrong.desktop" xdg-tests-data-dir)))) | ||
| 60 | |||
| 61 | (ert-deftest xdg-desktop-strings-type () | ||
| 62 | "Test desktop \"string(s)\" type: strings delimited by \";\"." | ||
| 63 | (should (equal (xdg-desktop-strings " a") '("a"))) | ||
| 64 | (should (equal (xdg-desktop-strings "a;b") '("a" "b"))) | ||
| 65 | (should (equal (xdg-desktop-strings "a;b;") '("a" "b"))) | ||
| 66 | (should (equal (xdg-desktop-strings "\\;") '(";"))) | ||
| 67 | (should (equal (xdg-desktop-strings ";") '(""))) | ||
| 68 | (should (equal (xdg-desktop-strings " ") nil)) | ||
| 69 | (should (equal (xdg-desktop-strings "a; ;") '("a" " ")))) | ||
| 70 | |||
| 71 | ;;; xdg-tests.el ends here | ||