[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/tomelr a7b3a57037 48/84: feat: Make a very basic nested
From: |
ELPA Syncer |
Subject: |
[elpa] externals/tomelr a7b3a57037 48/84: feat: Make a very basic nested array of TTA work |
Date: |
Tue, 3 May 2022 09:58:11 -0400 (EDT) |
branch: externals/tomelr
commit a7b3a5703729682e88d6352932e235cbe04deb28
Author: Kaushal Modi <kaushal.modi@gmail.com>
Commit: Kaushal Modi <kaushal.modi@gmail.com>
feat: Make a very basic nested array of TTA work
---
test/ttable-array.el | 37 +++++++++++++++++++++++++++++++++++++
tomelr.el | 15 ++++++++++-----
2 files changed, 47 insertions(+), 5 deletions(-)
diff --git a/test/ttable-array.el b/test/ttable-array.el
index 37392ba28d..5d1b2c4333 100644
--- a/test/ttable-array.el
+++ b/test/ttable-array.el
@@ -62,5 +62,42 @@ 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)))))
+;;;; Nested array of tables
+(ert-deftest test-nested-array-of-tables ()
+ (let ((inp '(
+ ((fruits . (((varieties . (((name . "red delicious"))
+ ((name . "granny smith"))))))))
+ ;; ((fruits . (((name . "apple")
+ ;; (physical . ((color . "red")
+ ;; (shape . "round")))
+ ;; (varieties . (((name . "red delicious"))
+ ;; ((name . "granny smith")))))
+ ;; ((name . "banana")
+ ;; (varieties . (((name . "plantain"))))))))
+ ))
+ (ref '("[[fruits]]
+ [[fruits.varieties]]
+ name = \"red delicious\"
+ [[fruits.varieties]]
+ name = \"granny smith\""
+ ;; "[[fruits]]
+ ;; name = \"apple\"
+ ;; [fruits.physical]
+ ;; color = \"red\"
+ ;; shape = \"round\"
+ ;; [[fruits.varieties]]
+ ;; name = \"red delicious\"
+ ;; [[fruits.varieties]]
+ ;; name = \"granny smith\"
+ ;; [[fruits]]
+ ;; name = \"banana\"
+ ;; [[fruits.varieties]]
+ ;; name = \"plantain\""
+ ))
+ out)
+ (dolist (el inp)
+ (push (tomelr-encode el) out))
+ (should (equal ref (nreverse out)))))
+
(provide 'ttable-array)
diff --git a/tomelr.el b/tomelr.el
index f61c10db9d..fc5bdc72a9 100644
--- a/tomelr.el
+++ b/tomelr.el
@@ -54,7 +54,9 @@ ordered alphabetically.")
Dictates repetitions of `tomelr-encoding-default-indentation'.")
(defvar tomelr--print-table-hierarchy ()
- "Internal variable used to save the TOML Table hierarchy.")
+ "Internal variable used to save TOML Table hierarchies.
+This variable is used for both TOML Tables and Arrays of TOML
+Tables.")
(defvar tomelr--print-table-array-key ""
"Internal variable used to save the TOML Table Array name.")
@@ -219,8 +221,7 @@ Return nil if OBJECT cannot be encoded as a TOML string."
(string-trim-left (symbol-name object) ":"))
((symbolp object)
(symbol-name object)))))
- (cond
- ((equal type 'table)
+ (when type
;; (message "[tomelr--print-stringlike DBG] %S is symbol, type = %S,
depth = %d"
;; object type tomelr--print-indentation-depth)
(if (null (nth tomelr--print-indentation-depth
tomelr--print-table-hierarchy))
@@ -236,9 +237,12 @@ Return nil if OBJECT cannot be encoded as a TOML string."
sym-name))
;; (message "[tomelr--print-stringlike DBG] table hier: %S"
;; tomelr--print-table-hierarchy)
+ )
+ (cond
+ ((equal type 'table)
(princ (format "[%s]" (string-join tomelr--print-table-hierarchy "."))))
((equal type 'table-array)
- (let ((tta-name (format "[[%s]]" sym-name)))
+ (let ((tta-name (format "[[%s]]" (string-join
tomelr--print-table-hierarchy "."))))
(setq tomelr--print-table-array-key tta-name)
(princ tta-name)))
((stringp object)
@@ -417,7 +421,8 @@ See `tomelr-encode-array' that returns the same as a
string."
(mapc (lambda (elt)
(if first
(setq first nil)
- (insert (format "\n%s" tomelr--print-table-array-key)))
+ (tomelr--print-indentation)
+ (insert tomelr--print-table-array-key))
(tomelr--print elt))
array))))
(t
- [elpa] externals/tomelr f37841cc78 25/84: test: Add test for TOML Array of Arrays, (continued)
- [elpa] externals/tomelr f37841cc78 25/84: test: Add test for TOML Array of Arrays, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr cedb75df72 29/84: feat: Support basic TOML tables, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 91800b26b8 21/84: feat: Recognize RFC 3339 formatted date-time + offset, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 83e924559e 13/84: chore(doc): Fix typo, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 98c9b8c1fc 26/84: fix: Use `=` and `length` separately instead of `length=`, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr c0962ba15f 33/84: fix: Don't run plist to TOML conversion test on emacs 26.3 and older, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 3c068fb9d9 34/84: refactor: Move TOML Table detection logic to a separate fn, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr ad8366d904 36/84: feat: Support basic TOML Table Arrays, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 55fefb0fa8 40/84: doc: Add few links, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 38160ef271 41/84: fix: Stricter condition before starting TOML table array check, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr a7b3a57037 48/84: feat: Make a very basic nested array of TTA work,
ELPA Syncer <=
- [elpa] externals/tomelr 3aa4dc1dbd 54/84: chore: Add Package-Requires and other info in the header comment, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr f3b6951cfe 53/84: doc: Add note that the scalars need to be earlier in the order, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 192cb06a23 57/84: chore(style): Whitespace change only, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 6d2be83669 69/84: chore: package-lint fixes, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 41ccea4ebe 64/84: refactor: Remove unnecessary tomelr-encode-keyword, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 406f4922a8 58/84: test: Add tests for json.el functions used in tomelr, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr b3b6a28d15 68/84: doc: Add more examples, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr f9d670e165 56/84: refactor: Clean up unused code, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 511240765b 71/84: chore: Ignore .elc files, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr ed13b73e9b 74/84: feat: Support string keys, ELPA Syncer, 2022/05/03