Skip to content

Commit

Permalink
better tests for Mojo::JSON booleans
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Nov 26, 2014
1 parent 24f5aaf commit 752656b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/Mojo/JSON.pm
Expand Up @@ -48,7 +48,7 @@ sub encode { encode_json($_[1]) }

sub encode_json { Mojo::Util::encode 'UTF-8', _encode_value(shift) }

sub false {$FALSE}
sub false () {$FALSE}

sub from_json {
my $err = _catch(\my $value, shift, 1);
Expand All @@ -68,7 +68,7 @@ sub new {

sub to_json { _encode_value(shift) }

sub true {$TRUE}
sub true () {$TRUE}

sub _catch {
my $valueref = shift;
Expand Down
8 changes: 5 additions & 3 deletions t/mojo/json.t
Expand Up @@ -279,9 +279,11 @@ is encode_json({false => \!!$bytes}), '{"false":false}',
is encode_json({false => \$bytes}), '{"false":false}',
'encode false boolean from reference';

# Stringify booleans
is(Mojo::JSON->true, 1, 'right value');
is(Mojo::JSON->false, 0, 'right value');
# Booleans in different contexts
is(true, 1, 'right string value');
is(true + 0, 1, 'right numeric value');
is(false, 0, 'right string value');
is(false + 0, 0, 'right numeric value');

# Upgraded numbers
my $num = 3;
Expand Down

0 comments on commit 752656b

Please sign in to comment.