1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
;;; test-util.el --- Flycheck Specs: Utility functions -*- lexical-binding: t; -*-
;; Copyright (C) 2016 Sebastian Wiesner and Flycheck contributors
;; Author: Sebastian Wiesner <swiesner@lunaryorn.com>
;; 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 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/>.
;;; Commentary:
;; Specs for Flycheck's utility functions
;;; Code:
(require 'flycheck-buttercup)
(describe "Utilties"
(describe "flycheck-buffer-empty-p"
(it "considers an empty buffer as empty"
(with-temp-buffer
(expect (flycheck-buffer-empty-p) :to-be-truthy)))
(it "does not consider an buffer with content as empty"
(with-temp-buffer
(insert "foo bar")
(expect (flycheck-buffer-empty-p) :not :to-be-truthy)))
(it "detects emptiness of narrowed buffers"
(with-temp-buffer
(insert "foo\nbar")
(goto-char (point-min))
(narrow-to-region (point-min) (point-min))
(expect (buffer-string) :to-equal "")
(expect (flycheck-buffer-empty-p) :not :to-be-truthy))))
(describe "flycheck-buffer-saved-p"
(it "considers an unmodified buffer without backing file unsaved"
(with-temp-buffer
(expect (flycheck-buffer-saved-p) :not :to-be-truthy)))
(it "considers a modified buffer without backing file unsaved"
(with-temp-buffer
(set-buffer-modified-p t)
(expect (flycheck-buffer-saved-p) :not :to-be-truthy)))
(it "considers an unmodified buffer with backing file saved"
(spy-on 'file-exists-p :and-return-value t)
(spy-on 'buffer-file-name :and-return-value "test-buffer-name")
(with-temp-buffer
(expect (flycheck-buffer-saved-p) :to-be-truthy))
(expect (spy-calls-count 'file-exists-p) :to-equal 1)
(expect (spy-calls-count 'buffer-file-name) :to-equal 1))
(it "considers a modified buffer with backing file unsaved"
(spy-on 'file-exists-p :and-return-value t)
(spy-on 'buffer-file-name :and-return-value "test-buffer-name")
(with-temp-buffer
(set-buffer-modified-p t)
(expect (flycheck-buffer-saved-p) :not :to-be-truthy))
(expect (spy-calls-count 'file-exists-p) :to-equal 1)
(expect (spy-calls-count 'buffer-file-name) :to-equal 1))))
;;; test-util.el ends here
|