This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/core/tests/core-configuration-layer-utest.el

234 lines
10 KiB
EmacsLisp
Raw Normal View History

2015-04-06 01:01:54 +00:00
;;; core-configuration-layer-utest.el --- Spacemacs Unit Test File
2015-01-23 03:39:26 +00:00
;;
;; Copyright (c) 2012-2014 Sylvain Benner
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(require 'mocker)
2015-01-27 03:51:47 +00:00
(require 'core-configuration-layer)
;; ---------------------------------------------------------------------------
;; configuration-layer//declare-used-layers
;; ---------------------------------------------------------------------------
2015-07-26 14:45:34 +00:00
(ert-deftest test-declare-used-layers--result-order-is-not-reversed ()
(mocker-let ((configuration-layer//make-used-layer
(x)
((:input '(layer3) :output 'layer3)
(:input '(layer2) :output 'layer2)
(:input '(layer1) :output 'layer1))))
(let* ((input '(layer1 layer2 layer3))
(result (configuration-layer//declare-used-layers input)))
(should (equal result input)))))
(ert-deftest test-declare-used-layers--ignore-not-found-layer ()
(mocker-let ((configuration-layer//make-used-layer
(x)
((:input '(layer3) :output 'layer3)
(:input '(layer2-not-found) :output nil)
(:input '(layer1) :output 'layer1))))
(let* ((input '(layer1 layer2-not-found layer3))
(expected '(layer1 layer3))
(result (configuration-layer//declare-used-layers input)))
(should (equal result expected)))))
;; ---------------------------------------------------------------------------
;; configuration-layer//make-used-layer
;; ---------------------------------------------------------------------------
(ert-deftest test-make-used-layer--input-is-a-symbol ()
(let ((input 'testlayer)
(expected (cfgl-layer "testlayer"
:name 'testlayer
:dir "/a/dummy/path/testlayer/"
:ext-dir "/a/dummy/path/testlayer/extensions/")))
(mocker-let ((configuration-layer/get-layer-path
(x)
((:input `(,input) :output "/a/dummy/path/"))))
(let ((result (configuration-layer//make-used-layer input)))
(should (equal result expected))))))
(ert-deftest test-make-used-layer--input-is-a-list ()
(let ((input '(testlayer :variables var1 t var2 nil))
(expected (cfgl-layer "testlayer"
:name 'testlayer
:dir "/a/dummy/path/testlayer/"
:ext-dir "/a/dummy/path/testlayer/extensions/"
:variables '(var1 t var2 nil))))
(mocker-let ((configuration-layer/get-layer-path
(x)
((:input `(,(car input)) :output "/a/dummy/path/"))))
(let ((result (configuration-layer//make-used-layer input)))
(should (equal result expected))))))
;; ---------------------------------------------------------------------------
;; configuration-layer//set-layers-variables
;; ---------------------------------------------------------------------------
(ert-deftest test-set-layers-variables--none ()
(let ((input `(,(cfgl-layer "testlayer"
:name 'testlayer
:dir "/a/path/"
:ext-dir "/a/path/extensions/")))
(var 'foo))
(configuration-layer//set-layers-variables input)
(should (eq var 'foo))))
(ert-deftest test-set-layers-variables--one-value ()
(let ((input `(,(cfgl-layer "testlayer"
:name 'testlayer
:dir "/a/path/"
:ext-dir "/a/path/extensions/"
:variables '(var1 'bar)))))
(setq var1 'foo)
(configuration-layer//set-layers-variables input)
(should (eq var1 'bar))))
(ert-deftest test-set-layers-variables--multiple-values ()
(let ((input `(,(cfgl-layer "testlayer"
:name 'testlayer
:dir "/a/path/"
:ext-dir "/a/path/extensions/"
:variables '(var1 'bar1 var2 'bar2 var3 'bar3)))))
(setq var1 'foo)
(setq var2 'foo)
(setq var3 'foo)
(configuration-layer//set-layers-variables input)
(should (eq var1 'bar1))
(should (eq var2 'bar2))
(should (eq var3 'bar3))))
(ert-deftest test-set-layers-variables--odd-number-of-values ()
(let ((input `(,(cfgl-layer "testlayer"
:name 'testlayer
:dir "/a/path/"
:ext-dir "/a/path/extensions/"
:variables '(var1 'bar var2)))))
(mocker-let
2015-04-13 06:20:03 +00:00
((spacemacs-buffer/warning
(msg &rest args)
((:record-cls 'mocker-stub-record :output nil :occur 1))))
(setq var1 'foo)
(setq var2 'foo)
(configuration-layer//set-layers-variables input)
(should (eq var1 'bar))
(should (eq var2 'foo)))))
;; ---------------------------------------------------------------------------
;; configuration-layer//directory-type
;; ---------------------------------------------------------------------------
(ert-deftest test-directory-type--input-is-a-file ()
(let ((input "/a/path/to/a/layer/file"))
(mocker-let
((file-directory-p (f)
((:record-cls 'mocker-stub-record :output nil :occur 1))))
(should (null (configuration-layer//directory-type input))))))
(ert-deftest test-directory-type--category ()
(let ((input (concat configuration-layer-contrib-directory "!vim/")))
(mocker-let
((file-directory-p (f)
((:record-cls 'mocker-stub-record :output t :occur 1))))
(should (eq 'category (configuration-layer//directory-type input))))))
(ert-deftest test-directory-type--input-is-an-empty-directory ()
(let ((input "/a/path/to/a/layer/"))
(mocker-let
((file-directory-p (f)
((:record-cls 'mocker-stub-record :output t :occur 1)))
(directory-files
(directory &optional full match nosort)
((:record-cls 'mocker-stub-record :output nil :occur 1))))
(should (null (configuration-layer//directory-type input))))))
(ert-deftest test-directory-type--input-is-directory-and-not-a-layer ()
(let ((input "/a/path/to/a/layer/"))
(mocker-let
((file-directory-p (f)
((:record-cls 'mocker-stub-record :output t :occur 1)))
(directory-files
(directory &optional full match nosort)
((:record-cls 'mocker-stub-record :output '("toto.el" "tata.el") :occur 1))))
(should (null (configuration-layer//directory-type input))))))
(ert-deftest test-directory-type--layer-with-packages.el ()
(let ((input "/a/path/to/a/layer/"))
(mocker-let
((file-directory-p (f)
((:record-cls 'mocker-stub-record :output t :occur 1)))
(directory-files
(directory &optional full match nosort)
((:record-cls 'mocker-stub-record :output '("packages.el") :occur 1))))
(should (eq 'layer (configuration-layer//directory-type input))))))
(ert-deftest test-directory-type--layer-with-extensions.el ()
(let ((input "/a/path/to/a/layer/"))
(mocker-let
((file-directory-p (f)
((:record-cls 'mocker-stub-record :output t :occur 1)))
(directory-files
(directory &optional full match nosort)
((:record-cls 'mocker-stub-record :output '("extensions.el") :occur 1))))
(should (eq 'layer (configuration-layer//directory-type input))))))
(ert-deftest test-directory-type--layer-with-config.el ()
(let ((input "/a/path/to/a/layer/"))
(mocker-let
((file-directory-p (f)
((:record-cls 'mocker-stub-record :output t :occur 1)))
(directory-files
(directory &optional full match nosort)
((:record-cls 'mocker-stub-record :output '("config.el") :occur 1))))
(should (eq 'layer (configuration-layer//directory-type input))))))
(ert-deftest test-directory-type--layer-with-keybindings.el ()
(let ((input "/a/path/to/a/layer/"))
(mocker-let
((file-directory-p (f)
((:record-cls 'mocker-stub-record :output t :occur 1)))
(directory-files
(directory &optional full match nosort)
((:record-cls 'mocker-stub-record :output '("keybindings.el") :occur 1))))
(should (eq 'layer (configuration-layer//directory-type input))))))
(ert-deftest test-directory-type--layer-with-funcs.el ()
(let ((input "/a/path/to/a/layer/"))
(mocker-let
((file-directory-p (f)
((:record-cls 'mocker-stub-record :output t :occur 1)))
(directory-files
(directory &optional full match nosort)
((:record-cls 'mocker-stub-record :output '("funcs.el") :occur 1))))
(should (eq 'layer (configuration-layer//directory-type input))))))
;; ---------------------------------------------------------------------------
;; configuration-layer//get-category-from-path
;; ---------------------------------------------------------------------------
(ert-deftest test-get-category-from-path--input-is-a-file ()
(let ((input "/a/path/to/a/file"))
(mocker-let
((file-directory-p (f)
((:record-cls 'mocker-stub-record :output nil :occur 1))))
(should (null (configuration-layer//get-category-from-path input))))))
(ert-deftest test-get-category-from-path--input-is-a-regular-directory ()
(let ((input "/a/path/to/a/layer/"))
(mocker-let
((file-directory-p (f)
((:record-cls 'mocker-stub-record :output t :occur 1))))
(should (null (configuration-layer//get-category-from-path input))))))
(ert-deftest test-get-category-from-path--return-category ()
(let ((input "/a/path/to/a/!cat/"))
(mocker-let
((file-directory-p (f)
((:record-cls 'mocker-stub-record :output t :occur 1))))
(should (eq 'cat (configuration-layer//get-category-from-path input))))))