[-- Attachment #1: Type: text/plain, Size: 1285 bytes --] Hi, I encountered a bug in test-org-element/cache. The test creates the following Org file with table and runs (org-element-at-point) at the beginning of the second line. The expectation in the test is that we are at the table row, while in reality these are two distinct tables (the "ab" line is a table within "item" list entry): #+begin_center P0 - item P1 | a | b | | c | d | #+end_center I tested with emacs -Q (with no org-element-cache enabled). The return value of (org-element-at-point) is (table (...)). In the test (before inserting "item") the same point has different element: #+begin_center P0 P1 | a | b | | c | d | #+end_center Now, org-element-at-point (correctly) returns (table-row (...)). The master version of the test assumed that element would not change after modification (wrong). Yet, the test was passing with org-element-use-cache enabled (it should have not been). The current patch is fixing the test. Though I am not sure if it should be applied right now. The correct test will fail and org-element also need to be fixed. I do have a fix for org-element, but it is quite complex, not fully ready yet, involves other features, and needs to be discussed carefully. So, I am only submitting the patch for the test for now. Best, Ihor [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-Fix-test-org-element-cache-Preserve-local-structures.patch --] [-- Type: text/x-diff, Size: 1403 bytes --] From b9da1e2c4faeb5545fb43641209dd6eca80f5d51 Mon Sep 17 00:00:00 2001 Message-Id: <b9da1e2c4faeb5545fb43641209dd6eca80f5d51.1621077736.git.yantar92@gmail.com> From: Ihor Radchenko <yantar92@gmail.com> Date: Sat, 15 May 2021 19:19:09 +0800 Subject: [PATCH] Fix test-org-element/cache "Preserve local structures when re-parenting." * testing/lisp/test-org-element.el (test-org-element/cache): Add spaces to make the "abcd" table a single table. The old version uses example org text with two tables and was passing because of another bug in org-element-cache. Testing the old version with org-element-use-cache set to nil would yield error, while it should not. --- testing/lisp/test-org-element.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index 4f108754c..28e9ecd12 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -3770,7 +3770,7 @@ (ert-deftest test-org-element/cache () (eq 'table (let ((org-element-use-cache t)) (org-test-with-temp-text - "#+begin_center\nP0\n\n<point>\n\n P1\n | a | b |\n| c | d |\n#+end_center" + "#+begin_center\nP0\n\n<point>\n\n P1\n | a | b |\n | c | d |\n#+end_center" (save-excursion (search-forward "| c |") (org-element-at-point)) (insert "- item") (search-forward "| c |") -- 2.26.3
Ihor Radchenko <yantar92@gmail.com> writes:
> I encountered a bug in test-org-element/cache.
Applied in maint, thanks!
--
Bastien
Hello,
Ihor Radchenko <yantar92@gmail.com> writes:
> I encountered a bug in test-org-element/cache. The test creates the
> following Org file with table and runs (org-element-at-point) at the
> beginning of the second line. The expectation in the test is that we are
> at the table row, while in reality these are two distinct tables (the
> "ab" line is a table within "item" list entry):
>
> #+begin_center
> P0
>
> - item
>
> P1
> | a | b |
> | c | d |
> #+end_center
>
>
> I tested with emacs -Q (with no org-element-cache enabled). The return
> value of (org-element-at-point) is (table (...)). In the test (before
> inserting "item") the same point has different element:
>
> #+begin_center
> P0
>
>
>
> P1
> | a | b |
> | c | d |
> #+end_center
>
> Now, org-element-at-point (correctly) returns (table-row (...)).
I'm not sure to understand your report, but `org-element-at-point'
should return a `table' element at the very beginning of a table (here
at the beginning of the first row), not a `table-row'.
Regards,
--
Nicolas Goaziou
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> I'm not sure to understand your report, but `org-element-at-point'
> should return a `table' element at the very beginning of a table (here
> at the beginning of the first row), not a `table-row'.
Sorry, I was probably not very clear. The test does the following:
1. Create initial file like:
#+begin_center
P0
P1
| a | b |
<point>| c | d |
#+end_center
Note that second line of the table is not indented.
Now, org-element-at-point returns table-row.
2. Modify the file to test org-element-cache
#+begin_center
P0
- item
P1
| a | b |
<point>| c | d |
#+end_center
Now, the first (indented) row of the table belongs to item. The second
row becomes individual table and org-element-at-point returns table.
The patch asserted that org-element-at-point still returned a table row.
Best,
Ihor
[-- Attachment #1: Type: text/plain, Size: 233 bytes --] Bastien <bzg@gnu.org> writes: > Applied in maint, thanks! The patch also revealed an idea for another test. The new test is revealing existing bug on master. Attached is the patch adding the test with ":expected-result :failed". [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-Add-a-test-for-known-bug-in-org-element-cache.patch --] [-- Type: text/x-diff, Size: 1899 bytes --] From d3a5a606c64ed1da0d1880f503c2461839dbfec9 Mon Sep 17 00:00:00 2001 Message-Id: <d3a5a606c64ed1da0d1880f503c2461839dbfec9.1621081760.git.yantar92@gmail.com> From: Ihor Radchenko <yantar92@gmail.com> Date: Sat, 15 May 2021 20:27:20 +0800 Subject: [PATCH] Add a test for known bug in org-element-cache * testing/lisp/test-org-element.el (test-org-element/cache-bugs): A new test documenting a known bug: 1. Create initial file like: P0 P1 | a | b | <point>| c | d | Note that second line of the table is not indented. Now, org-element-at-point returns table-row. 2. Modify the file to test org-element-cache P0 - item P1 | a | b | <point>| c | d | Now, the first (indented) row of the table belongs to item. The second row should be an individual table and org-element-at-point returns table. --- testing/lisp/test-org-element.el | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index 28e9ecd12..18991b5bc 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -3889,6 +3889,21 @@ (ert-deftest test-org-element/cache () :end (org-element-property :parent (org-element-at-point))) (+ parent-end 3)))))) +(ert-deftest test-org-element/cache-bugs () + "Test basic expectations and common pitfalls for cache." + :expected-result :failed + ;; Unindented second row of the table should not be re-parented by + ;; inserted item. + (should + (eq 'table + (let ((org-element-use-cache t)) + (org-test-with-temp-text + "#+begin_center\nP0\n\n<point>\n\n P1\n | a | b |\n| c | d |\n#+end_center" + (save-excursion (search-forward "| c |") (org-element-at-point)) + (insert "- item") + (search-forward "| c |") + (beginning-of-line) + (org-element-type (org-element-at-point))))))) (provide 'test-org-element) -- 2.26.3
> The patch asserted that org-element-at-point still returned a table row.
* The old test
Ihor Radchenko <yantar92@gmail.com> writes:
> Bastien <bzg@gnu.org> writes:
>> Applied in maint, thanks!
>
> The patch also revealed an idea for another test. The new test is
> revealing existing bug on master. Attached is the patch adding the test
> with ":expected-result :failed".
Applied in master, thanks.
--
Bastien