[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/tomelr 96c890a68b 23/84: feat: Convert Lisp lists to TO
From: |
ELPA Syncer |
Subject: |
[elpa] externals/tomelr 96c890a68b 23/84: feat: Convert Lisp lists to TOML arrays |
Date: |
Tue, 3 May 2022 09:58:09 -0400 (EDT) |
branch: externals/tomelr
commit 96c890a68b9a587283bc7522c3893370cc522ca6
Author: Kaushal Modi <kaushal.modi@gmail.com>
Commit: Kaushal Modi <kaushal.modi@gmail.com>
feat: Convert Lisp lists to TOML arrays
---
README.org | 34 ++++++++++++++++------------------
test/all-tests.el | 1 +
test/{all-tests.el => tarray.el} | 28 +++++++++++++++++++++++-----
tomelr.el | 17 ++++-------------
4 files changed, 44 insertions(+), 36 deletions(-)
diff --git a/README.org b/README.org
index c21b8a72e9..948d37fdaa 100644
--- a/README.org
+++ b/README.org
@@ -18,7 +18,7 @@ the Emacs core library
[[https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/j
It will then be gradually refactored so that it meets the
specification defined below.
-* Library Completion Status [2/7]
+* Library Completion Status [3/7]
- [X] Scalar
- [X] Boolean
- [X] Integer
@@ -27,7 +27,7 @@ specification defined below.
- [X] Date
- [X] Date + Time with Offset
- [X] Nil
-- [ ] Arrays
+- [X] Arrays
- [ ] Array of Arrays
- [ ] Tables
- [ ] Array of Tables
@@ -280,29 +280,33 @@ key5 = true
: }
** TOML Arrays: Lists
https://toml.io/en/v1.0.0#array
-*** Lists
+*** DONE Plain Arrays
+CLOSED: [2022-04-29 Fri 00:25]
**** S-expression
-#+begin_src emacs-lisp :eval no :noweb-ref lists
+#+begin_src emacs-lisp :eval no :noweb-ref arrays
'((integers . (1 2 3))
(integers2 . [1 2 3]) ;Same as above
(colors . ("red" "yellow" "green"))
- (string_array . ("all" "strings" "are the same" "type"))
+ ;; Mixed-type arrays are allowed
(numbers . (0.1 0.2 0.5 1 2 5)))
#+end_src
**** TOML
+#+begin_src emacs-lisp :noweb yes :exports results :wrap src toml
+(tomelr-encode
+ <<arrays>>)
+#+end_src
+
+#+RESULTS:
#+begin_src toml
integers = [ 1, 2, 3 ]
integers2 = [ 1, 2, 3 ]
colors = [ "red", "yellow", "green" ]
-string_array = [ "all", 'strings', """are the same""", '''type''' ]
-
-# Mixed-type arrays are allowed
numbers = [ 0.1, 0.2, 0.5, 1, 2, 5 ]
#+end_src
**** JSON Reference
#+begin_src emacs-lisp :noweb yes :exports results
(json-encode-pretty
- <<lists>>)
+ <<arrays>>)
#+end_src
#+RESULTS:
@@ -323,12 +327,6 @@ numbers = [ 0.1, 0.2, 0.5, 1, 2, 5 ]
"yellow",
"green"
],
- "string_array": [
- "all",
- "strings",
- "are the same",
- "type"
- ],
"numbers": [
0.1,
0.2,
@@ -339,9 +337,9 @@ numbers = [ 0.1, 0.2, 0.5, 1, 2, 5 ]
]
}
#+end_example
-*** Lists of lists
+*** Array of Arrays
**** S-expression
-#+begin_src emacs-lisp :eval no :noweb-ref lists-of-lists
+#+begin_src emacs-lisp :eval no :noweb-ref array-of-arrays
'((nested_arrays_of_ints . [(1 2) (3 4 5)])
(nested_mixed_array . [(1 2) ("a" "b" "c")])
(contributors . ("Foo Bar <foo@example.com>"
@@ -363,7 +361,7 @@ contributors = [
**** JSON Reference
#+begin_src emacs-lisp :noweb yes :exports results
(json-encode-pretty
- <<lists-of-lists>>)
+ <<array-of-arrays>>)
#+end_src
#+RESULTS:
diff --git a/test/all-tests.el b/test/all-tests.el
index 5b1013864c..f89407594b 100644
--- a/test/all-tests.el
+++ b/test/all-tests.el
@@ -23,3 +23,4 @@
(require 'tscalar)
(require 'tnil)
+(require 'tarray)
diff --git a/test/all-tests.el b/test/tarray.el
similarity index 51%
copy from test/all-tests.el
copy to test/tarray.el
index 5b1013864c..1c92e55c8c 100644
--- a/test/all-tests.el
+++ b/test/tarray.el
@@ -1,4 +1,4 @@
-;;; all-tests.el --- Tests for tomelr.el -*-
lexical-binding: t; -*-
+;; -*- lexical-binding: t; -*-
;; Authors: Kaushal Modi <kaushal.modi@gmail.com>
@@ -17,9 +17,27 @@
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
-;;; Code:
+;;; Commentary:
-(setq load-prefer-newer t)
+;; Test conversion to TOML arrays.
-(require 'tscalar)
-(require 'tnil)
+;;; Code:
+(require 'tomelr)
+
+;;;; Key with array value
+(ert-deftest test-array ()
+ (let ((inp '(((integers . (1 2 3)))
+ ((integers2 . [1 2 3])) ;Same as above
+ ((colors . ("red" "yellow" "green")))
+ ((numbers . (0.1 0.2 0.5 1 2 5))))) ;Mixed-type arrays are
allowed
+ (ref '("integers = [ 1, 2, 3 ]"
+ "integers2 = [ 1, 2, 3 ]"
+ "colors = [ \"red\", \"yellow\", \"green\" ]"
+ "numbers = [ 0.1, 0.2, 0.5, 1, 2, 5 ]"))
+ out)
+ (dolist (el inp)
+ (push (tomelr-encode el) out))
+ (should (equal ref (nreverse out)))))
+
+
+(provide 'tarray)
diff --git a/tomelr.el b/tomelr.el
index cd7ff6b901..8952f920a9 100644
--- a/tomelr.el
+++ b/tomelr.el
@@ -37,11 +37,6 @@
"String used for a single indentation level during encoding.
This value is repeated for each further nested element.")
-(defvar tomelr-encoding-lisp-style-closings nil
- "If non-nil, delimiters ] and } will be formatted Lisp-style.
-This means they will be placed on the same line as the last
-element of the respective array or object, without indentation.")
-
(defvar tomelr-encoding-object-sort-predicate nil
"Sorting predicate for TOML object keys during encoding.
If nil, no sorting is performed. Else, TOML object keys are
@@ -281,21 +276,17 @@ non-nil. Sorting can optionally be DESTRUCTIVE for
speed."
;;;; Arrays
(defun tomelr--print-array (array)
"Like `tomelr-encode-array', but insert the TOML at point."
- (insert ?\[)
+ (insert "[ ")
(unless (length= array 0)
(tomelr--with-indentation
- (tomelr--print-indentation)
(let ((first t))
(mapc (lambda (elt)
(if first
(setq first nil)
- (insert ",")
- (tomelr--print-indentation))
+ (insert ", "))
(tomelr--print elt))
- array)))
- (or tomelr-encoding-lisp-style-closings
- (tomelr--print-indentation)))
- (insert ?\]))
+ array))))
+ (insert " ]"))
(defun tomelr-encode-array (array)
"Return a TOML representation of ARRAY.
- [elpa] externals/tomelr d96a3b235b 04/84: doc: Add LOGBOOK drawer example, (continued)
- [elpa] externals/tomelr d96a3b235b 04/84: doc: Add LOGBOOK drawer example, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 05d2cafcd9 09/84: test: Add test for boolean scalar key-value pairs, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 2ea3b5e032 03/84: fix!: Set boolean false using :false value, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 28642f2e78 05/84: fix: dates will be strings in Lisp, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 52dc93201d 08/84: feat: First cut -- Port json-encode from json.el to tomelr-encode, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 7cd15e79b8 10/84: tool(ci): Add GHA setup, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr c872e9efc1 17/84: test: Add test for integer scalar key-value pairs, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr a1f434f03a 31/84: feat: Support nested TOML tables, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 6bbe740e52 28/84: test: Test that 'false is also considered as boolean false in TOML, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 9c91e0dc07 18/84: test: Add test for float scalar key-value pairs, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 96c890a68b 23/84: feat: Convert Lisp lists to TOML arrays,
ELPA Syncer <=
- [elpa] externals/tomelr bb85106ee9 27/84: doc: Add spec for nested tables and arrays of tables, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 1d65064ffa 20/84: feat: Recognize local date format YYYY-MM-DD, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 2810504e84 32/84: feat: Add basic support for S-exp plists -> TOML conversion, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 0f4e7b4f2c 47/84: fix: Better detection of nested TTA, but still wip, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr cff1f8aa89 38/84: fix: Support TOML tables arrays specified as plist vector, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 4c419bcee2 37/84: fix: Support TOML tables specified as plists, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr baf81228bc 45/84: fix: Correct the spec for nested array of tables, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 4dda8e6be3 46/84: chore: Style edits in a test, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 5959b90ffa 44/84: fix: Don't let TOML tables be recognized as TOML tables arrays, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr b64eb07e99 49/84: fix: Detect TT with sub-tables correctly, ELPA Syncer, 2022/05/03