summaryrefslogtreecommitdiff
path: root/cpan/JSON-PP/t/119_incr_parse_utf8.t
diff options
context:
space:
mode:
authorKenichi Ishigaki <ishigaki@cpan.org>2022-06-27 14:33:15 +0000
committerJames E Keenan <jkeenan@cpan.org>2022-06-27 14:33:15 +0000
commit602e63aa36686ad5cfa326a1b2f20721af9b1ce0 (patch)
tree905095e58c83adf59922f2c6dc779e772debfa62 /cpan/JSON-PP/t/119_incr_parse_utf8.t
parent36540e72e5ebd2d98e8833f34b1b25b20553e7cd (diff)
downloadperl-602e63aa36686ad5cfa326a1b2f20721af9b1ce0.tar.gz
JSON-PP: Sync with CPAN version 4.10
From Changes: 4.10 2022-06-24 - fix a regression of decode_error introduced at 4.08 (GH#75, reported by andk++) - convert all tests to use Test::More (GH#70, haarg++) 4.09 2022-05-22 - reverted core boolean support for now (GH#72) - incr_parse() Hangs on Certain Inputs (GH#67, DabeDotCom++) - silence warnings about non-characters on older perls (GH#68, haarg++) 4.08 2022-04-10 - remove unneeded utf8::upgrade and downgrade (GH#59, FGasper++) - core boolean support (GH#62, 63, haarg++) - EBCDIC support (GH#64, khwilliamson++) - shorten a test name (GH#65, khwilliamson)
Diffstat (limited to 'cpan/JSON-PP/t/119_incr_parse_utf8.t')
-rw-r--r--cpan/JSON-PP/t/119_incr_parse_utf8.t75
1 files changed, 75 insertions, 0 deletions
diff --git a/cpan/JSON-PP/t/119_incr_parse_utf8.t b/cpan/JSON-PP/t/119_incr_parse_utf8.t
new file mode 100644
index 0000000000..90916fbbe2
--- /dev/null
+++ b/cpan/JSON-PP/t/119_incr_parse_utf8.t
@@ -0,0 +1,75 @@
+use strict;
+use warnings;
+use Test::More tests => 24;
+
+use utf8;
+use JSON::PP;
+use Encode;
+use charnames qw< :full >;
+
+use vars qw< @vs >;
+
+############################################################
+### These first tests mimic the ones in `t/001_utf8.t` ###
+############################################################
+
+scalar eval { JSON::PP->new->allow_nonref (1)->utf8 (1)->incr_parse ('"ü"') };
+like $@, qr/malformed UTF-8/;
+
+ok (JSON::PP->new->allow_nonref (1)->incr_parse ('"ü"') eq "ü");
+ok (JSON::PP->new->allow_nonref (1)->incr_parse ('"\u00fc"') eq "ü");
+ok (JSON::PP->new->allow_nonref (1)->incr_parse ('"\ud801\udc02' . "\x{10204}\"") eq "\x{10402}\x{10204}");
+ok (JSON::PP->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::PP->new->utf8->incr_parse( $JSON_TXT ) };
+like $@, qr/Wide character in subroutine entry/;
+
+
+@vs = eval { JSON::PP->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::PP->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::PP->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" } );