use File::Spec::Functions ':ALL';
use Parse::CPAN::Meta::Test;
-use Test::More tests(20);
+use Test::More tests(37);
);
# Piped multi-line scalar
-yaml_ok( <<'END_YAML', [ [ "foo\nbar\n", 1 ] ], 'indented', nosyck => 1 );
+yaml_ok(
+ <<'END_YAML',
---
- |
foo
bar
- 1
END_YAML
+ [ [ "foo\nbar\n", 1 ] ],
+ 'indented',
+);
# ... with a pointless hyphen
-yaml_ok( <<'END_YAML', [ [ "foo\nbar", 1 ] ], 'indented', nosyck => 1 );
+yaml_ok( <<'END_YAML',
---
- |-
foo
bar
- 1
END_YAML
-
+ [ [ "foo\nbar", 1 ] ],
+ 'indented',
+);
#####################################################################
-# Support for YAML document version declarations
+# Support for YAML version directives
-# Simple case
+# Simple inline case (comment variant)
yaml_ok(
<<'END_YAML',
--- #YAML:1.0
foo: bar
END_YAML
[ { foo => 'bar' } ],
- 'simple_doctype',
+ 'simple_doctype_comment',
+ nosyck => 1,
+);
+
+# Simple inline case (percent variant)
+yaml_ok(
+ <<'END_YAML',
+--- %YAML:1.0
+foo: bar
+END_YAML
+ [ { foo => 'bar' } ],
+ 'simple_doctype_percent',
+ noyamlpm => 1,
+ noxs => 1,
+ noyamlperl => 1,
+);
+
+# Simple header (comment variant)
+yaml_ok(
+ <<'END_YAML',
+%YAML:1.0
+---
+foo: bar
+END_YAML
+ [ { foo => 'bar' } ],
+ 'predocument_1_0',
+ noyamlpm => 1,
+ nosyck => 1,
+ noxs => 1,
+ noyamlperl => 1,
);
-# Multiple documents
+# Simple inline case (comment variant)
+yaml_ok(
+ <<'END_YAML',
+%YAML 1.1
+---
+foo: bar
+END_YAML
+ [ { foo => 'bar' } ],
+ 'predocument_1_1',
+ noyamlpm => 1,
+ nosyck => 1,
+ noyamlperl => 1,
+);
+
+# Multiple inline documents (comment variant)
yaml_ok(
<<'END_YAML',
--- #YAML:1.0
foo: bar
END_YAML
[ { foo => 'bar' }, [ 1 ], { foo => 'bar' } ],
- 'multi_doctype',
+ 'multi_doctype_comment',
+);
+
+# Simple pre-document case (comment variant)
+yaml_ok(
+ <<'END_YAML',
+%YAML 1.1
+---
+foo: bar
+END_YAML
+ [ { foo => 'bar' } ],
+ 'predocument_percent',
+ noyamlpm => 1,
+ nosyck => 1,
+ noyamlperl => 1,
+);
+
+# Simple pre-document case (comment variant)
+yaml_ok(
+ <<'END_YAML',
+#YAML 1.1
+---
+foo: bar
+END_YAML
+ [ { foo => 'bar' } ],
+ 'predocument_comment',
);
- ~
- 'bar'
END_YAML
- [ { abstract => 'Generate fractal curves', foo => undef, arr => [ 'foo', undef, 'bar' ] } ],
+ [ {
+ abstract => 'Generate fractal curves',
+ foo => undef,
+ arr => [ 'foo', undef, 'bar' ],
+ } ],
'trailing whitespace',
+ noyamlperl => 1,
);
#####################################################################
-# Single Quote Idiosyncracy
+# Quote and Escaping Idiosyncracies
+
+yaml_ok(
+ <<'END_YAML',
+---
+name1: 'O''Reilly'
+name2: 'O''Reilly O''Tool'
+name3: 'Double '''' Quote'
+END_YAML
+ [ {
+ name1 => "O'Reilly",
+ name2 => "O'Reilly O'Tool",
+ name3 => "Double '' Quote",
+ } ],
+ 'single quote subtleties',
+);
yaml_ok(
<<'END_YAML',
---
-slash: '\\'
-name: 'O''Reilly'
+slash1: '\\'
+slash2: '\\foo'
+slash3: '\\foo\\\\'
END_YAML
- [ { slash => "\\\\", name => "O'Reilly" } ],
+ [ {
+ slash1 => "\\\\",
+ slash2 => "\\\\foo",
+ slash3 => "\\\\foo\\\\\\\\",
+ } ],
'single quote subtleties',
);
END_YAML
[ { foo => 0, requires => undef, build_requires => undef } ],
'empty hash keys',
+ noyamlpm => 1,
+ noyamlperl => 1,
);
yaml_ok(
END_YAML
[ [ 'foo', undef, undef ] ],
'empty array keys',
+ noyamlpm => 1,
+ noyamlperl => 1,
);
END_YAML
[ { foo => 'bar' } ],
'comment header',
+ noyamlpm => 1,
+ noyamlperl => 1,
);
+#####################################################################
+# Confirm we can read the synopsis
+
+yaml_ok(
+ <<'END_YAML',
+---
+rootproperty: blah
+section:
+ one: two
+ three: four
+ Foo: Bar
+ empty: ~
+END_YAML
+ [ {
+ rootproperty => 'blah',
+ section => {
+ one => 'two',
+ three => 'four',
+ Foo => 'Bar',
+ empty => undef,
+ },
+ } ],
+ 'synopsis',
+ noyamlperl => 1,
+);
+
+
+
+
+
+#####################################################################
+# Unprintable Characters
+
+yaml_ok(
+ "--- \"foo\\n\\x00\"\n",
+ [ "foo\n\0" ],
+ 'unprintable',
+);
+
+
+
+
+
+#####################################################################
+# Empty Quote Line
+
+yaml_ok(
+ <<'END_YAML',
+---
+- foo
+#
+- bar
+END_YAML
+ [ [ "foo", "bar" ] ],
+);
+
+
+
+
+
+#####################################################################
+# Indentation after empty hash value
+
+yaml_ok(
+ <<'END_YAML',
+---
+Test:
+ optmods:
+ Bad: 0
+ Foo: 1
+ Long: 0
+ version: 5
+Test_IncludeA:
+ optmods:
+Test_IncludeB:
+ optmods:
+_meta:
+ name: 'test profile'
+ note: 'note this test profile'
+END_YAML
+ [ {
+ Test => {
+ optmods => {
+ Bad => 0,
+ Foo => 1,
+ Long => 0,
+ },
+ version => 5,
+ },
+ Test_IncludeA => {
+ optmods => undef,
+ },
+ Test_IncludeB => {
+ optmods => undef,
+ },
+ _meta => {
+ name => 'test profile',
+ note => 'note this test profile',
+ },
+ } ],
+ 'Indentation after empty hash value',
+ noyamlperl => 1,
+);
+
+
+
+
+
+#####################################################################
+# Spaces in the Key
+
+yaml_ok(
+ <<'END_YAML',
+---
+the key: the value
+END_YAML
+ [ { 'the key' => 'the value' } ],
+);
+
+
+
+
+
+#####################################################################
+# Ticker #32402
+
+# Tests a particular pathological case
+
+yaml_ok(
+ <<'END_YAML',
+---
+- value
+- '><'
+END_YAML
+ [ [ 'value', '><' ] ],
+ 'Pathological >< case',
+);
+
+
+
+
+
+#####################################################################
+# Special Characters
+
+#yaml_ok(
+# <<'END_YAML',
+#---
+#- "Ingy d\xC3\xB6t Net"
+#END_YAML
+# [ [ "Ingy d\xC3\xB6t Net" ] ],
+#);
+
+
+
+
+
######################################################################
# Non-Indenting Sub-List
END_YAML
[ { foo => [ 'list' ], bar => 'value' } ],
'Non-indenting sub-list',
+ noyamlpm => 1,
+ noyamlperl => 1,
+);
+
+
+
+
+
+
+#####################################################################
+# Check Multiple-Escaping
+
+# RT #42119: write of two single quotes
+yaml_ok(
+ "--- \"A'B'C\"\n",
+ [ "A'B'C" ],
+ 'Multiple escaping of quote ok',
+);
+
+# Escapes without whitespace
+yaml_ok(
+ "--- A\\B\\C\n",
+ [ "A\\B\\C" ],
+ 'Multiple escaping of escape ok',
+);
+
+# Escapes with whitespace
+yaml_ok(
+ "--- 'A\\B \\C'\n",
+ [ "A\\B \\C" ],
+ 'Multiple escaping of escape with whitespace ok',
+);
+
+
+
+
+
+######################################################################
+# Check illegal characters that are in legal places
+
+yaml_ok(
+ "--- 'Wow!'\n",
+ [ "Wow!" ],
+ 'Bang in a quote',
+);
+yaml_ok(
+ "--- 'This&that'\n",
+ [ "This&that" ],
+ 'Ampersand in a quote',
);