Skip to content

Commit

Permalink
fix: Detect TT with sub-tables correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushalmodi committed Apr 30, 2022
1 parent a7b3a57 commit b64eb07
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
8 changes: 6 additions & 2 deletions test/tinternal.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))))))
Expand All @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions test/ttable-array.el
Original file line number Diff line number Diff line change
Expand Up @@ -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 '(
Expand Down
14 changes: 8 additions & 6 deletions tomelr.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b64eb07

Please sign in to comment.