Skip to content

Commit

Permalink
added Mojo::JSON tests for empty keys
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jun 13, 2013
1 parent 6527cc6 commit a265d7f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

4.15 2013-06-12
4.15 2013-06-13
- Fixed a few error reporting bugs in Mojo::IOLoop::Client and
Mojo::IOLoop::Server.

Expand Down
8 changes: 4 additions & 4 deletions lib/Mojo/JSON.pm
Expand Up @@ -32,10 +32,10 @@ for (0x00 .. 0x1F, 0x7F) { $REVERSE{pack 'C', $_} //= sprintf '\u%.4X', $_ }

# Unicode encoding detection
my $UTF_PATTERNS = {
'UTF-32BE' => qr/^\0\0\0[^\0]/,
'UTF-16BE' => qr/^\0[^\0]\0[^\0]/,
'UTF-32LE' => qr/^[^\0]\0\0\0/,
'UTF-16LE' => qr/^[^\0]\0[^\0]\0/
'UTF-32BE' => qr/^\x00{3}[^\x00]/,
'UTF-32LE' => qr/^[^\x00]\x00{3}/,
'UTF-16BE' => qr/^(?:\x00[^\x00]){2}/,
'UTF-16LE' => qr/^(?:[^\x00]\x00){2}/
};

my $WHITESPACE_RE = qr/[\x20\x09\x0a\x0d]*/;
Expand Down
10 changes: 6 additions & 4 deletions t/mojo/json.t
Expand Up @@ -29,10 +29,8 @@ is_deeply $array, ['-122.026020'], 'decode [ -122.026020 ]';
$array = $json->decode('[ -122.026020 ]');
is_deeply $array, ['-122.02602'], 'decode [ -122.026020 ]';
$array = $json->decode('[0.0]');
isa_ok $array, 'ARRAY', 'decode [0.0]';
cmp_ok $array->[0], '==', 0, 'value is 0';
$array = $json->decode('[0e0]');
isa_ok $array, 'ARRAY', 'decode [0e0]';
cmp_ok $array->[0], '==', 0, 'value is 0';
$array = $json->decode('[1,-2]');
is_deeply $array, [1, -2], 'decode [1,-2]';
Expand All @@ -43,7 +41,6 @@ is_deeply $array, [10000000000000, [2]], 'decode [10e12 , [2 ]]';
$array = $json->decode('[37.7668 , [ 20 ]] ');
is_deeply $array, [37.7668, [20]], 'decode [37.7668 , [ 20 ]] ';
$array = $json->decode('[1e3]');
isa_ok $array, 'ARRAY', 'decode [1e3]';
cmp_ok $array->[0], '==', 1e3, 'value is 1e3';

# Decode name
Expand Down Expand Up @@ -228,9 +225,14 @@ $hash = $json->decode('{"foo": 1, "foo": 2}');
is_deeply $hash, {foo => 2}, 'decode {"foo": 1, "foo": 2}';

# Complicated roudtrips
$bytes = '{"":""}';
$hash = $json->decode($bytes);
is_deeply $hash, {'' => ''}, 'decode {"":""}';
is $json->encode($hash), $bytes, 'reencode';
$bytes = '[null,false,true,"",0,1]';
$array = $json->decode($bytes);
isa_ok $array, 'ARRAY', 'decode [null,false,true,"",0,1]';
is_deeply $array, [undef, Mojo::JSON->false, Mojo::JSON->true, '', 0, 1],
'decode [null,false,true,"",0,1]';
is $json->encode($array), $bytes, 'reencode';
$array = [undef, 0, 1, '', Mojo::JSON->true, Mojo::JSON->false];
$bytes = $json->encode($array);
Expand Down

0 comments on commit a265d7f

Please sign in to comment.