From 21152c2045345135fd18749e016367aa0388ae4b Mon Sep 17 00:00:00 2001 From: Michael Brand Date: Sat, 4 Jan 2014 16:21:28 +0100 Subject: [PATCH 1/2] TBLFM remote ref: Add ERT for summary table * testing/lisp/test-org-table.el (test-org-table/remote-reference-indirect): Add a use case of summarizing two tables with a sum into one table for the total; as a preparation for remote reference indirection. --- testing/lisp/test-org-table.el | 80 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/testing/lisp/test-org-table.el b/testing/lisp/test-org-table.el index edb51c4..a4f8caa 100644 --- a/testing/lisp/test-org-table.el +++ b/testing/lisp/test-org-table.el @@ -793,6 +793,86 @@ See also `test-org-table/copy-field'." ;; Do a calculation: Use Calc (or Lisp ) formula "$2 = 2 * remote(table, @1$2)"))) +(ert-deftest test-org-table/remote-reference-indirect () + "Access to remote reference with indirection of name or ID." + (let ((source-tables " +#+NAME: 2012 +| amount | +|--------| +| 1 | +| 2 | +|--------| +| 3 | +#+TBLFM: @>$1 = vsum(@I..@II) + +#+NAME: 2013 +| amount | +|--------| +| 4 | +| 8 | +|--------| +| 12 | +#+TBLFM: @>$1 = vsum(@I..@II) +")) + + ;; Read several remote references from same column + (org-test-table-target-expect + (concat source-tables " +#+NAME: summary +| year | amount | +|-------+---------| +| 2012 | replace | +| 2013 | replace | +|-------+---------| +| total | replace | +") + (concat source-tables " +#+NAME: summary +| year | amount | +|-------+--------| +| 2012 | 3 | +| 2013 | 12 | +|-------+--------| +| total | 15 | +") + 1 + ;; Calc formula + (concat "#+TBLFM: " + "@2$2 = remote(2012, @>$1) :: " + "@3$2 = remote(2013, @>$1) :: " + "@>$2 = vsum(@I..@II)") + ;; Lisp formula + (concat "#+TBLFM: " + "@2$2 = '(identity remote(2012, @>$1)); N :: " + "@3$2 = '(identity remote(2013, @>$1)); N :: " + "@>$2 = '(+ @I..@II); N")) + + ;; Read several remote references from same row + (org-test-table-target-expect + (concat source-tables " +#+NAME: summary +| year | 2012 | 2013 | total | +|--------+---------+---------+---------| +| amount | replace | replace | replace | +") + (concat source-tables " +#+NAME: summary +| year | 2012 | 2013 | total | +|--------+------+------+-------| +| amount | 3 | 12 | 15 | +") + 1 + ;; Calc formula + (concat "#+TBLFM: " + "@2$2 = remote(2012, @>$1) :: " + "@2$3 = remote(2013, @>$1) :: " + "@2$> = vsum($<<..$>>)") + ;; Lisp formula + (concat "#+TBLFM: " + "@2$2 = '(identity remote(2012, @>$1)); N :: " + "@2$3 = '(identity remote(2013, @>$1)); N :: " + "@2$> = '(+ $<<..$>>); N")))) + (ert-deftest test-org-table/org-at-TBLFM-p () (org-test-with-temp-text-in-file " -- 1.7.12.4 (Apple Git-37)