Add unit test suite.

This commit is contained in:
Vincent Zhang 2018-12-08 02:59:08 +08:00
parent fef210416f
commit cd62baebf9
4 changed files with 114 additions and 3 deletions

View file

@ -22,5 +22,5 @@ install:
script: script:
- emacs --version - emacs --version
- pwd - cask exec ert-runner
- cask build - cask build

0
test/.nosearch Normal file
View file

View file

@ -0,0 +1,70 @@
;;; doom-modeline-test.el --- Unit tests for doom-modeline -*- lexical-binding: t; -*-
;; Copyright (C) 2018 Vincent Zhang
;; Author: Vincent Zhang <seagle0128@gmail.com>
;; Homepage: https://github.com/seagle0128/doom-modeline
;; This file is not part of GNU Emacs.
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;
;;; Commentary:
;;
;; Unit tests for doom-modeline.
;;
;;; Code:
(ert-deftest doom-modeline--buffer-file-name/truncate-upto-project ()
(let ((default-directory "/home/user/project/")
(file-path "/home/user/project/relative/test.txt")
(true-file-path nil))
(should
(string= (strip-text-properties
(doom-modeline--buffer-file-name file-path true-file-path 'shrink))
"/h/u/project/relative/test.txt"))))
(ert-deftest doom-modeline--buffer-file-name/truncate-from-project ()
(let ((default-directory "/home/user/project/")
(file-path "/home/user/project/relative/test.txt")
(true-file-path nil))
(should
(string= (strip-text-properties
(doom-modeline--buffer-file-name file-path true-file-path nil 'shrink))
"/home/user/project/r/test.txt"))))
(ert-deftest doom-modeline--buffer-file-name/truncate-with-project ()
(let ((default-directory "/home/user/project/")
(file-path "/home/user/project/relative/test.txt")
(true-file-path nil))
(should
(string= (strip-text-properties
(doom-modeline--buffer-file-name file-path true-file-path 'shrink 'shrink 'hide))
"project/r/test.txt"))))
(ert-deftest doom-modeline--buffer-file-name/truncate-except-project ()
(let ((default-directory "/home/user/project/")
(file-path "/home/user/project/relative/test.txt")
(true-file-path nil))
(should
(string= (strip-text-properties
(doom-modeline--buffer-file-name file-path true-file-path 'shrink 'shrink))
"/h/u/project/r/test.txt"))))
;;; doom-modeline-test.el ends here

41
test/test-helper.el Normal file
View file

@ -0,0 +1,41 @@
;;; test-helper.el --- Helpers for doom-modeline-test.el -*- lexical-binding: t; -*-
;; Copyright (C) 2018 Vincent Zhang
;; Author: Vincent Zhang <seagle0128@gmail.com>
;; Homepage: https://github.com/seagle0128/doom-modeline
;; This file is not part of GNU Emacs.
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;
;;; Commentary:
;;
;; Helpers for doom-modeline-test.el
;;
;;; Code:
(require 'doom-modeline (expand-file-name "doom-modeline.el"))
(require 'ert)
(defun strip-text-properties(txt)
"Strip text properties of TXT."
(set-text-properties 0 (length txt) nil txt)
txt)
;;; test-helper.el ends here