From 380bea265ebd0f3dec4f6e857a7442fb61f856c6 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 11 Dec 2018 01:05:16 +0800 Subject: [PATCH] Add unit test cases. --- test/doom-modeline-test.el | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/doom-modeline-test.el b/test/doom-modeline-test.el index 7cdd5b1..057d0bb 100644 --- a/test/doom-modeline-test.el +++ b/test/doom-modeline-test.el @@ -67,4 +67,42 @@ (doom-modeline--buffer-file-name file-path true-file-path 'shrink 'shrink)) "/h/u/project/r/test.txt")))) +(ert-deftest doom-modeline--buffer-file-name-truncate/truncate-upto-root () + (let ((default-directory "/home/user/project/") + (file-path "/home/user/project/relative/test.txt") + (true-file-path "~/project/relative/test.txt")) + (should + (string= (strip-text-properties + (doom-modeline--buffer-file-name-truncate file-path true-file-path)) + "~/p/relative/test.txt")))) + +(ert-deftest doom-modeline--buffer-file-name-truncate/truncate-all () + (let ((default-directory "/home/user/project/") + (file-path "/home/user/project/relative/test.txt") + (true-file-path "~/project/relative/test.txt")) + (should + (string= (strip-text-properties + (doom-modeline--buffer-file-name-truncate file-path true-file-path t)) + "~/p/r/test.txt")))) + +(ert-deftest doom-modeline--buffer-file-name-relative/relative-to-project () + (let ((default-directory "/home/user/project/") + (file-path nil) + (true-file-path "/home/user/project/relative/test.txt")) + (cl-flet ((doom-modeline-project-root () "/home/user/project/")) + (should + (string= (strip-text-properties + (doom-modeline--buffer-file-name-relative file-path true-file-path)) + "relative/test.txt"))))) + +(ert-deftest doom-modeline--buffer-file-name-relative/relative-from-project () + (let ((default-directory "/home/user/project/") + (file-path nil) + (true-file-path "/home/user/project/relative/test.txt")) + (cl-flet ((doom-modeline-project-root () "/home/user/project/")) + (should + (string= (strip-text-properties + (doom-modeline--buffer-file-name-relative file-path true-file-path 'include-project)) + "project/relative/test.txt"))))) + ;;; doom-modeline-test.el ends here