branch: externals/tomelr commit b64eb07e99e9ab45cc88dc6b628f8bc828a0dc28 Author: Kaushal Modi <kaushal.m...@gmail.com> Commit: Kaushal Modi <kaushal.m...@gmail.com>
fix: Detect TT with sub-tables correctly --- test/tinternal.el | 8 ++++++-- test/ttable-array.el | 16 ++++++++++++++++ tomelr.el | 14 ++++++++------ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/test/tinternal.el b/test/tinternal.el index 0e46b57ebb..29346b43bf 100644 --- a/test/tinternal.el +++ b/test/tinternal.el @@ -31,6 +31,10 @@ (:a 1) ((a . 1) (b . 2)) (:a 1 :b 2) + ;; Nested TT + ((a . 1) + (b . ((c . 3) + (d . 4)))) ))) (dolist (el inp) (should (equal t (tomelr--toml-table-p el)))))) @@ -47,10 +51,10 @@ ;;;; tomelr--toml-table-array-p (ert-deftest test-internal-valid-tta () (let ((inp '( - ;; ;; TTA with 1 table of 1 key-val pair + ;; TTA with 1 table of 1 key-val pair (((a . 1))) ((:a 1)) - ;; ;; TTA with 2 tables of 2 key-val pairs + ;; TTA with 2 tables of 2 key-val pairs (((a . 1) (b . 2)) ((a . 100) (b . 200))) ((:a 1 :b 2) diff --git a/test/ttable-array.el b/test/ttable-array.el index 5d1b2c4333..740cf10de9 100644 --- a/test/ttable-array.el +++ b/test/ttable-array.el @@ -62,6 +62,22 @@ See [org#Drawers](https://www.gnu.org/software/emacs/manual/html_mono/org.html#D (push (tomelr-encode el) out)) (should (equal ref (nreverse out))))) +;;;; Sub-table in a TOML Table Array +(ert-deftest test-subtable-in-tta () + (let ((inp '( + ((fruits . (((name . "apple") + (physical . ((color . "red") + (shape . "round"))))))))) + (ref '("[[fruits]] + name = \"apple\" + [fruits.physical] + color = \"red\" + shape = \"round\"")) + out) + (dolist (el inp) + (push (tomelr-encode el) out)) + (should (equal ref (nreverse out))))) + ;;;; Nested array of tables (ert-deftest test-nested-array-of-tables () (let ((inp '( diff --git a/tomelr.el b/tomelr.el index fc5bdc72a9..01b652b0f4 100644 --- a/tomelr.el +++ b/tomelr.el @@ -292,16 +292,18 @@ Definition of a TOML Table (TT): ;; (when (listp elem) ;; (message " [tomelr--toml-table-p DBG] sub-elem 0 = %S, type = %S, len = %d" ;; (car elem) (type-of (car elem)) (safe-length (car elem)))) - (and (consp elem) - (= 1 (safe-length elem)) - (not (consp (car elem))))) + (or (and (consp elem) + (= 1 (safe-length elem)) + (not (consp (car elem)))) + (and (listp elem) + (symbolp (car elem)) + (tomelr--toml-table-p (cdr elem))))) object) t) - ((and (listp (car object)) - (symbolp (car (car object)))) - (tomelr--toml-table-p (cdr (car object)))) (t nil)))) + ;; (message "[tomelr--toml-table-p DBG] tablep = %S" tablep) + ;; (message "=====") tablep)) (defun tomelr--print-pair (key val)