Skip to content

PHPC-2259: Sync BSON corpus tests for Decimal128 values with large exponents #1446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions tests/bson-corpus/decimal128-1-valid-057.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
--TEST--
Decimal128: Clamped zeros with a large positive exponent
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

DO NOT EDIT THIS FILE
--FILE--
<?php

require_once __DIR__ . '/../utils/basic.inc';

$canonicalBson = hex2bin('180000001364000000000000000000000000000000FE5F00');
$canonicalExtJson = '{"d" : {"$numberDecimal" : "0E+6111"}}';
$degenerateExtJson = '{"d" : {"$numberDecimal" : "0E+2147483647"}}';

// Canonical BSON -> Native -> Canonical BSON
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";

// Canonical BSON -> BSON object -> Canonical BSON
echo bin2hex((string) MongoDB\BSON\Document::fromBSON($canonicalBson)), "\n";

// Canonical BSON -> Canonical extJSON
echo json_canonicalize(toCanonicalExtendedJSON($canonicalBson)), "\n";

// Canonical BSON -> BSON object -> Canonical extJSON
echo json_canonicalize(MongoDB\BSON\Document::fromBSON($canonicalBson)->toCanonicalExtendedJSON()), "\n";

// Canonical extJSON -> Canonical BSON
echo bin2hex(fromJSON($canonicalExtJson)), "\n";

// Canonical extJSON -> BSON object -> Canonical BSON
echo bin2hex((string) MongoDB\BSON\Document::fromJSON($canonicalExtJson)), "\n";

// Degenerate extJSON -> Canonical BSON
echo bin2hex(fromJSON($degenerateExtJson)), "\n";

// Degenerate extJSON -> BSON object -> Canonical BSON
echo bin2hex((string) MongoDB\BSON\Document::fromJSON($degenerateExtJson)), "\n";

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
180000001364000000000000000000000000000000fe5f00
180000001364000000000000000000000000000000fe5f00
{"d":{"$numberDecimal":"0E+6111"}}
{"d":{"$numberDecimal":"0E+6111"}}
180000001364000000000000000000000000000000fe5f00
180000001364000000000000000000000000000000fe5f00
180000001364000000000000000000000000000000fe5f00
180000001364000000000000000000000000000000fe5f00
===DONE===
52 changes: 52 additions & 0 deletions tests/bson-corpus/decimal128-1-valid-058.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
--TEST--
Decimal128: Clamped zeros with a large negative exponent
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

DO NOT EDIT THIS FILE
--FILE--
<?php

require_once __DIR__ . '/../utils/basic.inc';

$canonicalBson = hex2bin('180000001364000000000000000000000000000000000000');
$canonicalExtJson = '{"d" : {"$numberDecimal" : "0E-6176"}}';
$degenerateExtJson = '{"d" : {"$numberDecimal" : "0E-2147483647"}}';

// Canonical BSON -> Native -> Canonical BSON
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";

// Canonical BSON -> BSON object -> Canonical BSON
echo bin2hex((string) MongoDB\BSON\Document::fromBSON($canonicalBson)), "\n";

// Canonical BSON -> Canonical extJSON
echo json_canonicalize(toCanonicalExtendedJSON($canonicalBson)), "\n";

// Canonical BSON -> BSON object -> Canonical extJSON
echo json_canonicalize(MongoDB\BSON\Document::fromBSON($canonicalBson)->toCanonicalExtendedJSON()), "\n";

// Canonical extJSON -> Canonical BSON
echo bin2hex(fromJSON($canonicalExtJson)), "\n";

// Canonical extJSON -> BSON object -> Canonical BSON
echo bin2hex((string) MongoDB\BSON\Document::fromJSON($canonicalExtJson)), "\n";

// Degenerate extJSON -> Canonical BSON
echo bin2hex(fromJSON($degenerateExtJson)), "\n";

// Degenerate extJSON -> BSON object -> Canonical BSON
echo bin2hex((string) MongoDB\BSON\Document::fromJSON($degenerateExtJson)), "\n";

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
180000001364000000000000000000000000000000000000
180000001364000000000000000000000000000000000000
{"d":{"$numberDecimal":"0E-6176"}}
{"d":{"$numberDecimal":"0E-6176"}}
180000001364000000000000000000000000000000000000
180000001364000000000000000000000000000000000000
180000001364000000000000000000000000000000000000
180000001364000000000000000000000000000000000000
===DONE===
52 changes: 52 additions & 0 deletions tests/bson-corpus/decimal128-1-valid-059.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
--TEST--
Decimal128: Clamped negative zeros with a large positive exponent
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

DO NOT EDIT THIS FILE
--FILE--
<?php

require_once __DIR__ . '/../utils/basic.inc';

$canonicalBson = hex2bin('180000001364000000000000000000000000000000FEDF00');
$canonicalExtJson = '{"d" : {"$numberDecimal" : "-0E+6111"}}';
$degenerateExtJson = '{"d" : {"$numberDecimal" : "-0E+2147483647"}}';

// Canonical BSON -> Native -> Canonical BSON
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";

// Canonical BSON -> BSON object -> Canonical BSON
echo bin2hex((string) MongoDB\BSON\Document::fromBSON($canonicalBson)), "\n";

// Canonical BSON -> Canonical extJSON
echo json_canonicalize(toCanonicalExtendedJSON($canonicalBson)), "\n";

// Canonical BSON -> BSON object -> Canonical extJSON
echo json_canonicalize(MongoDB\BSON\Document::fromBSON($canonicalBson)->toCanonicalExtendedJSON()), "\n";

// Canonical extJSON -> Canonical BSON
echo bin2hex(fromJSON($canonicalExtJson)), "\n";

// Canonical extJSON -> BSON object -> Canonical BSON
echo bin2hex((string) MongoDB\BSON\Document::fromJSON($canonicalExtJson)), "\n";

// Degenerate extJSON -> Canonical BSON
echo bin2hex(fromJSON($degenerateExtJson)), "\n";

// Degenerate extJSON -> BSON object -> Canonical BSON
echo bin2hex((string) MongoDB\BSON\Document::fromJSON($degenerateExtJson)), "\n";

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
180000001364000000000000000000000000000000fedf00
180000001364000000000000000000000000000000fedf00
{"d":{"$numberDecimal":"-0E+6111"}}
{"d":{"$numberDecimal":"-0E+6111"}}
180000001364000000000000000000000000000000fedf00
180000001364000000000000000000000000000000fedf00
180000001364000000000000000000000000000000fedf00
180000001364000000000000000000000000000000fedf00
===DONE===
52 changes: 52 additions & 0 deletions tests/bson-corpus/decimal128-1-valid-060.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
--TEST--
Decimal128: Clamped negative zeros with a large negative exponent
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

DO NOT EDIT THIS FILE
--FILE--
<?php

require_once __DIR__ . '/../utils/basic.inc';

$canonicalBson = hex2bin('180000001364000000000000000000000000000000008000');
$canonicalExtJson = '{"d" : {"$numberDecimal" : "-0E-6176"}}';
$degenerateExtJson = '{"d" : {"$numberDecimal" : "-0E-2147483647"}}';

// Canonical BSON -> Native -> Canonical BSON
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";

// Canonical BSON -> BSON object -> Canonical BSON
echo bin2hex((string) MongoDB\BSON\Document::fromBSON($canonicalBson)), "\n";

// Canonical BSON -> Canonical extJSON
echo json_canonicalize(toCanonicalExtendedJSON($canonicalBson)), "\n";

// Canonical BSON -> BSON object -> Canonical extJSON
echo json_canonicalize(MongoDB\BSON\Document::fromBSON($canonicalBson)->toCanonicalExtendedJSON()), "\n";

// Canonical extJSON -> Canonical BSON
echo bin2hex(fromJSON($canonicalExtJson)), "\n";

// Canonical extJSON -> BSON object -> Canonical BSON
echo bin2hex((string) MongoDB\BSON\Document::fromJSON($canonicalExtJson)), "\n";

// Degenerate extJSON -> Canonical BSON
echo bin2hex(fromJSON($degenerateExtJson)), "\n";

// Degenerate extJSON -> BSON object -> Canonical BSON
echo bin2hex((string) MongoDB\BSON\Document::fromJSON($degenerateExtJson)), "\n";

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
180000001364000000000000000000000000000000008000
180000001364000000000000000000000000000000008000
{"d":{"$numberDecimal":"-0E-6176"}}
{"d":{"$numberDecimal":"-0E-6176"}}
180000001364000000000000000000000000000000008000
180000001364000000000000000000000000000000008000
180000001364000000000000000000000000000000008000
180000001364000000000000000000000000000000008000
===DONE===