1;;; alchemist-test-mode-test.el --- Test suite for Alchemist testing mode 2 3;; Copyright © 2015 Samuel Tonini 4;; 5;; Author: Samuel Tonini <tonini.samuel@gmail.com> 6 7;; This file is not part of GNU Emacs. 8 9;; This program is free software: you can redistribute it and/or modify 10;; it under the terms of the GNU General Public License as published by 11;; the Free Software Foundation, either version 3 of the License, or 12;; (at your option) any later version. 13 14;; This program is distributed in the hope that it will be useful, 15;; but WITHOUT ANY WARRANTY; without even the implied warranty of 16;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17;; GNU General Public License for more details. 18 19;; You should have received a copy of the GNU General Public License 20;; along with this program. If not, see <http://www.gnu.org/licenses/>. 21 22;;; Commentary: 23 24;; Test suite for Alchemist testing mode 25 26;;; Code: 27 28(require 'test-helper) 29 30(defun alchemist-test-current-position () 31 (interactive) 32 (message "current position > %s")) 33 34(defmacro alchemist-test-with-temp-buffer (content &rest body) 35 "Evaluate BODY in a temporary buffer with CONTENTS." 36 (declare (debug t) 37 (indent 1)) 38 `(with-temp-buffer 39 (insert ,content) 40 (alchemist-mode) 41 (alchemist-test-mode) 42 (font-lock-fontify-buffer) 43 (goto-char (point-min)) 44 ,@body)) 45 46(defun alchemist-test-face-at (pos &optional content) 47 "Get the face at POS in CONTENT. 48 49If CONTENT is not given, return the face at POS in the current 50buffer." 51 (if content 52 (alchemist-test-with-temp-buffer content 53 (get-text-property pos 'face)) 54 (get-text-property pos 'face))) 55 56(ert-deftest fontify-specific-functions-inside-testing-mode () 57 (alchemist-test-with-temp-buffer 58 " 59defmodule MyTest do 60 use ExUnit.Case 61 62 test \"foo\" do 63 assert true 64 assert_in_delta 1.1, 1.5, 0.2 65 assert_raise(ArgumentError, fn -> :foo end) 66 67 refute false 68 refute_in_delta 1.1, 1.5, 0.2 69 refute_receive :foo 70 refute_receive(:foo) 71 end 72 73 test \"...\" do 74 flunk \"failed\" 75 flunk(\"failed\") 76 end 77end 78" 79 (should (eq (alchemist-test-face-at 43) 'font-lock-variable-name-face)) 80 (should (eq (alchemist-test-face-at 63) 'font-lock-type-face)) 81 (should (eq (alchemist-test-face-at 114) 'font-lock-type-face)) 82 (should (eq (alchemist-test-face-at 162) 'font-lock-type-face)) 83 (should (eq (alchemist-test-face-at 179) 'font-lock-type-face)) 84 (should (eq (alchemist-test-face-at 213) 'font-lock-type-face)) 85 (should (eq (alchemist-test-face-at 237) 'font-lock-type-face)) 86 (should (eq (alchemist-test-face-at 267) 'font-lock-variable-name-face)) 87 88 (should (eq (alchemist-test-face-at 283) 'font-lock-type-face)) ;; flunk "msg" 89 (should (eq (alchemist-test-face-at 302) 'font-lock-type-face)) ;; flunk("msg") 90 )) 91 92(ert-deftest get-list-of-all-tests-in-buffer () 93 (should (equal '("\"create a pkg file/dir skeleton\"" ":symbol") 94 (with-temp-buffer 95 (alchemist-test-mode) 96 (insert " 97defmodule MyTest do 98 test \"create a pkg file/dir skeleton\" do 99 end 100 101 test :symbol do 102 end 103end 104") 105 (-map 'car (alchemist-test-mode--tests-in-buffer)))))) 106 107(provide 'alchemist-test-mode-test) 108 109;;; alchemist-test-mode-test.el ends here 110