;;; 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 . ;;; 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