1;;; alchemist-macroexpand-test.el ---
2
3;; Copyright © 2014-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(require 'alchemist-macroexpand)
30
31(defun capture-macroexpand-popup-content ()
32  (with-current-buffer (get-buffer alchemist-macroexpand-buffer-name)
33    (buffer-substring-no-properties (point-min) (point-max))))
34
35
36(ert-deftest alchemist-macroexpand/expand-once-current-line ()
37  (with-temp-buffer
38    (alchemist-mode)
39    (insert "unless false, do: IO.puts 'Please no!'")
40    (alchemist-macroexpand-once-current-line)
41    (wait 1))
42  (should (equal "if(false) do
43  nil
44else
45  IO.puts('Please no!')
46end"
47                 (capture-macroexpand-popup-content))))
48
49(ert-deftest alchemist-macroexpand/expand-current-line ()
50  (with-temp-buffer
51    (alchemist-mode)
52    (insert "unless false, do: IO.puts 'Please no!'")
53    (alchemist-macroexpand-current-line)
54    (wait 1))
55  (should (equal "case(false) do
56  x when x in [false, nil] ->
57    IO.puts('Please no!')
58  _ ->
59    nil
60end"
61                 (capture-macroexpand-popup-content))))
62
63(ert-deftest alchemist-macroexpand/expand-once-region ()
64  (with-temp-buffer
65    (alchemist-mode)
66    (insert "unless false do
67  IO.puts 'Please no!'
68end")
69    (alchemist-macroexpand-once-region (point-min) (point-max))
70    (wait 1))
71  (should (equal "if(false) do
72  nil
73else
74  IO.puts('Please no!')
75end"
76                 (capture-macroexpand-popup-content))))
77
78(ert-deftest alchemist-macroexpand/expand-region ()
79  (with-temp-buffer
80    (alchemist-mode)
81    (insert "unless false do
82  IO.puts 'Please no!'
83end")
84    (alchemist-macroexpand-region (point-min) (point-max))
85    (wait 1))
86  (should (equal "case(false) do
87  x when x in [false, nil] ->
88    IO.puts('Please no!')
89  _ ->
90    nil
91end"
92                 (capture-macroexpand-popup-content))))
93
94(ert-deftest alchemist-macroexpand/expand-once-print-current-line ()
95  (should (equal "unless false, do: IO.puts 'Please no!'
96# => if(false) do
97# =>   nil
98# => else
99# =>   IO.puts('Please no!')
100# => end" (with-temp-buffer
101            (alchemist-mode)
102            (insert "unless false, do: IO.puts 'Please no!'")
103            (alchemist-macroexpand-once-print-current-line)
104            (wait 1)
105            (buffer-substring-no-properties (point-min) (point-max))))))
106
107
108(ert-deftest alchemist-macroexpand/expand-print-current-line ()
109  (should (equal "unless false, do: IO.puts 'Please no!'
110# => case(false) do
111# =>   x when x in [false, nil] ->
112# =>     IO.puts('Please no!')
113# =>   _ ->
114# =>     nil
115# => end" (with-temp-buffer
116            (alchemist-mode)
117            (insert "unless false, do: IO.puts 'Please no!'")
118            (alchemist-macroexpand-print-current-line)
119            (wait 1)
120            (buffer-substring-no-properties (point-min) (point-max))))))
121
122(ert-deftest alchemist-macroexpand/expand-once-print-region ()
123  (should (equal "unless false do
124  IO.puts 'Please no!'
125end
126# => if(false) do
127# =>   nil
128# => else
129# =>   IO.puts('Please no!')
130# => end" (with-temp-buffer
131            (alchemist-mode)
132            (insert "unless false do
133  IO.puts 'Please no!'
134end")
135            (alchemist-macroexpand-once-print-region (point-max) (point-min))
136            (wait 1)
137            (buffer-substring-no-properties (point-min) (point-max))))))
138
139(ert-deftest alchemist-macroexpand/expand-print-region ()
140  (should (equal "unless false do
141  IO.puts 'Please no!'
142end
143# => case(false) do
144# =>   x when x in [false, nil] ->
145# =>     IO.puts('Please no!')
146# =>   _ ->
147# =>     nil
148# => end" (with-temp-buffer
149            (alchemist-mode)
150            (insert "unless false do
151  IO.puts 'Please no!'
152end")
153            (alchemist-macroexpand-print-region (point-max) (point-min))
154            (wait 1)
155            (buffer-substring-no-properties (point-min) (point-max))))))
156
157(provide 'alchemist-macroexpand-test)
158
159;;; alchemist-macroexpand-test.el ends here
160