Permalink
Browse files

Generate Undef instead of Nulls. Reclaim few more tests

  • Loading branch information...
1 parent ef664df commit 5a55e2b16b6d1735bfc1b1082af2fc233723c9da @bacek bacek committed Jan 30, 2011
Showing with 32 additions and 27 deletions.
  1. +10 −10 lib/YAML/Tiny.pm
  2. +12 −15 t/02_basic.t
  3. +1 −2 t/11_meta_yaml.t
  4. +9 −0 t/lib/Test.pm
View
@@ -86,7 +86,7 @@ method read_string($string) {
# if ( defined $1 and $1 !~ /^(?:\#.+|\%YAML[: ][\d\.]+)\z/ ) {
# match[0] is RPA. Get first element.
if +$match[0] {
- @result.push(self._read_scalar( ~$match[0][0], [ undef ], @lines ));
+ @result.push(self._read_scalar( ~$match[0][0], [ pir::new('Undef') ], @lines ));
next;
}
}
@@ -96,7 +96,7 @@ method read_string($string) {
if !@lines || (@lines[0] ~~ /^['---'|'...']/) {
debug("Naked", @lines);
# A naked document
- @result.push(undef);
+ @result.push(pir::new('Undef'));
while @lines && !(@lines[0] ~~ /^'---'/) {
@lines.shift;
}
@@ -142,8 +142,8 @@ method _read_scalar($string, $indent, @lines) {
# Trim trailing whitespace
$string := subst($string, /\s*$/, '');
- # Explitic null/undef
- return undef if $string eq '~';
+ # Explitic null/pir::new('Undef')
+ return pir::new('Undef') if $string eq '~';
# Single quote
my $match := $string ~~ /^\'(.*?)\'[\s+\#.*]?$/;
@@ -249,20 +249,20 @@ method _read_array(@array, @indent, @lines) {
elsif $m := @lines[0] ~~ /^\s* \- (\s*) (.+?) \s* $/ {
# Array entry with a value
@lines.shift;
- @array.push(self._read_scalar( ~$m[1], [ @indent, undef ], @lines ));
+ @array.push(self._read_scalar( ~$m[1], [ @indent, pir::new('Undef') ], @lines ));
}
elsif $m := @lines[0] ~~ /^\s*\-\s*$/ {
@lines.shift;
unless @lines {
- @array.push(undef);
+ @array.push(pir::new('Undef'));
return 1;
}
if $m := @lines[0] ~~ /^(\s*)\-/ {
my $indent2 := length($m[0]);
if @indent[-1] == $indent2 {
# Null array entry
- @array.push(undef);
+ @array.push(pir::new('Undef'));
}
else {
# Naked indenter
@@ -338,14 +338,14 @@ method _read_hash(%hash, @indent, @lines) {
if length(@lines[0]) {
# Yes
debug("Reading scalar", @lines[0]);
- %hash{$key} := self._read_scalar( @lines.shift, [ @indent, undef ], @lines );
+ %hash{$key} := self._read_scalar( @lines.shift, [ @indent, pir::new('Undef') ], @lines );
debug("Done", %hash);
}
else {
# An indent
@lines.shift;
unless @lines {
- %hash{$key} := undef;
+ %hash{$key} := pir::new('Undef');
return 1;
}
@@ -358,7 +358,7 @@ method _read_hash(%hash, @indent, @lines) {
my $indent2 := length($m[0]);
if ( @indent[-1] >= $indent2 ) {
# Null hash entry
- %hash{$key} := undef;
+ %hash{$key} := pir::new('Undef');
}
else {
%hash{$key} := {};
View
@@ -34,31 +34,31 @@ yaml_ok(
# Empty documents
yaml_ok(
"---\n",
- [ undef ],
+ [ pir::new('Undef') ],
'only_header',
noyamlperl => 1,
);
yaml_ok(
"---\n---\n",
- [ undef, undef ],
+ [ pir::new('Undef'), pir::new('Undef') ],
'two_header',
noyamlperl => 1,
);
yaml_ok(
"--- ~\n",
- [ undef ],
+ [ pir::new('Undef') ],
'one_undef',
noyamlperl => 1,
);
yaml_ok(
"--- ~\n",
- [ undef ],
+ [ pir::new('Undef') ],
'one_undef2',
noyamlperl => 1,
);
yaml_ok(
"--- ~\n---\n",
- [ undef, undef ],
+ [ pir::new('Undef'), pir::new('Undef') ],
'two_undef',
noyamlperl => 1,
);
@@ -94,7 +94,7 @@ yaml_ok(
);
yaml_ok(
"---\n- ~\n- bar\n",
- [ [ undef, 'bar' ] ],
+ [ [ pir::new('Undef'), 'bar' ] ],
'one_listundef',
noyamlperl => 1,
);
@@ -108,10 +108,9 @@ yaml_ok(
yaml_ok(
"---\nfoo: bar\nthis: ~\n",
- [ hash(this => undef, foo => 'bar') ],
+ [ hash(this => pir::new('Undef'), foo => 'bar') ],
'one_hash2',
noyamlperl => 1,
- todo => 1,
);
# Simple array inside a hash with an undef
@@ -122,7 +121,7 @@ foo:
- ~
- baz
},
- [ hash(foo => [ 'bar', undef, 'baz' ]) ],
+ [ hash(foo => [ 'bar', pir::new('Undef'), 'baz' ]) ],
'array_in_hash',
noyamlperl => 1,
);
@@ -134,10 +133,9 @@ foo: ~
bar:
foo: bar
},
- [ hash(foo => undef, bar => hash(foo => 'bar' )) ],
+ [ hash(foo => pir::new('Undef'), bar => hash(foo => 'bar' )) ],
'hash_in_hash',
noyamlperl => 1,
- todo => 1,
);
# Mixed hash and scalars inside an array
@@ -153,14 +151,13 @@ yaml_ok(
this: that
},
[ [
- hash( foo => undef, this => 'that' ),
+ hash( foo => pir::new('Undef'), this => 'that' ),
'foo',
- undef,
+ pir::new('Undef'),
hash( foo => 'bar', this => 'that' ),
] ],
'hash_in_array',
noyamlperl => 1,
- todo => 1,
);
# Simple single quote
@@ -226,7 +223,7 @@ yaml_ok(
this: that
- baz
},
- [ [ undef, hash( foo => 'bar', this => 'that' ), 'baz' ] ],
+ [ [ pir::new('Undef'), hash( foo => 'bar', this => 'that' ), 'baz' ] ],
'inline_nested_hash',
noyamlperl => 1,
);
View
@@ -171,14 +171,13 @@ generated_by: ExtUtils::MakeMaker version 6.17
version_from => 'Baby.pm',
installdirs => 'site',
requires => hash(
- warnings => undef,
+ warnings => pir::new('Undef'),
),
distribution_type => 'module',
generated_by => 'ExtUtils::MakeMaker version 6.17',
) ],
'Acme-Time-Baby',
noyamlperl => 1,
- todo => 1,
);
View
@@ -15,6 +15,15 @@ our sub yaml_ok($yaml, $expected, $description, *%adverbs) {
}
}
+# NQP semantic doesn't handle fatarrow well. We can have quoted keys.
+# So, use special helper for tests.
+our sub myhash(*@pos, *%named) {
+ for @pos -> $k, $v {
+ %named{$k} := $v;
+ }
+ %named;
+}
+
Q:PIR {
# We want Test::More features for testing. Not NQP's builtin.
.include "test_more.pir"

0 comments on commit 5a55e2b

Please sign in to comment.