xref: /php-src/ext/gmp/tests/gmp_strval.phpt (revision e9f783fc)
1--TEST--
2gmp_strval() tests
3--EXTENSIONS--
4gmp
5--FILE--
6<?php
7
8try {
9    var_dump(gmp_strval(""));
10} catch (\ValueError $e) {
11    echo $e->getMessage() . \PHP_EOL;
12}
13try {
14    var_dump(gmp_strval("", -1));
15} catch (\ValueError $e) {
16    echo $e->getMessage() . \PHP_EOL;
17}
18
19$fp = fopen(__FILE__, "r");
20try {
21    var_dump(gmp_strval($fp));
22} catch (\TypeError $e) {
23    echo $e->getMessage() . \PHP_EOL;
24}
25
26$g = gmp_init("9765456");
27var_dump(gmp_strval($g));
28try {
29    var_dump(gmp_strval($g, -1));
30} catch (\ValueError $e) {
31    echo $e->getMessage() . \PHP_EOL;
32}
33try {
34    var_dump(gmp_strval($g, 100000));
35} catch (\ValueError $e) {
36    echo $e->getMessage() . \PHP_EOL;
37}
38var_dump(gmp_strval($g, 10));
39
40$g = gmp_init("-3373333");
41var_dump(gmp_strval($g));
42try {
43    var_dump(gmp_strval($g, -1));
44} catch (\ValueError $e) {
45    echo $e->getMessage() . \PHP_EOL;
46}
47try {
48    var_dump(gmp_strval($g, 100000));
49} catch (\ValueError $e) {
50    echo $e->getMessage() . \PHP_EOL;
51}
52var_dump(gmp_strval($g, 10));
53
54try {
55    var_dump(gmp_strval(array(1,2)));
56} catch (\TypeError $e) {
57    echo $e->getMessage() . \PHP_EOL;
58}
59try {
60    var_dump(gmp_strval(new stdclass));
61} catch (\TypeError $e) {
62    echo $e->getMessage() . \PHP_EOL;
63}
64
65echo "Done\n";
66?>
67--EXPECT--
68gmp_strval(): Argument #1 ($num) is not an integer string
69gmp_strval(): Argument #2 ($base) must be between 2 and 62, or -2 and -36
70gmp_strval(): Argument #1 ($num) must be of type GMP|string|int, resource given
71string(7) "9765456"
72gmp_strval(): Argument #2 ($base) must be between 2 and 62, or -2 and -36
73gmp_strval(): Argument #2 ($base) must be between 2 and 62, or -2 and -36
74string(7) "9765456"
75string(8) "-3373333"
76gmp_strval(): Argument #2 ($base) must be between 2 and 62, or -2 and -36
77gmp_strval(): Argument #2 ($base) must be between 2 and 62, or -2 and -36
78string(8) "-3373333"
79gmp_strval(): Argument #1 ($num) must be of type GMP|string|int, array given
80gmp_strval(): Argument #1 ($num) must be of type GMP|string|int, stdClass given
81Done
82