This repository has been archived by the owner on Jun 1, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Silence Gconvert -Wunused-result. Add unblessed_bool property (PR #118 by Pali) Add seperate allow_dupkeys property, in relaxed (#122), Fixed allow_dupkeys for the XS slow path, Silence 2 -Wunused-value warnings, Fix ->unblessed_bool to produce modifiable perl structures (PR #121 by Pali).
- Loading branch information
Showing
9 changed files
with
155 additions
and
22 deletions.
There are no files selected for viewing
Submodule .git-rr-cache
updated
10 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,38 @@ | ||
use Test::More tests => 4; | ||
use strict; | ||
use Test::More tests => 9; | ||
use Cpanel::JSON::XS; | ||
|
||
my $json = Cpanel::JSON::XS->new; | ||
|
||
# disallow dupkeys: | ||
# disallow dupkeys | ||
ok (!eval { $json->decode ('{"a":"b","a":"c"}') }); # y_object_duplicated_key.json | ||
ok (!eval { $json->decode ('{"a":"b","a":"b"}') }); # y_object_duplicated_key_and_value.json | ||
|
||
# relaxed allows dupkeys | ||
$json->relaxed; | ||
is (encode_json ($json->decode ('{"a":"b","a":"c"}')), '{"a":"c"}'); # y_object_duplicated_key.json | ||
is (encode_json ($json->decode ('{"a":"b","a":"b"}')), '{"a":"b"}'); # y_object_duplicated_key_and_value.json | ||
# y_object_duplicated_key.json | ||
is (encode_json ($json->decode ('{"a":"b","a":"c"}')), '{"a":"c"}', 'relaxed'); | ||
# y_object_duplicated_key_and_value.json | ||
is (encode_json ($json->decode ('{"a":"b","a":"b"}')), '{"a":"b"}', 'relaxed'); | ||
|
||
# turning off relaxed disallows dupkeys | ||
$json->relaxed(0); | ||
$json->allow_dupkeys; # but turn it on | ||
is (encode_json ($json->decode ('{"a":"b","a":"c"}')), '{"a":"c"}', 'allow_dupkeys'); | ||
is (encode_json ($json->decode ('{"a":"b","a":"b"}')), '{"a":"b"}', 'allow_dupkeys'); | ||
|
||
# disallow dupkeys explicitly | ||
$json->allow_dupkeys(0); | ||
eval { $json->decode ('{"a":"b","a":"c"}') }; | ||
like ($@, qr/^Duplicate keys not allowed/, 'allow_dupkeys(0)'); | ||
|
||
# disallow dupkeys explicitly with relaxed | ||
$json->relaxed; | ||
$json->allow_dupkeys(0); | ||
eval { $json->decode ('{"a":"b","a":"c"}') }; # the XS slow path | ||
like ($@, qr/^Duplicate keys not allowed/, 'relaxed and allow_dupkeys(0)'); | ||
|
||
$json->allow_dupkeys; | ||
$json->relaxed(0); # tuning off relaxed needs to turn off dupkeys | ||
eval { $json->decode ('{"a":"b","a":"c"}') }; | ||
like ($@, qr/^Duplicate keys not allowed/, 'relaxed(0)'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters