2015-04-06 01:01:54 +00:00
|
|
|
;;; core-funcs-utest.el --- Spacemacs Unit Test File
|
2015-01-27 03:39:14 +00:00
|
|
|
;;
|
2021-03-22 20:11:29 +00:00
|
|
|
;; Copyright (c) 2012-2021 Sylvain Benner & Contributors
|
2015-01-27 03:39:14 +00:00
|
|
|
;;
|
|
|
|
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
2021-04-09 20:52:24 +00:00
|
|
|
;; 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 3 of the License, 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. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2015-01-27 03:39:14 +00:00
|
|
|
(require 'mocker)
|
2015-01-27 03:51:47 +00:00
|
|
|
(require 'core-funcs)
|
2015-01-27 03:39:14 +00:00
|
|
|
|
|
|
|
;; ---------------------------------------------------------------------------
|
2018-06-07 10:13:06 +00:00
|
|
|
;; spacemacs/mplist-get-values
|
2015-01-27 03:39:14 +00:00
|
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
|
2018-06-07 10:13:06 +00:00
|
|
|
(ert-deftest test-mplist-get-values--one-property ()
|
2015-01-27 03:39:14 +00:00
|
|
|
(let* ((input '(dummy :property sym1 sym2 sym3))
|
2018-06-07 10:13:06 +00:00
|
|
|
(result (spacemacs/mplist-get-values input :property)))
|
2015-01-27 03:39:14 +00:00
|
|
|
(should (equal '(sym1 sym2 sym3) result))))
|
|
|
|
|
2018-06-07 10:13:06 +00:00
|
|
|
(ert-deftest test-mplist-get-values--multiple-properties-get-first ()
|
2015-01-27 03:39:14 +00:00
|
|
|
(let* ((input '(dummy :prop1 sym1 sym2 sym3 :prop2 sym4 :prop3 sym5 sym6))
|
2018-06-07 10:13:06 +00:00
|
|
|
(result (spacemacs/mplist-get-values input :prop1)))
|
2015-01-27 03:39:14 +00:00
|
|
|
(should (equal '(sym1 sym2 sym3) result))))
|
|
|
|
|
2018-06-07 10:13:06 +00:00
|
|
|
(ert-deftest test-mplist-get-values--multiple-properties-get-middle ()
|
2015-01-27 03:39:14 +00:00
|
|
|
(let* ((input '(dummy :prop1 sym1 sym2 sym3 :prop2 sym4 :prop3 sym5 sym6))
|
2018-06-07 10:13:06 +00:00
|
|
|
(result (spacemacs/mplist-get-values input :prop2)))
|
2015-01-27 03:39:14 +00:00
|
|
|
(should (equal '(sym4) result))))
|
|
|
|
|
2018-06-07 10:13:06 +00:00
|
|
|
(ert-deftest test-mplist-get-values--multiple-properties-get-last ()
|
2015-01-27 03:39:14 +00:00
|
|
|
(let* ((input '(dummy :prop1 sym1 sym2 sym3 :prop2 sym4 :prop3 sym5 sym6))
|
2018-06-07 10:13:06 +00:00
|
|
|
(result (spacemacs/mplist-get-values input :prop3)))
|
2015-01-27 03:39:14 +00:00
|
|
|
(should (equal '(sym5 sym6) result))))
|
|
|
|
|
2018-06-07 10:13:06 +00:00
|
|
|
(ert-deftest test-mplist-get-values--one-property-no-value ()
|
2015-01-27 03:39:14 +00:00
|
|
|
(let* ((input '(dummy :property))
|
2018-06-07 10:13:06 +00:00
|
|
|
(result (spacemacs/mplist-get-values input :property)))
|
2015-01-27 03:39:14 +00:00
|
|
|
(should (null result))))
|
|
|
|
|
2018-06-07 10:13:06 +00:00
|
|
|
(ert-deftest test-mplist-get-values--multiple-same-poperty-ignore-all-but-first ()
|
2015-01-27 03:39:14 +00:00
|
|
|
(let* ((input '(dummy :property val1 :property val2))
|
2018-06-07 10:13:06 +00:00
|
|
|
(result (spacemacs/mplist-get-values input :property)))
|
2015-01-27 03:39:14 +00:00
|
|
|
(should (equal '(val1) result))))
|
|
|
|
|
2018-06-04 05:19:44 +00:00
|
|
|
;; ---------------------------------------------------------------------------
|
2018-06-07 10:13:06 +00:00
|
|
|
;; spacemacs/mplist-get-value
|
2018-06-04 05:19:44 +00:00
|
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
|
2018-06-07 10:13:06 +00:00
|
|
|
(ert-deftest test-mplist-get-value--one-property ()
|
2018-06-04 05:19:44 +00:00
|
|
|
(let* ((input '(dummy :property sym1))
|
2018-06-07 10:13:06 +00:00
|
|
|
(result (spacemacs/mplist-get-value input :property)))
|
2018-06-04 05:19:44 +00:00
|
|
|
(should (equal 'sym1 result))))
|
|
|
|
|
2018-06-07 10:13:06 +00:00
|
|
|
(ert-deftest test-mplist-get-value--one-property-multiple-values-returns-first ()
|
2018-06-04 05:19:44 +00:00
|
|
|
(let* ((input '(dummy :property sym1 sym2 sym3))
|
2018-06-07 10:13:06 +00:00
|
|
|
(result (spacemacs/mplist-get-value input :property)))
|
2018-06-04 05:19:44 +00:00
|
|
|
(should (equal 'sym1 result))))
|
|
|
|
|
2018-06-07 10:13:06 +00:00
|
|
|
(ert-deftest test-mplist-get-value--multiple-properties-get-first ()
|
2018-06-04 05:19:44 +00:00
|
|
|
(let* ((input '(dummy :prop1 sym1 :prop2 sym4 :prop3 sym5))
|
2018-06-07 10:13:06 +00:00
|
|
|
(result (spacemacs/mplist-get-value input :prop1)))
|
2018-06-04 05:19:44 +00:00
|
|
|
(should (equal 'sym1 result))))
|
|
|
|
|
2018-06-07 10:13:06 +00:00
|
|
|
(ert-deftest test-mplist-get-value--multiple-properties-get-middle ()
|
2018-06-04 05:19:44 +00:00
|
|
|
(let* ((input '(dummy :prop1 sym1 :prop2 sym4 :prop3 sym5))
|
2018-06-07 10:13:06 +00:00
|
|
|
(result (spacemacs/mplist-get-value input :prop2)))
|
2018-06-04 05:19:44 +00:00
|
|
|
(should (equal 'sym4 result))))
|
|
|
|
|
2018-06-07 10:13:06 +00:00
|
|
|
(ert-deftest test-mplist-get-value--multiple-properties-get-last ()
|
2018-06-04 05:19:44 +00:00
|
|
|
(let* ((input '(dummy :prop1 sym1 :prop2 sym4 :prop3 sym5))
|
2018-06-07 10:13:06 +00:00
|
|
|
(result (spacemacs/mplist-get-value input :prop3)))
|
2018-06-04 05:19:44 +00:00
|
|
|
(should (equal 'sym5 result))))
|
|
|
|
|
2018-06-07 10:13:06 +00:00
|
|
|
(ert-deftest test-mplist-get-value--one-property-no-value ()
|
2018-06-04 05:19:44 +00:00
|
|
|
(let* ((input '(dummy :property))
|
2018-06-07 10:13:06 +00:00
|
|
|
(result (spacemacs/mplist-get-value input :property)))
|
2018-06-04 05:19:44 +00:00
|
|
|
(should (null result))))
|
|
|
|
|
2018-06-07 10:13:06 +00:00
|
|
|
(ert-deftest test-mplist-get-value--one-property-no-value-next-is-another-property ()
|
2018-06-04 05:19:44 +00:00
|
|
|
(let* ((input '(dummy :property :property2 sym2))
|
2018-06-07 10:13:06 +00:00
|
|
|
(result (spacemacs/mplist-get-value input :property)))
|
2018-06-04 05:19:44 +00:00
|
|
|
(should (null result))))
|
|
|
|
|
2018-06-07 10:13:06 +00:00
|
|
|
(ert-deftest test-mplist-get-value--multiple-same-poperty-ignore-all-but-first ()
|
2018-06-04 05:19:44 +00:00
|
|
|
(let* ((input '(dummy :property val1 :property val2))
|
2018-06-07 10:13:06 +00:00
|
|
|
(result (spacemacs/mplist-get-value input :property)))
|
2018-06-04 05:19:44 +00:00
|
|
|
(should (equal 'val1 result))))
|
|
|
|
|
2015-01-27 03:39:14 +00:00
|
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
;; spacemacs/mplist-remove
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(ert-deftest test-mplist-remove--one-property ()
|
|
|
|
(let* ((input '(dummy :property sym1 sym2 sym3))
|
|
|
|
(result (spacemacs/mplist-remove input :property)))
|
|
|
|
(should (equal '(dummy) result))))
|
|
|
|
|
|
|
|
(ert-deftest test-mplist-remove--one-property-no-value ()
|
|
|
|
(let* ((input '(dummy :property))
|
|
|
|
(result (spacemacs/mplist-remove input :property)))
|
|
|
|
(should (equal '(dummy) result))))
|
|
|
|
|
|
|
|
(ert-deftest test-mplist-remove--multiple-properties-remove-first ()
|
|
|
|
(let* ((input '(dummy :prop1 sym1 sym2 sym3 :prop2 sym4 sym5 :prop3 sym6))
|
|
|
|
(result (spacemacs/mplist-remove input :prop1)))
|
|
|
|
(should (equal '(dummy :prop2 sym4 sym5 :prop3 sym6) result))))
|
|
|
|
|
|
|
|
(ert-deftest test-mplist-remove--multiple-properties-remove-middle ()
|
|
|
|
(let* ((input '(dummy :prop1 sym1 sym2 sym3 :prop2 sym4 sym5 :prop3 sym6))
|
|
|
|
(result (spacemacs/mplist-remove input :prop2)))
|
|
|
|
(should (equal '(dummy :prop1 sym1 sym2 sym3 :prop3 sym6) result))))
|
|
|
|
|
|
|
|
(ert-deftest test-mplist-remove--multiple-properties-remove-last ()
|
|
|
|
(let* ((input '(dummy :prop1 sym1 sym2 sym3 :prop2 sym4 sym5 :prop3 sym6))
|
|
|
|
(result (spacemacs/mplist-remove input :prop3)))
|
|
|
|
(should (equal '(dummy :prop1 sym1 sym2 sym3 :prop2 sym4 sym5) result))))
|
|
|
|
|
|
|
|
(ert-deftest test-mplist-remove--multiple-same-property-remove-only-first ()
|
|
|
|
(let* ((input '(dummy :prop1 sym1 sym2 sym3 :prop2 sym4 sym5 :prop1 sym6))
|
|
|
|
(result (spacemacs/mplist-remove input :prop1)))
|
|
|
|
(should (equal '(dummy :prop2 sym4 sym5 :prop1 sym6) result))))
|