diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2022-07-19 16:24:00 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2022-07-19 16:24:00 +0900 |
commit | c7c962a282ca30e60db54b2a9786cd3478707d9d (patch) | |
tree | 1460f0008ae23f12bc39f08279fc3019adeb753e /t | |
parent | 80e2994434f3c840ce12546351ab9fd20cdd3aaa (diff) | |
download | perl-json-c7c962a282ca30e60db54b2a9786cd3478707d9d.tar.gz perl-json-c7c962a282ca30e60db54b2a9786cd3478707d9d.tar.bz2 perl-json-c7c962a282ca30e60db54b2a9786cd3478707d9d.zip |
Imported Upstream version 4.04upstream/4.04
Diffstat (limited to 't')
-rw-r--r-- | t/107_allow_singlequote.t | 2 | ||||
-rw-r--r-- | t/119_incr_parse_utf8.t | 77 | ||||
-rw-r--r-- | t/rt_122270_is_bool_for_obsolete_xs_boolean.t | 33 |
3 files changed, 111 insertions, 1 deletions
diff --git a/t/107_allow_singlequote.t b/t/107_allow_singlequote.t index c7bec6c..122c7b4 100644 --- a/t/107_allow_singlequote.t +++ b/t/107_allow_singlequote.t @@ -1,6 +1,6 @@ use Test::More;
-use strict;
+use strict; use warnings;
BEGIN { plan tests => 4 };
BEGIN { $ENV{PERL_JSON_BACKEND} ||= "JSON::backportPP"; }
diff --git a/t/119_incr_parse_utf8.t b/t/119_incr_parse_utf8.t new file mode 100644 index 0000000..182a5c6 --- /dev/null +++ b/t/119_incr_parse_utf8.t @@ -0,0 +1,77 @@ +use strict; +use warnings; +use Test::More tests => 24; + +use utf8; +BEGIN { $ENV{PERL_JSON_BACKEND} ||= "JSON::backportPP"; } + +use JSON; +use Encode; +use charnames qw< :full >; + +use vars qw< @vs >; + +############################################################ +### These first tests mimic the ones in `t/001_utf8.t` ### +############################################################ + +scalar eval { JSON->new->allow_nonref (1)->utf8 (1)->incr_parse ('"ü"') }; +like $@, qr/malformed UTF-8/; + +ok (JSON->new->allow_nonref (1)->incr_parse ('"ü"') eq "ü"); +ok (JSON->new->allow_nonref (1)->incr_parse ('"\u00fc"') eq "ü"); +ok (JSON->new->allow_nonref (1)->incr_parse ('"\ud801\udc02' . "\x{10204}\"") eq "\x{10402}\x{10204}"); +ok (JSON->new->allow_nonref (1)->incr_parse ('"\"\n\\\\\r\t\f\b"') eq "\"\012\\\015\011\014\010"); + + +my $JSON_TXT = <<JSON_TXT; +{ "a": "1" } +{ "b": "\N{BULLET}" } +{ "c": "3" } +JSON_TXT + +####################### +### With '->utf8' ### +####################### + +@vs = eval { JSON->new->utf8->incr_parse( $JSON_TXT ) }; +like $@, qr/Wide character in subroutine entry/; + + +@vs = eval { JSON->new->utf8->incr_parse( encode 'UTF-8' => $JSON_TXT ) }; + +ok( !$@ ); +ok( scalar @vs == 3 ); + +is_deeply( \@vs, [ { a => "1" }, { b => "\N{BULLET}" }, { c => "3" } ] ); +is_deeply( $vs[0], { a => "1" } ); +is_deeply( $vs[1], { b => "\N{BULLET}" } ); +is_deeply( $vs[2], { c => "3" } ); + + +# Double-Encoded => "You Get What You Ask For" + +@vs = eval { JSON->new->utf8->incr_parse( encode 'UTF-8' => ( encode 'UTF-8' => $JSON_TXT ) ) }; + +ok( !$@ ); +ok( scalar @vs == 3 ); + +is_deeply( \@vs, [ { a => "1" }, { b => "\x{E2}\x{80}\x{A2}" }, { c => "3" } ] ); +is_deeply( $vs[0], { a => "1" } ); +is_deeply( $vs[1], { b => "\x{E2}\x{80}\x{A2}" } ); +is_deeply( $vs[2], { c => "3" } ); + + +########################## +### Without '->utf8' ### +########################## + +@vs = eval { JSON->new->incr_parse( $JSON_TXT ) }; + +ok( !$@ ); +ok( scalar @vs == 3 ); + +is_deeply( \@vs, [ { a => "1" }, { b => "\N{BULLET}" }, { c => "3" } ] ); +is_deeply( $vs[0], { a => "1" } ); +is_deeply( $vs[1], { b => "\N{BULLET}" } ); +is_deeply( $vs[2], { c => "3" } ); diff --git a/t/rt_122270_is_bool_for_obsolete_xs_boolean.t b/t/rt_122270_is_bool_for_obsolete_xs_boolean.t new file mode 100644 index 0000000..64fad70 --- /dev/null +++ b/t/rt_122270_is_bool_for_obsolete_xs_boolean.t @@ -0,0 +1,33 @@ +# copied over from JSON::XS and modified to use JSON + +use strict; +use warnings; +use Test::More; +BEGIN { plan tests => 10 }; + +BEGIN { $ENV{PERL_JSON_BACKEND} ||= "JSON::backportPP"; } + +use utf8; +use JSON; + +SKIP: { + skip "no JSON::XS < 3", 5 unless eval { require JSON::XS; JSON::XS->VERSION < 3 }; + + my $false = JSON::XS::false(); + ok (JSON::is_bool $false); + ok (++$false == 1); + ok (!JSON::is_bool $false); + ok (!JSON::is_bool "JSON::Boolean"); + ok (!JSON::is_bool {}); # GH-34 +} + +SKIP: { + skip "no Types::Serialiser 0.01", 5 unless eval { require JSON::XS; JSON::XS->VERSION(3.00); require Types::Serialiser; Types::Serialiser->VERSION == 0.01 }; + + my $false = JSON::XS::false(); + ok (JSON::is_bool $false); + ok (++$false == 1); + ok (!JSON::is_bool $false); + ok (!JSON::is_bool "JSON::Boolean"); + ok (!JSON::is_bool {}); # GH-34 +} |