Skip to content

Commit

Permalink
test tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 4, 2013
1 parent f020e9d commit 747f08d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,6 +1,7 @@

3.85 2013-01-31
3.85 2013-02-04
- Improved documentation.
- Improved tests.

3.84 2013-01-30
- Deprecated after_static_dispatch hook in favor of before_routes.
Expand Down
10 changes: 5 additions & 5 deletions lib/Mojo/JSON.pm
Expand Up @@ -98,7 +98,7 @@ sub decode {

sub encode {
my ($self, $ref) = @_;
return Mojo::Util::encode 'UTF-8', _encode_values($ref);
return Mojo::Util::encode 'UTF-8', _encode_value($ref);
}

sub false {$FALSE}
Expand Down Expand Up @@ -251,12 +251,12 @@ sub _decode_value {

sub _encode_array {
my $array = shift;
return '[' . join(',', map { _encode_values($_) } @$array) . ']';
return '[' . join(',', map { _encode_value($_) } @$array) . ']';
}

sub _encode_object {
my $object = shift;
my @pairs = map { _encode_string($_) . ':' . _encode_values($object->{$_}) }
my @pairs = map { _encode_string($_) . ':' . _encode_value($object->{$_}) }
keys %$object;
return '{' . join(',', @pairs) . '}';
}
Expand All @@ -267,7 +267,7 @@ sub _encode_string {
return "\"$string\"";
}

sub _encode_values {
sub _encode_value {
my $value = shift;

# Reference
Expand All @@ -285,7 +285,7 @@ sub _encode_values {

# Blessed reference with TO_JSON method
if (blessed $value && (my $sub = $value->can('TO_JSON'))) {
return _encode_values($value->$sub);
return _encode_value($value->$sub);
}
}

Expand Down
8 changes: 4 additions & 4 deletions t/mojo/json.t
Expand Up @@ -269,14 +269,14 @@ is $json->encode({true => \1}), '{"true":true}', 'encode {true => \1}';
is $json->encode({false => \0}), '{"false":false}', 'encode {false => \0}';
$bytes = 'some true value';
is $json->encode({true => \!!$bytes}), '{"true":true}',
'encode true boolean from string';
'encode true boolean from double negated reference';
is $json->encode({true => \$bytes}), '{"true":true}',
'encode true boolean from string';
'encode true boolean from reference';
$bytes = '';
is $json->encode({false => \!!$bytes}), '{"false":false}',
'encode false boolean from string';
'encode false boolean from double negated reference';
is $json->encode({false => \$bytes}), '{"false":false}',
'encode false boolean from string';
'encode false boolean from reference';

# Errors
is $json->decode('["♥"]'), undef, 'wide character in input';
Expand Down

0 comments on commit 747f08d

Please sign in to comment.