From cd62baebf9e97a14c8391b230b3c3f555f0e53f1 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Sat, 8 Dec 2018 02:59:08 +0800 Subject: [PATCH] Add unit test suite. --- .travis.yml | 6 ++-- test/.nosearch | 0 test/doom-modeline-test.el | 70 ++++++++++++++++++++++++++++++++++++++ test/test-helper.el | 41 ++++++++++++++++++++++ 4 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 test/.nosearch create mode 100644 test/doom-modeline-test.el create mode 100644 test/test-helper.el diff --git a/.travis.yml b/.travis.yml index f96799e..52f2d3b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,8 +19,8 @@ before_install: install: - cask install - + script: - emacs --version - - pwd - - cask build + - cask exec ert-runner + - cask build diff --git a/test/.nosearch b/test/.nosearch new file mode 100644 index 0000000..e69de29 diff --git a/test/doom-modeline-test.el b/test/doom-modeline-test.el new file mode 100644 index 0000000..7cdd5b1 --- /dev/null +++ b/test/doom-modeline-test.el @@ -0,0 +1,70 @@ +;;; doom-modeline-test.el --- Unit tests for doom-modeline -*- lexical-binding: t; -*- + +;; Copyright (C) 2018 Vincent Zhang + +;; Author: Vincent Zhang +;; 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 diff --git a/test/test-helper.el b/test/test-helper.el new file mode 100644 index 0000000..9ec9dae --- /dev/null +++ b/test/test-helper.el @@ -0,0 +1,41 @@ +;;; test-helper.el --- Helpers for doom-modeline-test.el -*- lexical-binding: t; -*- + +;; Copyright (C) 2018 Vincent Zhang + +;; Author: Vincent Zhang +;; 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