[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/tomelr ed13b73e9b 74/84: feat: Support string keys
From: |
ELPA Syncer |
Subject: |
[elpa] externals/tomelr ed13b73e9b 74/84: feat: Support string keys |
Date: |
Tue, 3 May 2022 09:58:15 -0400 (EDT) |
branch: externals/tomelr
commit ed13b73e9b68ac2c51f3545ac337bbfeba063a42
Author: Kaushal Modi <kaushal.modi@gmail.com>
Commit: Kaushal Modi <kaushal.modi@gmail.com>
feat: Support string keys
---
README.org | 14 ++++++++++++-
test/all-tests.el | 1 +
test/tinternal.el | 8 ++++++--
test/tkey.el | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
test/ttable.el | 33 +++++++++++++++++++++++++++++++
tomelr.el | 10 +++++++++-
6 files changed, 121 insertions(+), 4 deletions(-)
diff --git a/README.org b/README.org
index 3bf0b13e59..8afb94fad9 100644
--- a/README.org
+++ b/README.org
@@ -590,7 +590,9 @@ CLOSED: [2022-04-29 Fri 14:30]
'((table-1 . ((table-1a . ((key1 . "some string")
(key2 . 123)))
(table-1b . ((key1 . "foo")
- (key2 . 98765))))))
+ (key2 . 98765)))))
+ (menu . (("auto weight" . ((weight . 4033)
+ (identifier . "foo"))))))
#+end_src
**** TOML
#+begin_src emacs-lisp :noweb yes :exports results :wrap src toml
@@ -607,6 +609,10 @@ CLOSED: [2022-04-29 Fri 14:30]
[table-1.table-1b]
key1 = "foo"
key2 = 98765
+[menu]
+ [menu."auto weight"]
+ weight = 4033
+ identifier = "foo"
#+end_src
**** JSON Reference
#+begin_src emacs-lisp :noweb yes :exports results
@@ -626,6 +632,12 @@ CLOSED: [2022-04-29 Fri 14:30]
"key1": "foo",
"key2": 98765
}
+ },
+ "menu": {
+ "auto weight": {
+ "weight": 4033,
+ "identifier": "foo"
+ }
}
}
#+end_example
diff --git a/test/all-tests.el b/test/all-tests.el
index adab51f609..c25fd78e48 100644
--- a/test/all-tests.el
+++ b/test/all-tests.el
@@ -24,6 +24,7 @@
(require 'tjson-utils)
(require 'tinternal)
+(require 'tkey)
(require 'tscalar)
(require 'tnil)
(require 'tarray)
diff --git a/test/tinternal.el b/test/tinternal.el
index 3aa23cb06f..2a51a0b6b2 100644
--- a/test/tinternal.el
+++ b/test/tinternal.el
@@ -30,8 +30,12 @@
((a . 1) (b . 2))
;; Nested TT
((a . 1)
- (b . ((c . 3)
- (d . 4))))
+ (b . ((c . ((d . 3)
+ (e . 4))))))
+ ;; Nested TT with string key
+ ((a . 1)
+ (b . (("some key" . ((d . 3)
+ (e . 4))))))
;; Nested TTA
((a . 1)
(b . (((c . 3))
diff --git a/test/tkey.el b/test/tkey.el
new file mode 100644
index 0000000000..de3453d098
--- /dev/null
+++ b/test/tkey.el
@@ -0,0 +1,59 @@
+;; -*- lexical-binding: t; -*-
+
+;; Authors: Kaushal Modi <kaushal.modi@gmail.com>
+
+;; This file is not part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Test conversion to TOML keys.
+
+;;; Code:
+(require 'tomelr)
+
+;;;; Scalar - Boolean
+(ert-deftest test-key-with-space ()
+ (let ((inp '(
+ (("some key" . t))
+ ))
+ (ref '(
+ "\"some key\" = true"
+ ))
+ out)
+ (dolist (el inp)
+ (push (tomelr-encode el) out))
+ (should (equal ref (nreverse out)))))
+
+(ert-deftest test-table-name-with-space ()
+ (let ((inp '(
+ ((menu .
+ (("auto weight" .
+ ((weight . 4033)
+ (identifier . "foo"))))))
+ ))
+ (ref '(
+ "[menu]
+ [menu.\"auto weight\"]
+ weight = 4033
+ identifier = \"foo\""
+ ))
+ out)
+ (dolist (el inp)
+ (push (tomelr-encode el) out))
+ (should (equal ref (nreverse out)))))
+
+
+(provide 'tkey)
diff --git a/test/ttable.el b/test/ttable.el
index c84fc0bf60..d1e70b19a5 100644
--- a/test/ttable.el
+++ b/test/ttable.el
@@ -81,5 +81,38 @@
(push (tomelr-encode el) out))
(should (equal ref (nreverse out)))))
+(ert-deftest test-nested-table-string-keys ()
+ (let ((inp '(
+ ((table-1 . (("some key" . ((key1 . "some string")
+ (key2 . 123))))))
+ ((table-1 . ((table-1a . ((key1 . "some string")
+ (key2 . 123)))
+ (table-1b . ((key1 . "foo")
+ (key2 . 98765)))))
+ (menu . (("auto weight" . ((weight . 4033)
+ (identifier . "foo"))))))
+ ))
+ (ref '(
+ "[table-1]
+ [table-1.\"some key\"]
+ key1 = \"some string\"
+ key2 = 123"
+ "[table-1]
+ [table-1.table-1a]
+ key1 = \"some string\"
+ key2 = 123
+ [table-1.table-1b]
+ key1 = \"foo\"
+ key2 = 98765
+[menu]
+ [menu.\"auto weight\"]
+ weight = 4033
+ identifier = \"foo\""
+ ))
+ out)
+ (dolist (el inp)
+ (push (tomelr-encode el) out))
+ (should (equal ref (nreverse out)))))
+
(provide 'ttable)
diff --git a/tomelr.el b/tomelr.el
index ad7906e338..c9a0694ced 100644
--- a/tomelr.el
+++ b/tomelr.el
@@ -131,6 +131,7 @@ set to `keyword'.
Return the same STRING passed as input."
;; (message "[tomelr--print-string DBG] string = `%s'" string)
+ (setq string (string-trim string "\"" "\""))
(let ((special-chars '((?b . ?\b) ;U+0008
(?f . ?\f) ;U+000C
(?\\ . ?\\)))
@@ -181,7 +182,14 @@ Possible value of TYPE are `table', `table-array' or nil.
Return nil if OBJECT cannot be encoded as a TOML string."
(let ((sym-name (cond ((stringp object)
- object)
+ ;; https://toml.io/en/v1.0.0#keys
+ ;; Bare keys may only contain ASCII letters, ASCII
digits,
+ ;; underscores, and dashes (A-Za-z0-9_-).
+ (if (string-match-p "\\`[A-Za-z0-9_-]+\\'" object)
+ object
+ ;; Wrap string in double-quotes if it
+ ;; doesn't contain only A-Za-z0-9_- chars.
+ (format "\"%s\"" object)))
;; Symbol beginning with `:', like `:some_key'
((keywordp object)
(string-trim-left (symbol-name object) ":"))
- [elpa] externals/tomelr a7b3a57037 48/84: feat: Make a very basic nested array of TTA work, (continued)
- [elpa] externals/tomelr a7b3a57037 48/84: feat: Make a very basic nested array of TTA work, ELPA Syncer, 2022/05/03
- [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 <=
- [elpa] externals/tomelr de661716af 72/84: style: Remove space from after and before [ and ] brackets, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 334b7cba54 76/84: refactor: Don't attempt to triple-quote TOML keys, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr c2d1328c44 80/84: fix: Boolean coercing when value is a symbol true or false, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr ebe5959174 75/84: feat: Auto-coerce string to boolean, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr a676192b43 81/84: fix: Integer coercing of a number strings with underscores, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 8da825067b 15/84: chore(readme): Update, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 65653d53ee 30/84: chore(doc): M-x checkdoc fixes, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr bcaea16ec0 39/84: chore(doc): Clean up old code block, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 45542fb234 67/84: chore: Bump version, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 7c004af90d 66/84: style: Remove unnecessary tomelr-encode-* functions, ELPA Syncer, 2022/05/03