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

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

[elpa] externals/yaml ed9dded709 027/124: Fix l+block-mapping auto-detec


From: ELPA Syncer
Subject: [elpa] externals/yaml ed9dded709 027/124: Fix l+block-mapping auto-detect-indent bug
Date: Fri, 29 Nov 2024 15:59:56 -0500 (EST)

branch: externals/yaml
commit ed9dded709f4a345db296a6e5de09fd72e4e5af3
Author: Zachary Romero <zacromero@posteo.net>
Commit: Zachary Romero <zacromero@posteo.net>

    Fix l+block-mapping auto-detect-indent bug
---
 yaml-tests.el | 309 +++++++++++-----------------------------------------------
 yaml.el       |  14 +--
 2 files changed, 65 insertions(+), 258 deletions(-)

diff --git a/yaml-tests.el b/yaml-tests.el
index 15793dd9cb..ab232ac244 100644
--- a/yaml-tests.el
+++ b/yaml-tests.el
@@ -5,253 +5,6 @@
 (require 'yaml)
 (require 'ert)
 
-(ert-deftest yaml-parsing-functions-characters ()
-  "Tests the auto-generated parsing "
-  ;; 5.1. Character Set
-  (should (yaml-parse "\u0009"
-            (yaml-c-printable)))
-  (should (yaml-parse "\u000A"
-            (yaml-c-printable)))
-  (should (yaml-parse "\u000A"
-            (yaml-c-printable)))
-  (should (not (yaml-parse "\u000B"
-                 (yaml-c-printable))))
-  (should (yaml-parse "\u0020"
-            (yaml-c-printable)))
-  (should (yaml-parse "\u0085"
-            (yaml-c-printable)))
-  (should (yaml-parse "\uE000"
-            (yaml-c-printable)))
-  (should (yaml-parse "\u10FFFF"
-            (yaml-c-printable)))
-  (should (yaml-parse "\u0009"
-            (yaml-nb-json)))
-  (should (yaml-parse "\u0009"
-            (yaml-nb-json)))
-  (should (yaml-parse "\u0020"
-            (yaml-nb-json)))
-  (should (yaml-parse "\uAAAAAA"
-            (yaml-nb-json)))
-  ;; 5.2. Character Encodings
-  (should (yaml-parse "\uFEFF"
-            (yaml-c-byte-order-mark)))
-  ;; 5.3. Indicator Characters
-  (should (yaml-parse "-"
-            (yaml-c-sequence-entry)))
-  (should (yaml-parse "?"
-            (yaml-c-mapping-key)))
-  (should (yaml-parse ":"
-            (yaml-c-mapping-value)))
-  (should (yaml-parse ","
-            (yaml-c-collect-entry)))
-  (should (yaml-parse "["
-            (yaml-c-sequence-start)))
-  (should (yaml-parse "]"
-            (yaml-c-sequence-end)))
-  (should (yaml-parse "{"
-            (yaml-c-mapping-start)))
-  (should (yaml-parse "}"
-            (yaml-c-mapping-end)))
-  (should (yaml-parse "#"
-            (yaml-c-comment)))
-  (should (yaml-parse "&"
-            (yaml-c-anchor)))
-  (should (yaml-parse "*"
-            (yaml-c-alias)))
-  (should (yaml-parse "!"
-            (yaml-c-tag)))
-  (should (yaml-parse "|"
-            (yaml-c-literal)))
-  (should (yaml-parse ">"
-            (yaml-c-folded)))
-  (should (yaml-parse "'"
-            (yaml-c-single-quote)))
-  (should (yaml-parse "\""
-            (yaml-c-double-quote)))
-  (should (yaml-parse "%"
-            (yaml-c-directive)))
-  (should (yaml-parse "@"
-            (yaml-c-reserved)))
-  (should (yaml-parse "`'"
-            (yaml-c-reserved)))
-  (should (yaml-parse "-"
-            (yaml-c-indicator)))
-  (should (yaml-parse "?"
-            (yaml-c-indicator)))
-  (should (yaml-parse ":"
-            (yaml-c-indicator)))
-  (should (yaml-parse ","
-            (yaml-c-indicator)))
-  (should (yaml-parse "|"
-            (yaml-c-indicator)))
-  (should (yaml-parse "%"
-            (yaml-c-indicator)))
-  (should (yaml-parse ","
-            (yaml-c-flow-indicator)))
-  (should (yaml-parse "["
-            (yaml-c-flow-indicator)))
-  (should (yaml-parse "]"
-            (yaml-c-flow-indicator)))
-  (should (yaml-parse "}"
-            (yaml-c-flow-indicator)))
-
-  ;; 5.4. Line Break Characters
-  (should (yaml-parse "\u000A"
-            (yaml-b-line-feed)))
-  (should (yaml-parse "\u000D"
-            (yaml-b-carriage-return)))
-  (should (yaml-parse "\u000A"
-            (yaml-b-char)))
-  (should (yaml-parse "a"
-            (yaml-nb-char)))
-  (should (not (yaml-parse "\u000A"
-                 (yaml-nb-char))))
-  (should (not (yaml-parse "\u000D"
-                 (yaml-nb-char))))
-
-  (should (yaml-parse "\u000A"
-            (yaml-b-break)))
-  (should (yaml-parse "\u000D\u000A"
-            (yaml-b-break)))
-  (should (yaml-parse "\u000D"
-            (yaml-b-break)))
-  (should (yaml-parse "\u000D"
-            (yaml-b-as-line-feed)))
-  (should (yaml-parse "\u000A"
-            (yaml-b-non-content)))
-
-  ;; 5.5. White Space Characters
-  (should (yaml-parse " "
-            (yaml-s-space)))
-  (should (yaml-parse "\t"
-            (yaml-s-tab)))
-  (should (yaml-parse " "
-            (yaml-s-white)))
-  (should (yaml-parse "\t"
-            (yaml-s-white)))
-  (should (yaml-parse "x"
-            (yaml-ns-char)))
-  (should (not (yaml-parse ""
-                 (yaml-ns-char))))
-
-  ;; 5.6. Miscellaneous Characters
-  (should (yaml-parse "0"
-            (yaml-ns-dec-digit)))
-  (should (yaml-parse "1"
-            (yaml-ns-dec-digit)))
-  (should (yaml-parse "4"
-            (yaml-ns-dec-digit)))
-  (should (yaml-parse "9"
-            (yaml-ns-dec-digit)))
-  (should (yaml-parse "A"
-            (yaml-ns-hex-digit)))
-  (should (yaml-parse "F"
-            (yaml-ns-hex-digit)))
-  (should (not (yaml-parse "G"
-                 (yaml-ns-hex-digit))))
-  (should (yaml-parse "a"
-            (yaml-ns-hex-digit)))
-  (should (yaml-parse "f"
-            (yaml-ns-hex-digit)))
-  (should (yaml-parse "a"
-            (yaml-ns-ascii-letter)))
-  (should (yaml-parse "z"
-            (yaml-ns-ascii-letter)))
-  (should (yaml-parse "-"
-            (yaml-ns-word-char)))
-  (should (yaml-parse "#"
-            (yaml-ns-uri-char)))
-  (should (yaml-parse "A"
-            (yaml-ns-uri-char)))
-  (should (yaml-parse "_"
-            (yaml-ns-uri-char)))
-  (should (yaml-parse ";"
-            (yaml-ns-uri-char)))
-  (should (yaml-parse "a"
-            (yaml-ns-tag-char)))
-  ;; 5.7. Escaped Characters
-  (should (yaml-parse "\\"
-            (yaml-c-escape)))
-
-  (should (yaml-parse "n"
-            (yaml-ns-esc-line-feed)
-            ))
-  (should (yaml-parse "\\n"
-            (yaml-c-ns-esc-char))))
-
-(ert-deftest yaml-parsing-functions-basic-structure ()
-  "Tests the auto-generated parsing"
-  (should (yaml-parse "    "
-            (yaml-s-indent 4)))
-  (should (yaml-parse " "
-            (yaml-s-indent 1)))
-  ;; (should (yaml-parse " " (yaml-s-indent-lt 1)))
-  ;; (should (yaml-parse " " (yaml-s-indent-le 1)))
-  (should (yaml-parse "    "
-            (yaml-s-separate-in-line)))
-  (should (yaml-parse "  "
-            (yaml-s-block-line-prefix 2)))
-  (should (yaml-parse "  "
-            (yaml-s-block-line-prefix 2)))
-  (should (yaml-parse "  "
-            (yaml-s-flow-line-prefix 2)))
-  (should (yaml-parse "  \n"
-            (yaml-l-empty 2 "block-in")))
-  (should (yaml-parse "\n  \n \n\n"
-                      (yaml-b-l-trimmed 2 "block-in")))
-  (should (yaml-parse "\n"
-                      (yaml-b-as-space)))
-  (should (yaml-parse "\n  "
-                      (yaml-s-flow-folded 1)))
-
-  ;; 6.6. Comments
-  (should (yaml-parse "# Comment"
-                      (yaml-c-nb-comment-text)))
-  (should (yaml-parse "\n"
-                      (yaml-b-comment)))
-  (should (yaml-parse "    # Comment\n"
-                      (yaml-s-b-comment)))
-  (should (yaml-parse "  # Comment\n   \n\n"
-                      (yaml-l-comment)))
-  (should (yaml-parse "    # Comment\n          # Lines\n"
-                      (yaml-s-l-comments)))
-
-  ;; 6.7. Separation Lines
-  (should (yaml-parse "\n# Statistics:\n  "
-                      (yaml-s-separate-lines 2)))
-
-  ;; 6.8. Directives
-  (should (yaml-parse "FOO  bar baz"
-                      (yaml-ns-reserved-directive)))
-  (should (yaml-parse "%FOO  bar baz # Should be ignored"
-                      (yaml-l-directive)))
-
-  ;; 6.8.1. YAML Directives
-  (should (yaml-parse "1.3"
-                      (yaml-ns-yaml-version)))
-  (should (yaml-parse "YAML 1.3"
-                      (yaml-ns-yaml-directive)))
-
-  ;; 6.8.3. TAG Directives
-  (should (yaml-parse "TAG !yaml! tag:yaml.org,2002:"
-                      (yaml-ns-tag-directive)))
-
-  (should (yaml-parse "!e!"
-                      (yaml-c-named-tag-handle)))
-
-  ;;6.9. Node Properties
-  (should (yaml-parse "&a2"
-                      (yaml-c-ns-anchor-property)))
-
-  (should (yaml-parse "!<tag:yaml.org,2002:str>"
-                      (yaml-c-verbatim-tag)))
-  (should (yaml-parse "!local"
-                      (yaml-c-ns-shorthand-tag)))
-
-  (should (yaml-parse "&anchor"
-            (yaml-c-ns-anchor-property))))
-
-
 (defun yaml--hash-table-equal (h1 h2)
   (when (or (not (hash-table-p h1))
             (not (hash-table-p h2)))
@@ -325,13 +78,13 @@
   (should (equal (yaml-parse-string "value")
                  "value"))
   (should (equal (yaml-parse-string "[abc, def, ghi]")
-                 '("abc" "def" "ghi")))
+                 ["abc" "def" "ghi"]))
   (should (equal (yaml-parse-string "- abc\n- def\n- ghi")
-                 '("abc" "def" "ghi")))
+                 ["abc" "def" "ghi"]))
   (should (equal (yaml-parse-string "- abc\n- def\n- ghi")
-                 '("abc" "def" "ghi")))
+                 ["abc" "def" "ghi"]))
   (should (equal (yaml-parse-string "- [abc, def, ghi]\n- [jkl, mno, pqr]\n- 
[stu, vwx, yz]")
-                 '(("abc" "def" "ghi") ("jkl" "mno" "pqr") ("stu" "vwx" 
"yz"))))
+                 [["abc" "def" "ghi"] ["jkl" "mno" "pqr"] ["stu" "vwx" "yz"]]))
   (should (equal (yaml-parse-string "a")
                  "a"))
   (should (equal (yaml-parse-string "\"a\"")
@@ -373,7 +126,59 @@
 
 # Comment")
 
-                 "\nfolded line\nnext line\n  * bullet\n\n  * list\n  * 
lines\n\nlast line\n")))
+                 "\nfolded line\nnext line\n  * bullet\n\n  * list\n  * 
lines\n\nlast line\n"))
+  (should (equal (yaml-parse-string "- # Empty
+- abc")
+                 [:null "abc"]))
+  (should (equal (yaml-parse-string "block sequence:
+  - one
+  - two : three
+" :object-type 'alist)
+                 '(("block sequence" . ["one" (("two" . "three"))]))))
+
+  ;; Example 8.15. Block Sequence Entry Types
+  (should (equal (yaml-parse-string "- # Empty
+- |
+ block node
+- - one # Compact
+  - two # sequence
+- one: two # Compact mapping" :object-type 'alist)
+                 [:null "block node\n" ["one" "two"] (("one" . "two"))]))
+
+  ;; Example 8.16. Block mapping
+  (should (equal (yaml-parse-string "block mapping:
+ key: value
+" :object-type 'alist)
+                 '(("block mapping" . (("key" . "value"))))))
+
+
+  ;; Example 8.17. Explicit Block Mapping Entries
+  (should (equal (yaml-parse-string "? explicit key # Empty value
+? |
+  block key
+: - one # Explicit compact
+  - two # block value
+" :object-type 'alist)
+                 '(("explicit key" . :null)
+                   ("block key\n" . ["one" "two"]))))
+
+  ;; Example 8.18. Implicit Block Mapping Entries
+  (should (equal (yaml-parse-string "plain key: in-line value
+: # Both empty
+\"quoted key\":
+- entry
+" :object-type 'alist)
+                 '(("plain key" . "in-line value")
+                   (:null . :null)
+                   ("quoted key" . ["entry"]))))
+
+
+  ;; Example 8.19. Compact Block Mappings
+  (should (equal (yaml-parse-string "- sun: yellow
+- ? earth: blue
+  : moon: white
+" :object-type 'alist)
+                 [(("sun" . "yellow")) (((("earth" . "blue")) . (("moon" . 
"white"))))])))
 
 (ert-deftest yaml-parsing-completes ()
   "Tests that the yaml parses."
diff --git a/yaml.el b/yaml.el
index cdef905dfb..1c1f221b0f 100644
--- a/yaml.el
+++ b/yaml.el
@@ -1654,12 +1654,14 @@ Rules for this function are defined by the yaml-spec 
JSON file."
    ((eq state 'l+block-mapping)
     (yaml--frame "l+block-mapping"
       (let ((new-m (yaml--auto-detect-indent (nth 0 args))))
-        (yaml--all (yaml--set m new-m)
-                   (yaml--rep 1 nil
-                              (lambda ()
-                                (yaml--all
-                                 (yaml--parse-from-grammar 's-indent (+ (nth 0 
args) new-m))
-                                 (yaml--parse-from-grammar 
'ns-l-block-map-entry (+ (nth 0 args) new-m)))))))))
+        (if (= 0 new-m)
+            nil ;; For some fixed auto-detected m > 0
+          (yaml--all (yaml--set m new-m)
+                     (yaml--rep 1 nil
+                                (lambda ()
+                                  (yaml--all
+                                   (yaml--parse-from-grammar 's-indent (+ (nth 
0 args) new-m))
+                                   (yaml--parse-from-grammar 
'ns-l-block-map-entry (+ (nth 0 args) new-m))))))))))
 
    ((eq state 'c-ns-flow-map-adjacent-value) (let ((n (nth 0 args)) (c (nth 1 
args))) (yaml--frame "c-ns-flow-map-adjacent-value" (yaml--all (yaml--chr ?\:) 
(yaml--any (yaml--all (yaml--rep 0 1 (lambda () (yaml--parse-from-grammar 
's-separate n c))) (yaml--parse-from-grammar 'ns-flow-node n c)) 
(yaml--parse-from-grammar 'e-node))))))
    ((eq state 's-single-next-line) (let ((n (nth 0 args))) (yaml--frame 
"s-single-next-line" (yaml--all (yaml--parse-from-grammar 's-flow-folded n) 
(yaml--rep 0 1 (lambda () (yaml--all (yaml--parse-from-grammar 'ns-single-char) 
(yaml--parse-from-grammar 'nb-ns-single-in-line) (yaml--any 
(yaml--parse-from-grammar 's-single-next-line n) (yaml--rep2 0 nil (lambda () 
(yaml--parse-from-grammar 's-white)))))))))))



reply via email to

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