yaml / yaml-test-suite

Comprehensive, language independent Test Suite for YAML
MIT License
172 stars 58 forks source link

M7A3: Either in-json or out-yaml is wrong #39

Closed eemeli closed 5 years ago

eemeli commented 6 years ago

This test corresponds to Example 9.3 of the spec, where a stream has either two or three documents, depending on whether the second one is skipped or not:

Bare
document
...
# No document
...
|
%!PS-Adobe-2.0 # Not the first line

The current in-json and the test-event stream skip the second one, but the out-yaml includes it as an explicit document. I'm not sure what's really right here, but I'd at least prefer to include the second empty/null document in the stream.

hvr commented 6 years ago

IMHO, out-yaml is wrong, as the intent of that example in the spec is clearly to show an example with only 2 docs. (also note that ... on their own don't introduce a new document)

I'm a bit suprised btw that the canonical right-hand-side of example 9.3 doesn't read

%YAML 1.2
---
!!str "Bare document"
...
%YAML 1.2
---
!!str "%!PS-Adobe-2.0\n"

(notice the ...) like the similar one from example 9.5 had.


PS: To expand a bit more:

The YAML 1.2 spec says (emphasis added)

YAML uses three dashes (“---”) to separate directives from document content. This also serves to signal the start of a document if no directives are present. Three dots ( “...”) indicate the end of a document without starting a new one, for use in communication channels.

moreover,

[205] l-document-suffix ::= c-document-end s-l-comments

So the # No document comment would be part of the l-document-suffix production.

Moreover,

[211]   l-yaml-stream   ::=     l-document-prefix* l-any-document?
                              ( l-document-suffix+ l-document-prefix* l-any-document?
                              | l-document-prefix* l-explicit-document? )* 

encodes that multiple consecutive occurences of l-document-suffix count as one.

Hence we got only two documents, and thus test-event stating

+STR
+DOC
=VAL :Bare document
-DOC ...
+DOC
=VAL |%!PS-Adobe-2.0 # Not the first line\n
-DOC
-STR

is in fact correct.

perlpunk commented 5 years ago

Thanks, my suggested fix is in #42

perlpunk commented 5 years ago

Merged #42