Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
use values instead of data structures in descriptions
  • Loading branch information
kraih committed Mar 3, 2014
1 parent 0254ad1 commit a0db1ba
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
10 changes: 5 additions & 5 deletions lib/Mojo/JSON.pm
Expand Up @@ -354,13 +354,13 @@ individually.
my $value = decode_json($bytes);
Decode JSON to Perl data structure and die if decoding fails.
Decode JSON to Perl value and die if decoding fails.
=head2 encode_json
my $bytes = encode_json({foo => 'bar'});
Encode Perl data structure to JSON.
Encode Perl value to JSON.
=head2 j
Expand All @@ -369,7 +369,7 @@ Encode Perl data structure to JSON.
my $value = j($bytes);
Encode Perl data structure, which may only be an C<Array> reference or C<Hash>
reference, or decode JSON and return C<undef> if decoding fails.
reference, to JSON or decode JSON and return C<undef> if decoding fails.
=head1 ATTRIBUTES
Expand All @@ -391,13 +391,13 @@ following new ones.
my $value = $json->decode($bytes);
Decode JSON to Perl data structure and return C<undef> if decoding fails.
Decode JSON to Perl value and return C<undef> if decoding fails.
=head2 encode
my $bytes = $json->encode({foo => 'bar'});
Encode Perl data structure to JSON.
Encode Perl value to JSON.
=head2 false
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/JSON/Pointer.pm
Expand Up @@ -76,8 +76,8 @@ the following new ones.
my $bool = $pointer->contains('/foo/1');
my $bool = $pointer->contains($data, '/foo/1');
Check if data structure contains a value that can be identified with the given
JSON Pointer, defaults to using L</data>.
Check if Perl data structure contains a value that can be identified with the
given JSON Pointer, defaults to using L</data>.
# True
$pointer->contains({'♥' => 'mojolicious'}, '/♥');
Expand Down
8 changes: 4 additions & 4 deletions lib/Test/Mojo.pm
Expand Up @@ -157,7 +157,7 @@ sub json_hasnt {
sub json_is {
my $self = shift;
my ($p, $data) = @_ > 1 ? (shift, shift) : ('', shift);
my $desc = encode 'UTF-8', qq{exact match for JSON Pointer "$p"};
my $desc = encode 'UTF-8', shift || qq{exact match for JSON Pointer "$p"};
return $self->_test('is_deeply', $self->tx->res->json($p), $data, $desc);
}

Expand All @@ -176,7 +176,7 @@ sub json_message_hasnt {
sub json_message_is {
my $self = shift;
my ($p, $data) = @_ > 1 ? (shift, shift) : ('', shift);
my $desc = encode 'UTF-8', qq{exact match for JSON Pointer "$p"};
my $desc = encode 'UTF-8', shift || qq{exact match for JSON Pointer "$p"};
return $self->_test('is_deeply', $self->_json(get => $p), $data, $desc);
}

Expand Down Expand Up @@ -667,7 +667,7 @@ Opposite of L</"json_has">.
$t = $t->json_is({foo => [1, 2, 3]});
$t = $t->json_is('/foo' => [1, 2, 3]);
$t = $t->json_is('/foo/1' => 2);
$t = $t->json_is('/foo/1' => 2, 'right value');
Check the value extracted from JSON response using the given JSON Pointer with
L<Mojo::JSON::Pointer>, which defaults to the root value if it is omitted.
Expand All @@ -691,7 +691,7 @@ Opposite of L</"json_message_has">.
$t = $t->json_message_is({foo => [1, 2, 3]});
$t = $t->json_message_is('/foo' => [1, 2, 3]);
$t = $t->json_message_is('/foo/1' => 2);
$t = $t->json_message_is('/foo/1' => 2, 'right value');
Check the value extracted from JSON WebSocket message using the given JSON
Pointer with L<Mojo::JSON::Pointer>, which defaults to the root value if it is
Expand Down
5 changes: 3 additions & 2 deletions t/mojolicious/lite_app.t
Expand Up @@ -888,8 +888,9 @@ $t->post_ok('/malformed_utf8' =>
# JSON
$t->get_ok('/json')->status_is(200)->header_is(Server => 'Mojolicious (Perl)')
->content_type_is('application/json')->json_is({foo => [1, -2, 3, 'b☃r']})
->json_is('/foo' => [1, -2, 3, 'b☃r'])->json_is('/foo/3', 'b☃r')
->json_has('/foo')->json_hasnt('/bar');
->json_is('/foo' => [1, -2, 3, 'b☃r'])
->json_is('/foo/3', 'b☃r', 'right value')->json_has('/foo')
->json_hasnt('/bar');

# Stash values in template
$t->get_ok('/autostash?bar=23')->status_is(200)
Expand Down
3 changes: 2 additions & 1 deletion t/mojolicious/websocket_lite_app.t
Expand Up @@ -208,7 +208,8 @@ $t->websocket_ok('/json')->send_ok({json => {test => 23, snowman => '☃'}})
->message_ok->json_message_is([1, 2, 3, 4])->json_message_is([1, 2, 3, 4])
->send_ok({binary => j([1, 2, 3])})
->message_ok->json_message_has('/2', 'has two elements')
->json_message_is('/2' => 3)->json_message_hasnt('/5', 'not five elements')
->json_message_is('/2' => 3, 'right value')
->json_message_hasnt('/5', 'not five elements')
->send_ok({json => {'' => [1, 2, 3]}})
->message_ok->json_message_is('/☃', [1, 2, 3])->send_ok({json => 'works'})
->message_ok->json_message_is('works')->send_ok({json => undef})
Expand Down

0 comments on commit a0db1ba

Please sign in to comment.