From a6a00af0f3f291fb0b4eb19012b80d28d3419a38 Mon Sep 17 00:00:00 2001 From: Florian Beck Date: Tue, 9 Sep 2014 12:40:27 +0200 Subject: [PATCH 4/4] test-org-table: Add tests * testing/lisp/test-org-table.el (test-org-table/org-table-end-of-field, test-org-table/org-table-beginning-of-field): New tests. --- testing/lisp/test-org-table.el | 105 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/testing/lisp/test-org-table.el b/testing/lisp/test-org-table.el index 40101be..49ed153 100644 --- a/testing/lisp/test-org-table.el +++ b/testing/lisp/test-org-table.el @@ -1168,6 +1168,111 @@ See also `test-org-table/copy-field'." (should (string= got expect))))) +(ert-deftest test-org-table/org-table-end-of-field () + "Test `org-table-end-of-field' specifications." + ;; Outside a table, return an error. + (should-error + (org-test-with-temp-text "Paragraph" + (goto-char 2) + (org-table-end-of-field))) + ;; Move to end of cell. + (should + (org-test-with-temp-text + "| Cell:1 | Cell2 |Cell3|\n| Cell4 | | Cell5|" + (search-forward ":") + (org-table-end-of-field) + (looking-back "Cell:1"))) + ;; Move to next cell if already at the end. + (should + (org-test-with-temp-text + "| Cell:1 | Cell2 |Cell3|\n| Cell4 | | Cell5|" + (search-forward ":") + (org-table-end-of-field) + (org-table-end-of-field) + (looking-back "Cell2"))) + ;; Work in unaligned cells. + (should + (org-test-with-temp-text + "| Cell1 | Cell2 |Cell:3|\n| Cell4 | | Cell5|" + (search-forward ":") + (org-table-end-of-field) + (looking-back "Cell:3"))) + ;; Move to next row + (should + (org-test-with-temp-text + "| Cell1 | Cell2 |Cell:3|\n| Cell4 | | Cell5|" + (search-forward ":") + (org-table-end-of-field) + (org-table-end-of-field) + (looking-back "Cell4"))) + ;; With argument, skip N-1 fields forward + (should + (org-test-with-temp-text + "| Cell:1 | Cell2 |Cell3|\n| Cell4 | | Cell5|" + (search-forward ":") + (org-table-end-of-field 4) + (looking-back "Cell4"))) + ;; Empty cells + (should + (org-test-with-temp-text + "| Cell1 | Cell2 |Cell3|\n| Cell4: | | Cell5|" + (search-forward ":") + (forward-char) + (org-table-end-of-field) + (looking-back "| "))) + (should + (org-test-with-temp-text + "| Cell1 | Cell2 |Cell3|\n| Cell4: | | Cell5|" + (search-forward ":") + (forward-char 6) + (org-table-end-of-field) + (looking-back "Cell5"))) + (should + (org-test-with-temp-text + "| Cell1 | Cell2 |Cell3|\n| Cell4: || Cell5|" + (search-forward ":") + (forward-char 3) + (org-table-end-of-field) + (looking-back "Cell5"))) + ;; On table border + (should + (org-test-with-temp-text + "| Cell1 | Cell2 |:Cell3|\n| Cell4 || Cell5|" + (search-forward ":") + (forward-char -2) + (org-table-end-of-field) + (looking-back ":Cell3")))) + +(ert-deftest test-org-table/org-table-beginning-of-field () + "Test `org-table-beginning-of-field' specifications." + ;; Outside a table, return an error. + (should-error + (org-test-with-temp-text "Paragraph" + (goto-char 2) + (org-table-beginning-of-field))) + ;; Move to end of cell. + (should + (org-test-with-temp-text + "| Cell:1 | Cell2 |Cell3|\n| Cell4 | | Cell5|" + (search-forward ":") + (org-table-beginning-of-field) + (looking-at "Cell:1"))) + ;; With argument, skip N-1 fields backwards + (should + (org-test-with-temp-text + "| Cell1 | Cell2 |Cell3|\n| Cell4 | | Cell:5|" + (search-forward ":") + (org-table-beginning-of-field 5) + (looking-at "Cell2"))) + ;; Empty cells + (should + (org-test-with-temp-text + "| Cell1 | Cell2 |Cell3|\n| Cell4: | | Cell5|" + (search-forward ":") + (forward-char 6) + (org-table-beginning-of-field) + (looking-back "| ")))) + (provide 'test-org-table) ;;; test-org-table.el ends here -- 1.9.1