branch: externals/yaml commit 276596561ad7cb990dd941d11521a9cb8e5a5346 Author: Zachary Romero <zacrom...@posteo.net> Commit: Zachary Romero <zacrom...@posteo.net>
Fix explicit document end on ns-plain --- yaml-tests.el | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- yaml.el | 13 ++++++++++--- 2 files changed, 71 insertions(+), 4 deletions(-) diff --git a/yaml-tests.el b/yaml-tests.el index d38a665b16..e409168d6f 100644 --- a/yaml-tests.el +++ b/yaml-tests.el @@ -181,7 +181,67 @@ - ? earth: blue : moon: white " :object-type 'alist) - [(("sun" . "yellow")) (((("earth" . "blue")) . (("moon" . "white"))))]))) + [(("sun" . "yellow")) (((("earth" . "blue")) . (("moon" . "white"))))])) + + ;; Example 8.20. Block Node Types + (should (equal (yaml-parse-string "- + \"flow in block\" +- > + Block scalar +- !!map # Block collection + foo : bar +" :object-type 'alist) + ["flow in block" "Block scalar\n" (("foo" . "bar"))])) + + ;; Example 8.21. Block Scalar Nodes + ;; TODO: The document has no new line after the literal and folded + ;; but since it is using default chomp, I think there should be one new line. + ;; Which one is right? + (should (equal (yaml-parse-string "literal: |2 + value +folded: + !foo + >1 + value" :object-type 'alist) + '(("literal" . "value\n") ("folded" . "value\n")))) + + (should (equal (yaml-parse-string "sequence: !!seq +- entry +- !!seq + - nested +mapping: !!map + foo: bar" :object-type 'alist) + '(("sequence" . ["entry" ["nested"]]) + ("mapping" . (("foo" . "bar")))))) + + ;; Example 9.2. Document Markers + (should (equal (yaml-parse-string "%YAML 1.2 +--- +Document +...") + "Document")) + + ;; Example 9.3 Bare Documents + ;; TODO: Allow first character of bare document to be % + ;; (should (equal (yaml-parse-string "%!PS-Adobe-2.0 # Not the first line + ;; "))) + + (should (equal (yaml-parse-string "--- +{ matches +% : 20 } +... +--- +# Empty +...") + "" ;; TODO: Should this be :null instead? + )) + + ;; Example 9.4. Explicit Documents + (should (equal (yaml-parse-string "--- +{ matches +% : 20 } +..." :object-type 'alist) + '(("matches %" . 20))))) (ert-deftest yaml-parsing-completes () "Tests that the yaml parses." diff --git a/yaml.el b/yaml.el index 9f6e26c9c4..f1ddd24d26 100644 --- a/yaml.el +++ b/yaml.el @@ -482,17 +482,24 @@ This flag is intended for development purposes.") ("ns-flow-pair" . (lambda (text) (yaml--add-event (yaml--mapping-end-event)))) ("ns-plain" . (lambda (text) - (let* ((replaced (replace-regexp-in-string + (let* ((replaced (if (and (zerop (length yaml--state-stack)) + (string-match "\\(^\\|\n\\)...$" text)) + ;; Hack to not send the document parse end. + ;; Will only occur with bare ns-plain at top level. + (string-trim-right (string-trim-right text "...") "\n") + text)) + (replaced (replace-regexp-in-string "\\(?:[ \t]*\r?\n[ \t]*\\)" "\n" - text)) + replaced)) (replaced (replace-regexp-in-string "\\(\n\\)\\(\n*\\)" (lambda (x) (if (> (length x) 1) (substring x 1) " ")) - replaced))) + replaced)) + ) (yaml--add-event (yaml--scalar-event "plain" replaced))))) ("c-single-quoted" . (lambda (text) (let* ((replaced (replace-regexp-in-string