1;;; alchemist-info-test.el ---
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;;
25
26;;; Code:
27
28(require 'test-helper)
29
30(defun datatype-info-of-expr (expr)
31  (with-temp-buffer
32    (alchemist-mode)
33    (insert expr)
34    (goto-char (point-min))
35    (alchemist-info-expression-at-point)))
36
37(defun info-buffer-content ()
38  (with-current-buffer alchemist-info-buffer-name
39    (buffer-substring-no-properties (point-min) (point-max))))
40
41(defun write-expr-and-get-datatype (expr)
42  (with-temp-buffer
43    (alchemist-mode)
44    (insert expr)
45    (goto-char (point-min))
46    (alchemist-info-datatype-at-point)
47    (wait 3)))
48
49;; Because the following functionality are Elixir v1.2 dependent
50;; the tests will just run if a proper Elixir version is available.
51(when (string-match "Elixir 1\.2.*" (alchemist-elixir-version))
52  (ert-deftest alchemist-info/datatype-info ()
53    (write-expr-and-get-datatype "List")
54    (should (string-match "Term
55  List
56Data type
57  Atom" (info-buffer-content)))
58    (write-expr-and-get-datatype ":ok")
59    (should (string-match "Term
60  :ok
61Data type
62  Atom
63Reference modules
64  Atom" (info-buffer-content)))
65    (write-expr-and-get-datatype "\"string\"")
66    (should (string-match "Term
67  \"string\"
68Data type
69  BitString
70Byte size
71  6" (info-buffer-content))))
72
73  (ert-deftest alchemist-info/expression-at-point ()
74    (should (equal (datatype-info-of-expr "Enum.any?")
75                   "Enum.any?"))
76    (should (equal (datatype-info-of-expr "String")
77                   "String"))
78    (should (equal (datatype-info-of-expr "String.Unicode")
79                   "String.Unicode"))
80    (should (equal (datatype-info-of-expr ":ok")
81                   ":ok"))
82    (should (equal (datatype-info-of-expr "'Bitstring'")
83                   "'Bitstring'"))
84    (should (equal (datatype-info-of-expr "\"And?\"")
85                   "\"And?\""))))
86(provide 'alchemist-info-test)
87
88;;; alchemist-info-test.el ends here
89