summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Brand <michael.ch.brand@gmail.com>2014-01-12 09:51:34 (GMT)
committer Michael Brand <michael.ch.brand@gmail.com>2014-01-12 09:51:34 (GMT)
commit3ab9b6b37d596606206aaeb4766773bb92d6cb94 (patch)
tree2c6292a4375ceca49fabd50035a4ea15e6adc9e0
parent90884b9748f87acc9ad2ac8810e9b5472387ff72 (diff)
downloadorg-mode-3ab9b6b37d596606206aaeb4766773bb92d6cb94.zip
org-mode-3ab9b6b37d596606206aaeb4766773bb92d6cb94.tar.gz
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.
-rw-r--r--testing/lisp/test-org-table.el80
1 files changed, 80 insertions, 0 deletions
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
"