-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest-ob-nim.el
112 lines (93 loc) · 2.78 KB
/
test-ob-nim.el
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
;;; test-ob-nim.el --- Tests for ob-nim.el -*- lexical-binding: t; -*-
;; Copyright (C) 2016
;; Author: <lompik@oriontabArch>
;; Keywords: convenience
;; 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:
;;
;;; Code:
(require 'ob-nim)
(describe
"ob-nim tests"
(before-each
(set-buffer (get-buffer-create "*Test*"))
(progn
(setq org-confirm-babel-evaluate nil)
(org-babel-do-load-languages 'org-babel-load-languages
'((emacs-lisp . t) (nim . t) (org . t))))
(erase-buffer)
(org-mode))
(after-each
(kill-buffer (get-buffer-create "*Test*")))
(it "should process `begin_src' headers
"
(insert "
#+header: :var x = 3
#+begin_src nim :import sequtils strutils :define release mydef
when defined(release):
when defined(mydef):
var temp = @[1, 2].map (proc(i:int ) : string= $(i*x) )
echo temp.join(\"/\")
#+end_src")
(goto-char 0)
(org-babel-next-src-block)
(expect (org-babel-execute-src-block) :to-equal "3/6"))
(it "should convert table with no colname
"
(insert "#+name: eg
| col1 | col2 |
|------+------|
| a | 1 |
| b | 2.0 |
#+header: :colnames no
#+header: :var x = eg
#+begin_src nim
import strutils
proc print_2d [I1,I2,T2](x:array[I1,array[I2,T2]]): void =
for i in x:
echo i.join(\" \")
print_2d(x)
#+end_src")
(goto-char 0)
(org-babel-next-src-block)
(expect (org-babel-execute-src-block) :to-equal '(("col1" "col2") ("a" 1) ("b" 2.0))))
(it "should convert table with colname
"
(insert "#+name: eg
| col1 | col2 |
|------+------|
| a | 1 |
| b | 2.0 |
#+header: :colnames yes
#+header: :var temp = eg
#+begin_src nim
import strutils
for j in temp[\"col1\"].low..temp[\"col1\"].high:
var line = \"\"
for i in temp.keys():
line &= $temp[i][j] & \" \"
echo line
#+end_src")
(goto-char 0)
(org-babel-next-src-block)
(expect (org-babel-execute-src-block) :to-equal '(("col1" "col2") hline ("a" 1) ("b" 2.0))))
(it "should not modify nim output
"
(insert "#+begin_src nim :results output
echo \"-0\"
#+end_src")
(goto-char 0)
(expect (org-babel-execute-src-block) :to-equal "-0
"))
)
(provide 'test-ob-nim)
;;; test-ob-nim.el ends here