Skip to content

Commit

Permalink
add yaml test cases for more bool types and multi-line flow scalars.
Browse files Browse the repository at this point in the history
  • Loading branch information
yaythomas authored and alecthomas committed May 11, 2020
1 parent 2b9c82d commit 2612dee
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
26 changes: 26 additions & 0 deletions lexers/testdata/yaml.actual
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ scientific_notation: 1e+12
# The number 1 will be interpreted as a number, not a boolean. if you want
# it to be interpreted as a boolean, use true
boolean: true
boolean_different_case: False
boolean_yes: YES
null_value: null
key with spaces: value
# Notice that strings don't need to be quoted. However, they can be.
Expand All @@ -25,6 +27,16 @@ double quotes: "have many: \", \0, \t, \u263A, \x0d\x0a == \r\n, and more."
# UTF-8/16/32 characters need to be encoded
Superscript two: \u00B2

# Multi-line flow scalars can be unquoted or quoted.
unquoted_scalar: Multiline scalar
with 'quotes' in the middle.
This is the last line.
single_quoted_scalar: 'Multiline single quoted scalar
with "quotes" in the middle
Last line'
double_quoted_scalar: "Multiline double quoted scalar
with 'quotes' in the middle
end"
# Multiple-line strings can be written either as a 'literal block' (using |),
# or a 'folded block' (using '>').
literal_block: |
Expand All @@ -44,7 +56,21 @@ folded_style: >

'More-indented' lines keep their newlines, too -
this text will appear over two lines.
literal_block_with_strip_chomping: |-
This entire block of text will be the value of the 'literal_block' key,
with line breaks being preserved and the strip chomping indicator.

The literal continues until de-dented, and the leading indentation is
stripped.

Any lines that are 'more-indented' keep the rest of their indentation -
these lines will be indented by 4 spaces.
literal_block_with_keep_chomping: |+
This entire block of text will be the value of the 'literal_block' key,
with line breaks being preserved and the keep chomping indicator.

The literal continues until de-dented, and the leading indentation is
stripped.
####################
# COLLECTION TYPES #
####################
Expand Down
45 changes: 44 additions & 1 deletion lexers/testdata/yaml.expected
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@
{"type":"TextWhitespace","value":" "},
{"type":"KeywordConstant","value":"true"},
{"type":"TextWhitespace","value":"\n"},
{"type":"NameTag","value":"boolean_different_case"},
{"type":"Punctuation","value":":"},
{"type":"TextWhitespace","value":" "},
{"type":"KeywordConstant","value":"False"},
{"type":"TextWhitespace","value":"\n"},
{"type":"NameTag","value":"boolean_yes"},
{"type":"Punctuation","value":":"},
{"type":"TextWhitespace","value":" "},
{"type":"KeywordConstant","value":"YES"},
{"type":"TextWhitespace","value":"\n"},
{"type":"NameTag","value":"null_value"},
{"type":"Punctuation","value":":"},
{"type":"TextWhitespace","value":" "},
Expand Down Expand Up @@ -83,6 +93,27 @@
{"type":"TextWhitespace","value":" "},
{"type":"Literal","value":"\\u00B2"},
{"type":"TextWhitespace","value":"\n\n"},
{"type":"Comment","value":"# Multi-line flow scalars can be unquoted or quoted."},
{"type":"TextWhitespace","value":"\n"},
{"type":"NameTag","value":"unquoted_scalar"},
{"type":"Punctuation","value":":"},
{"type":"TextWhitespace","value":" "},
{"type":"Literal","value":"Multiline scalar"},
{"type":"TextWhitespace","value":"\n "},
{"type":"Literal","value":"with 'quotes' in the middle."},
{"type":"TextWhitespace","value":"\n "},
{"type":"Literal","value":"This is the last line."},
{"type":"TextWhitespace","value":"\n"},
{"type":"NameTag","value":"single_quoted_scalar"},
{"type":"Punctuation","value":":"},
{"type":"TextWhitespace","value":" "},
{"type":"LiteralStringSingle","value":"'Multiline single quoted scalar\n with \"quotes\" in the middle\n Last line'"},
{"type":"TextWhitespace","value":"\n"},
{"type":"NameTag","value":"double_quoted_scalar"},
{"type":"Punctuation","value":":"},
{"type":"TextWhitespace","value":" "},
{"type":"LiteralStringDouble","value":"\"Multiline double quoted scalar\n with 'quotes' in the middle\n end\""},
{"type":"TextWhitespace","value":"\n"},
{"type":"Comment","value":"# Multiple-line strings can be written either as a 'literal block' (using |),"},
{"type":"TextWhitespace","value":"\n"},
{"type":"Comment","value":"# or a 'folded block' (using '\u003e')."},
Expand All @@ -95,7 +126,19 @@
{"type":"NameTag","value":"folded_style"},
{"type":"Punctuation","value":":"},
{"type":"TextWhitespace","value":" "},
{"type":"LiteralStringDoc","value":"\u003e\n This entire block of text will be the value of 'folded_style', but this\n time, all newlines will be replaced with a single space.\n\n Blank lines, like above, are converted to a newline character.\n\n 'More-indented' lines keep their newlines, too -\n this text will appear over two lines.\n\n####################"},
{"type":"LiteralStringDoc","value":"\u003e\n This entire block of text will be the value of 'folded_style', but this\n time, all newlines will be replaced with a single space.\n\n Blank lines, like above, are converted to a newline character.\n\n 'More-indented' lines keep their newlines, too -\n this text will appear over two lines."},
{"type":"TextWhitespace","value":"\n"},
{"type":"NameTag","value":"literal_block_with_strip_chomping"},
{"type":"Punctuation","value":":"},
{"type":"TextWhitespace","value":" "},
{"type":"LiteralStringDoc","value":"|-\n This entire block of text will be the value of the 'literal_block' key,\n with line breaks being preserved and the strip chomping indicator.\n\n The literal continues until de-dented, and the leading indentation is\n stripped.\n\n Any lines that are 'more-indented' keep the rest of their indentation -\n these lines will be indented by 4 spaces."},
{"type":"TextWhitespace","value":"\n"},
{"type":"NameTag","value":"literal_block_with_keep_chomping"},
{"type":"Punctuation","value":":"},
{"type":"TextWhitespace","value":" "},
{"type":"LiteralStringDoc","value":"|+\n This entire block of text will be the value of the 'literal_block' key,\n with line breaks being preserved and the keep chomping indicator.\n\n The literal continues until de-dented, and the leading indentation is\n stripped."},
{"type":"TextWhitespace","value":"\n"},
{"type":"Comment","value":"####################"},
{"type":"TextWhitespace","value":"\n"},
{"type":"Comment","value":"# COLLECTION TYPES #"},
{"type":"TextWhitespace","value":"\n"},
Expand Down

0 comments on commit 2612dee

Please sign in to comment.