emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/yaml d8ac09e8ca 053/124: Merge pull request #11 from zk


From: ELPA Syncer
Subject: [elpa] externals/yaml d8ac09e8ca 053/124: Merge pull request #11 from zkry/fix-encoding-nil-false-arrays
Date: Fri, 29 Nov 2024 16:00:00 -0500 (EST)

branch: externals/yaml
commit d8ac09e8cad7f67339e19c53e77da1cd0ff98d36
Merge: a45f60c999 64c117d084
Author: Zachary Romero <zacromero@posteo.net>
Commit: GitHub <noreply@github.com>

    Merge pull request #11 from zkry/fix-encoding-nil-false-arrays
    
    Fix encoding issues for nil, false, and arrays
---
 yaml-tests.el | 22 +++++++++++++++++++++-
 yaml.el       | 18 ++++++++++++++++--
 2 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/yaml-tests.el b/yaml-tests.el
index 67e0805b90..aee8f78246 100644
--- a/yaml-tests.el
+++ b/yaml-tests.el
@@ -512,11 +512,31 @@ keep: |+
               ("nested-map" . ((1 . 2) (3 . 4) (5 . 6)))
               ("nested-list" . (1 2 3 4 5)))
              ("nested" "list" 1 2 3))))
+  (should (yaml-test-round-trip
+           '("one" t nil :false)))
   (should (yaml-test-round-trip
            '(t nil)))
+  (should (yaml-test-round-trip
+           [1 2 3 4]))
   (should (yaml-encode
            '((("aaaa" "bbbb" "cccc") ("dddd" "eeee" "ffff") ("gggg" "hhhh" 
"iiii"))
-             ("jjjj" "kkkk" "llll") ("mmmm" "nnnn" "oooo") ("pppp" "qqqq" 
"rrrr")))))
+             ("jjjj" "kkkk" "llll") ("mmmm" "nnnn" "oooo") ("pppp" "qqqq" 
"rrrr"))))
+  (should (yaml-encode
+           '(("aaaa" "bbbb" "cccc" ("dddd" "eeee" "ffff") ("gggg" "hhhh" 
"iiii"))
+             ("jjjj" "kkkk" "llll") ("mmmm" "nnnn" "oooo") ("pppp" "qqqq" 
"rrrr"))))
+
+  (should (equal
+           (yaml-encode :null)
+           "null"))
+  (should (equal
+           (yaml-encode :false)
+           "false"))
+  (should (equal
+           (yaml-encode nil)
+           "null"))
+  (should (equal
+           (yaml-encode [1 2 3])
+           "[1, 2, 3]")))
 
 (provide 'yaml-tests)
 
diff --git a/yaml.el b/yaml.el
index aa9c812f75..a858a82d76 100644
--- a/yaml.el
+++ b/yaml.el
@@ -2371,6 +2371,7 @@ without first inserting a newline."
    ((yaml--scalarp object) (yaml--encode-scalar object))
    ((hash-table-p object) (yaml--encode-hash-table object indent auto-indent))
    ((listp object) (yaml--encode-list object indent auto-indent))
+   ((arrayp object) (yaml--encode-array object indent auto-indent))
    (t (error "Unknown object %s" object))))
 
 (defun yaml--scalarp (object)
@@ -2389,14 +2390,27 @@ without first inserting a newline."
          (s (replace-regexp-in-string "\"" "\\\\\"" s)))
     s))
 
+(defun yaml--encode-array (a indent &optional auto-indent)
+  "Encode array A to a string in the context of being INDENT deep.
+
+If AUTO-INDENT is non-nil, start the list on the current line,
+auto-detecting the indentation.  Functionality defers to
+`yaml--encode-list'."
+  (yaml--encode-list (seq-map #'identity a)
+                      indent
+                      auto-indent))
 
 
 (defun yaml--encode-scalar (s)
   "Encode scalar S to buffer."
   (cond
-   ((not s) (insert "nil"))
+   ((not s) (insert "null"))
    ((eql t s) (insert "true"))
-   ((symbolp s) (insert (symbol-name s)))
+   ((symbolp s)
+    (cond
+     ((eql s :null) (insert "null"))
+     ((eql s :false) (insert "false"))
+     (t (insert t))))
    ((numberp s) (insert (number-to-string s)))
    ((stringp s)
     (if (string-match "\\`[-_a-zA-Z0-9]+\\'" s)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]