mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
ext/gmp: Add behavioural tests for operator overloading
This commit is contained in:
parent
f9453a889d
commit
fe02fd5095
11 changed files with 1073 additions and 0 deletions
53
ext/gmp/tests/overloading_cmp_op_with_null.phpt
Normal file
53
ext/gmp/tests/overloading_cmp_op_with_null.phpt
Normal file
|
@ -0,0 +1,53 @@
|
|||
--TEST--
|
||||
GMP comparison operator overloading supports null
|
||||
--EXTENSIONS--
|
||||
gmp
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$num = gmp_init(42);
|
||||
|
||||
try {
|
||||
var_dump($num < null);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num > null);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num <= null);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num >= null);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num == null);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num <=> null);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
bool(false)
|
||||
bool(true)
|
||||
bool(false)
|
||||
bool(true)
|
||||
bool(false)
|
||||
int(1)
|
93
ext/gmp/tests/overloading_with_array.phpt
Normal file
93
ext/gmp/tests/overloading_with_array.phpt
Normal file
|
@ -0,0 +1,93 @@
|
|||
--TEST--
|
||||
GMP operator overloading does not support []
|
||||
--EXTENSIONS--
|
||||
gmp
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$num = gmp_init(42);
|
||||
|
||||
try {
|
||||
var_dump($num + []);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num - []);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num * []);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num / []);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num % []);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num ** []);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num | []);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num & []);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num ^ []);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num << []);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num >> []);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
TypeError: Number must be of type GMP|string|int, array given
|
||||
TypeError: Number must be of type GMP|string|int, array given
|
||||
TypeError: Number must be of type GMP|string|int, array given
|
||||
TypeError: Number must be of type GMP|string|int, array given
|
||||
TypeError: Number must be of type GMP|string|int, array given
|
||||
object(GMP)#3 (1) {
|
||||
["num"]=>
|
||||
string(1) "1"
|
||||
}
|
||||
TypeError: Number must be of type GMP|string|int, array given
|
||||
TypeError: Number must be of type GMP|string|int, array given
|
||||
TypeError: Number must be of type GMP|string|int, array given
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(2) "42"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(2) "42"
|
||||
}
|
117
ext/gmp/tests/overloading_with_float.phpt
Normal file
117
ext/gmp/tests/overloading_with_float.phpt
Normal file
|
@ -0,0 +1,117 @@
|
|||
--TEST--
|
||||
GMP operator overloading does support float with no fractional
|
||||
--EXTENSIONS--
|
||||
gmp
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$num = gmp_init(42);
|
||||
|
||||
try {
|
||||
var_dump($num + 42.0);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num - 42.0);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num * 42.0);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num / 42.0);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num % 42.0);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num ** 42.0);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num | 42.0);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num & 42.0);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num ^ 42.0);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num << 42.0);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num >> 42.0);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(2) "84"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(1) "0"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(4) "1764"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(1) "1"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(1) "0"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(69) "150130937545296572356771972164254457814047970568738777235893533016064"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(2) "42"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(2) "42"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(1) "0"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(15) "184717953466368"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(1) "0"
|
||||
}
|
132
ext/gmp/tests/overloading_with_float_fractional.phpt
Normal file
132
ext/gmp/tests/overloading_with_float_fractional.phpt
Normal file
|
@ -0,0 +1,132 @@
|
|||
--TEST--
|
||||
GMP operator overloading support for float with fractional is deprecated
|
||||
--EXTENSIONS--
|
||||
gmp
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$num = gmp_init(42);
|
||||
|
||||
try {
|
||||
var_dump($num + 42.5);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num - 42.5);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num * 42.5);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num / 42.5);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num % 42.5);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num ** 42.5);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num | 42.5);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num & 42.5);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num ^ 42.5);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num << 42.5);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num >> 42.5);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Deprecated: Implicit conversion from float 42.5 to int loses precision in %s on line %d
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(2) "84"
|
||||
}
|
||||
|
||||
Deprecated: Implicit conversion from float 42.5 to int loses precision in %s on line %d
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(1) "0"
|
||||
}
|
||||
|
||||
Deprecated: Implicit conversion from float 42.5 to int loses precision in %s on line %d
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(4) "1764"
|
||||
}
|
||||
|
||||
Deprecated: Implicit conversion from float 42.5 to int loses precision in %s on line %d
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(1) "1"
|
||||
}
|
||||
|
||||
Deprecated: Implicit conversion from float 42.5 to int loses precision in %s on line %d
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(1) "0"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(69) "150130937545296572356771972164254457814047970568738777235893533016064"
|
||||
}
|
||||
|
||||
Deprecated: Implicit conversion from float 42.5 to int loses precision in %s on line %d
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(2) "42"
|
||||
}
|
||||
|
||||
Deprecated: Implicit conversion from float 42.5 to int loses precision in %s on line %d
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(2) "42"
|
||||
}
|
||||
|
||||
Deprecated: Implicit conversion from float 42.5 to int loses precision in %s on line %d
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(1) "0"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(15) "184717953466368"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(1) "0"
|
||||
}
|
93
ext/gmp/tests/overloading_with_float_string.phpt
Normal file
93
ext/gmp/tests/overloading_with_float_string.phpt
Normal file
|
@ -0,0 +1,93 @@
|
|||
--TEST--
|
||||
GMP operator overloading does not support float strings
|
||||
--EXTENSIONS--
|
||||
gmp
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$num = gmp_init(42);
|
||||
|
||||
try {
|
||||
var_dump($num + "2.0");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num - "2.0");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num * "2.0");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num / "2.0");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num % "2.0");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num ** "2.0");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num | "2.0");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num & "2.0");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num ^ "2.0");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num << "2.0");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num >> "2.0");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
ValueError: Number is not an integer string
|
||||
ValueError: Number is not an integer string
|
||||
ValueError: Number is not an integer string
|
||||
ValueError: Number is not an integer string
|
||||
ValueError: Number is not an integer string
|
||||
object(GMP)#3 (1) {
|
||||
["num"]=>
|
||||
string(4) "1764"
|
||||
}
|
||||
ValueError: Number is not an integer string
|
||||
ValueError: Number is not an integer string
|
||||
ValueError: Number is not an integer string
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(3) "168"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(2) "10"
|
||||
}
|
117
ext/gmp/tests/overloading_with_int_string.phpt
Normal file
117
ext/gmp/tests/overloading_with_int_string.phpt
Normal file
|
@ -0,0 +1,117 @@
|
|||
--TEST--
|
||||
GMP operator overloading does support int strings
|
||||
--EXTENSIONS--
|
||||
gmp
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$num = gmp_init(42);
|
||||
|
||||
try {
|
||||
var_dump($num + "2");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num - "2");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num * "2");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num / "2");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num % "2");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num ** "2");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num | "2");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num & "2");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num ^ "2");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num << "2");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num >> "2");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(2) "44"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(2) "40"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(2) "84"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(2) "21"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(1) "0"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(4) "1764"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(2) "42"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(1) "2"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(2) "40"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(3) "168"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(2) "10"
|
||||
}
|
93
ext/gmp/tests/overloading_with_non_numeric_string.phpt
Normal file
93
ext/gmp/tests/overloading_with_non_numeric_string.phpt
Normal file
|
@ -0,0 +1,93 @@
|
|||
--TEST--
|
||||
GMP operator overloading does not support non-numeric strings
|
||||
--EXTENSIONS--
|
||||
gmp
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$num = gmp_init(42);
|
||||
|
||||
try {
|
||||
var_dump($num + "string");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num - "string");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num * "string");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num / "string");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num % "string");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num ** "string");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num | "string");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num & "string");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num ^ "string");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num << "string");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num >> "string");
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
ValueError: Number is not an integer string
|
||||
ValueError: Number is not an integer string
|
||||
ValueError: Number is not an integer string
|
||||
ValueError: Number is not an integer string
|
||||
ValueError: Number is not an integer string
|
||||
object(GMP)#3 (1) {
|
||||
["num"]=>
|
||||
string(1) "1"
|
||||
}
|
||||
ValueError: Number is not an integer string
|
||||
ValueError: Number is not an integer string
|
||||
ValueError: Number is not an integer string
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(2) "42"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(2) "42"
|
||||
}
|
76
ext/gmp/tests/overloading_with_null.phpt
Normal file
76
ext/gmp/tests/overloading_with_null.phpt
Normal file
|
@ -0,0 +1,76 @@
|
|||
--TEST--
|
||||
GMP operator overloading does not support null
|
||||
--EXTENSIONS--
|
||||
gmp
|
||||
--XFAIL--
|
||||
Test showcasing segfaulting behaviour
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$num = gmp_init(42);
|
||||
|
||||
try {
|
||||
var_dump($num + null);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num - null);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num * null);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num / null);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num % null);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num ** null);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num | null);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num & null);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num ^ null);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num << null);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num >> null);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
SEGFAULT
|
100
ext/gmp/tests/overloading_with_object_not_stringable.phpt
Normal file
100
ext/gmp/tests/overloading_with_object_not_stringable.phpt
Normal file
|
@ -0,0 +1,100 @@
|
|||
--TEST--
|
||||
GMP operator overloading does not support non-stringable objects
|
||||
--EXTENSIONS--
|
||||
gmp
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$num = gmp_init(42);
|
||||
$o = new stdClass();
|
||||
|
||||
try {
|
||||
var_dump($num + $o);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num - $o);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num * $o);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num / $o);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num % $o);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num ** $o);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num | $o);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num & $o);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num ^ $o);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num << $o);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num >> $o);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
TypeError: Number must be of type GMP|string|int, stdClass given
|
||||
TypeError: Number must be of type GMP|string|int, stdClass given
|
||||
TypeError: Number must be of type GMP|string|int, stdClass given
|
||||
TypeError: Number must be of type GMP|string|int, stdClass given
|
||||
TypeError: Number must be of type GMP|string|int, stdClass given
|
||||
|
||||
Warning: Object of class stdClass could not be converted to int in %s on line %d
|
||||
object(GMP)#4 (1) {
|
||||
["num"]=>
|
||||
string(2) "42"
|
||||
}
|
||||
TypeError: Number must be of type GMP|string|int, stdClass given
|
||||
TypeError: Number must be of type GMP|string|int, stdClass given
|
||||
TypeError: Number must be of type GMP|string|int, stdClass given
|
||||
|
||||
Warning: Object of class stdClass could not be converted to int in %s on line %d
|
||||
object(GMP)#3 (1) {
|
||||
["num"]=>
|
||||
string(2) "84"
|
||||
}
|
||||
|
||||
Warning: Object of class stdClass could not be converted to int in %s on line %d
|
||||
object(GMP)#3 (1) {
|
||||
["num"]=>
|
||||
string(2) "21"
|
||||
}
|
106
ext/gmp/tests/overloading_with_object_stringable.phpt
Normal file
106
ext/gmp/tests/overloading_with_object_stringable.phpt
Normal file
|
@ -0,0 +1,106 @@
|
|||
--TEST--
|
||||
GMP operator overloading does not support stringable objects
|
||||
--EXTENSIONS--
|
||||
gmp
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class T {
|
||||
public function __toString() {
|
||||
return "42";
|
||||
}
|
||||
}
|
||||
|
||||
$num = gmp_init(42);
|
||||
$o = new T();
|
||||
|
||||
try {
|
||||
var_dump($num + $o);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num - $o);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num * $o);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num / $o);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num % $o);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num ** $o);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num | $o);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num & $o);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num ^ $o);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num << $o);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num >> $o);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
TypeError: Number must be of type GMP|string|int, T given
|
||||
TypeError: Number must be of type GMP|string|int, T given
|
||||
TypeError: Number must be of type GMP|string|int, T given
|
||||
TypeError: Number must be of type GMP|string|int, T given
|
||||
TypeError: Number must be of type GMP|string|int, T given
|
||||
|
||||
Warning: Object of class T could not be converted to int in %s on line %d
|
||||
object(GMP)#4 (1) {
|
||||
["num"]=>
|
||||
string(2) "42"
|
||||
}
|
||||
TypeError: Number must be of type GMP|string|int, T given
|
||||
TypeError: Number must be of type GMP|string|int, T given
|
||||
TypeError: Number must be of type GMP|string|int, T given
|
||||
|
||||
Warning: Object of class T could not be converted to int in %s on line %d
|
||||
object(GMP)#3 (1) {
|
||||
["num"]=>
|
||||
string(2) "84"
|
||||
}
|
||||
|
||||
Warning: Object of class T could not be converted to int in %s on line %d
|
||||
object(GMP)#3 (1) {
|
||||
["num"]=>
|
||||
string(2) "21"
|
||||
}
|
93
ext/gmp/tests/overloading_with_resource.phpt
Normal file
93
ext/gmp/tests/overloading_with_resource.phpt
Normal file
|
@ -0,0 +1,93 @@
|
|||
--TEST--
|
||||
GMP operator overloading does not support resources
|
||||
--EXTENSIONS--
|
||||
gmp
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$num = gmp_init(42);
|
||||
|
||||
try {
|
||||
var_dump($num + STDERR);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num - STDERR);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num * STDERR);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num / STDERR);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num % STDERR);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num ** STDERR);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump($num | STDERR);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num & STDERR);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num ^ STDERR);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num << STDERR);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
try {
|
||||
var_dump($num >> STDERR);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
TypeError: Number must be of type GMP|string|int, resource given
|
||||
TypeError: Number must be of type GMP|string|int, resource given
|
||||
TypeError: Number must be of type GMP|string|int, resource given
|
||||
TypeError: Number must be of type GMP|string|int, resource given
|
||||
TypeError: Number must be of type GMP|string|int, resource given
|
||||
object(GMP)#3 (1) {
|
||||
["num"]=>
|
||||
string(5) "74088"
|
||||
}
|
||||
TypeError: Number must be of type GMP|string|int, resource given
|
||||
TypeError: Number must be of type GMP|string|int, resource given
|
||||
TypeError: Number must be of type GMP|string|int, resource given
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(3) "336"
|
||||
}
|
||||
object(GMP)#2 (1) {
|
||||
["num"]=>
|
||||
string(1) "5"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue