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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
| | ;;; test-org-tbljoin.el --- tests for org-tbljoin.el
;; Copyright (C) 2015 Thierry Banel
;; 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/>.
;;; Code:
;(unless (featurep 'org-tbljoin)
; (signal 'missing-test-dependency "Table Join"))
(defun org-tbljoin-test-pull (marker expected)
(org-test-at-marker
"../examples/org-tbljoin.org"
marker
(forward-line 1)
(org-update-dblock)
(let ((result (buffer-substring-no-properties (point) (progn (search-forward "#+END:") (point)))))
(set-buffer-modified-p nil)
(kill-buffer)
(should (equal result expected)))))
(ert-deftest org-tbljoin/pull/hh ()
"Joining two tables."
(org-tbljoin-test-pull
"a14723d3-13c8-4fd1-a69f-caf2fdb2d2b1"
"#+BEGIN: join :mas-table meal_with_header :mas-column $1 :ref-table nut_with_header :ref-column 2
| product | quty | Carb | Fiber | Sugar | Protein |
| common | in | ohyd | | | |
| name | gramms | rate | | | |
| (english) | | | | | |
|-----------+--------+------+-------+-------+---------|
| onion | 70 | 9.0 | 1.3 | 4.4 | 1.3 |
| unknown | 999 | | | | |
| tomatoe | 120 | 3.4 | 0.6 | 2.1 | 0.8 |
| eggplant | 300 | 8.6 | 2.5 | 3.2 | 0.8 |
| eggplant | 300 | 8.7 | 2.6 | 3.3 | 0.9 |
| eggplant | 300 | 8.5 | ? | ? | ? |
| corn | 250 | 21.3 | 4.7 | 1.8 | 2.8 |
#+END:"))
(ert-deftest org-tbljoin/pull/hb ()
"Joining two tables."
(org-tbljoin-test-pull
"79a90117-fc0e-4556-b790-c925b6acd450"
"#+BEGIN: join :mas-table \"meal_with_header\" :mas-column \"product\" :ref-table \"nut_no_header\" :ref-column \"2\"
| product | quty | | | | |
| common | in | | | | |
| name | gramms | | | | |
| (english) | | | | | |
|-----------+--------+------+-----+-----+-----|
| onion | 70 | 9.0 | 1.3 | 4.4 | 1.3 |
| unknown | 999 | | | | |
| tomatoe | 120 | 3.4 | 0.6 | 2.1 | 0.8 |
| eggplant | 300 | 8.6 | 2.5 | 3.2 | 0.8 |
| eggplant | 300 | 8.7 | 2.6 | 3.3 | 0.9 |
| eggplant | 300 | 8.5 | ? | ? | ? |
| corn | 250 | 21.3 | 4.7 | 1.8 | 2.8 |
#+END:"))
(ert-deftest org-tbljoin/pull/bh ()
"Joining two tables."
(org-tbljoin-test-pull
"24c5a7b4-2815-40d4-89ec-32b58f492b32"
"#+BEGIN: join :mas-table meal_no_header :mas-column $1 :ref-table nut_with_header :ref-column type
| onion | 70 | 9.0 | 1.3 | 4.4 | 1.3 |
| not known | 999 | | | | |
| tomatoe | 120 | 3.4 | 0.6 | 2.1 | 0.8 |
| eggplant | 300 | 8.6 | 2.5 | 3.2 | 0.8 |
| eggplant | 300 | 8.7 | 2.6 | 3.3 | 0.9 |
| eggplant | 300 | 8.5 | ? | ? | ? |
| corn | 250 | 21.3 | 4.7 | 1.8 | 2.8 |
#+END:"))
(ert-deftest org-tbljoin/pull/bb ()
"Joining two tables."
(org-tbljoin-test-pull
"e872df5c-dd5c-4ad6-b395-2e5a000488b5"
"#+BEGIN: join :mas-table meal_no_header :mas-column 1 :ref-table nut_no_header :ref-column $2
| onion | 70 | 9.0 | 1.3 | 4.4 | 1.3 |
| not known | 999 | | | | |
| tomatoe | 120 | 3.4 | 0.6 | 2.1 | 0.8 |
| eggplant | 300 | 8.6 | 2.5 | 3.2 | 0.8 |
| eggplant | 300 | 8.7 | 2.6 | 3.3 | 0.9 |
| eggplant | 300 | 8.5 | ? | ? | ? |
| corn | 250 | 21.3 | 4.7 | 1.8 | 2.8 |
#+END:"))
(defun org-tbljoin-test-push (markersrc marker1 marker2 expected1 expected2)
(org-test-at-marker
"../examples/org-tbljoin.org"
markersrc
(beginning-of-line)
(forward-line 3)
(orgtbl-send-table 'maybe)
(let ((result1
(buffer-substring-no-properties
(progn (search-forward marker1) (forward-char 1) (org-table-align) (point))
(progn (search-forward "#+END") (point))))
(result2
(buffer-substring-no-properties
(progn (search-forward marker2) (forward-char 1) (org-table-align) (point))
(progn (search-forward "#+END") (point)))))
(set-buffer-modified-p nil)
(kill-buffer)
(message "result1 = %s" result1)
(should
(and
(equal result1 expected1)
(equal result2 expected2))))))
(ert-deftest org-tbljoin/push/h ()
(org-tbljoin-test-push
"6426c948-bbd4-4b25-8b3d-2584b70af4d0"
"#+BEGIN RECEIVE ORGTBL joined1"
"#+BEGIN RECEIVE ORGTBL joined2"
"| product | quty | Carb | Fiber | Sugar | Protein |
| (yes) | (g) | ohyd | | | |
|---------------+------+------+-------+-------+---------|
| onion | 70 | 9.0 | 1.3 | 4.4 | 1.3 |
| not specified | 999 | | | | |
| tomatoe | 120 | 3.4 | 0.6 | 2.1 | 0.8 |
| eggplant | 300 | 8.6 | 2.5 | 3.2 | 0.8 |
| eggplant | 300 | 8.7 | 2.6 | 3.3 | 0.9 |
| eggplant | 300 | 8.5 | ? | ? | ? |
| corn | 250 | 21.3 | 4.7 | 1.8 | 2.8 |
#+END"
"| product | quty | | | | |
| (yes) | (g) | | | | |
|---------------+------+------+-----+-----+-----|
| onion | 70 | 9.0 | 1.3 | 4.4 | 1.3 |
| not specified | 999 | | | | |
| tomatoe | 120 | 3.4 | 0.6 | 2.1 | 0.8 |
| eggplant | 300 | 8.6 | 2.5 | 3.2 | 0.8 |
| eggplant | 300 | 8.7 | 2.6 | 3.3 | 0.9 |
| eggplant | 300 | 8.5 | ? | ? | ? |
| corn | 250 | 21.3 | 4.7 | 1.8 | 2.8 |
#+END"))
(ert-deftest org-tbljoin/push/b ()
(org-tbljoin-test-push
"1683a68c-f4df-4b04-9f2d-bd4c8a909bf3"
"#+BEGIN RECEIVE ORGTBL joined3"
"#+BEGIN RECEIVE ORGTBL joined4"
"| onion | 70 | 9.0 | 1.3 | 4.4 | 1.3 |
| not specified | 999 | | | | |
| tomatoe | 120 | 3.4 | 0.6 | 2.1 | 0.8 |
| eggplant | 300 | 8.6 | 2.5 | 3.2 | 0.8 |
| eggplant | 300 | 8.7 | 2.6 | 3.3 | 0.9 |
| eggplant | 300 | 8.5 | ? | ? | ? |
| corn | 250 | 21.3 | 4.7 | 1.8 | 2.8 |
#+END"
"| onion | 70 | 9.0 | 1.3 | 4.4 | 1.3 |
| not specified | 999 | | | | |
| tomatoe | 120 | 3.4 | 0.6 | 2.1 | 0.8 |
| eggplant | 300 | 8.6 | 2.5 | 3.2 | 0.8 |
| eggplant | 300 | 8.7 | 2.6 | 3.3 | 0.9 |
| eggplant | 300 | 8.5 | ? | ? | ? |
| corn | 250 | 21.3 | 4.7 | 1.8 | 2.8 |
#+END"))
(ert-deftest org-tbljoin/pull/auto ()
"Cartesian product of a table with itself."
(org-tbljoin-test-pull
"b6e51dab-cded-427e-8967-d14a34070d08"
"#+BEGIN: join :mas-table auto :mas-column t :ref-table auto :ref-column \"t\"
| t | n | n |
|---+---+---|
| a | 1 | 1 |
| a | 1 | 2 |
| a | 1 | 3 |
| a | 1 | 4 |
| a | 1 | 5 |
| a | 1 | 6 |
| a | 1 | 7 |
| a | 2 | 1 |
| a | 2 | 2 |
| a | 2 | 3 |
| a | 2 | 4 |
| a | 2 | 5 |
| a | 2 | 6 |
| a | 2 | 7 |
| a | 3 | 1 |
| a | 3 | 2 |
| a | 3 | 3 |
| a | 3 | 4 |
| a | 3 | 5 |
| a | 3 | 6 |
| a | 3 | 7 |
| a | 4 | 1 |
| a | 4 | 2 |
| a | 4 | 3 |
| a | 4 | 4 |
| a | 4 | 5 |
| a | 4 | 6 |
| a | 4 | 7 |
| a | 5 | 1 |
| a | 5 | 2 |
| a | 5 | 3 |
| a | 5 | 4 |
| a | 5 | 5 |
| a | 5 | 6 |
| a | 5 | 7 |
| a | 6 | 1 |
| a | 6 | 2 |
| a | 6 | 3 |
| a | 6 | 4 |
| a | 6 | 5 |
| a | 6 | 6 |
| a | 6 | 7 |
| a | 7 | 1 |
| a | 7 | 2 |
| a | 7 | 3 |
| a | 7 | 4 |
| a | 7 | 5 |
| a | 7 | 6 |
| a | 7 | 7 |
#+END:"))
(provide 'test-org-tbljoin)
;;; test-org-tbljoin.el ends here
|