1--TEST--
2mb_ereg_search_setpos() function
3--SKIPIF--
4<?php
5if (!extension_loaded('mbstring')) die('skip mbstring not enabled');
6if (!function_exists("mb_regex_encoding")) die("skip mb_regex_encoding() is not defined");
7?>
8--FILE--
9<?php
10mb_regex_encoding('iso-8859-1');
11$test_str = 'I�t�rn�ti�n�liz�ti�n'; // Length = 20
12
13var_dump(mb_ereg_search_setpos(50)); // OK
14try {
15    var_dump(mb_ereg_search_setpos(-1)); // Error
16} catch (\ValueError $e) {
17    echo $e->getMessage() . \PHP_EOL;
18}
19
20mb_ereg_search_init($test_str);
21
22$positions = array( 5, 20, 21, 25, 0, -5, -20, -30);
23foreach($positions as $pos) {
24    echo("\n* Position: $pos :\n");
25    try {
26        var_dump(mb_ereg_search_setpos($pos));
27    } catch (\ValueError $e) {
28        echo $e->getMessage() . \PHP_EOL;
29    }
30    try {
31        var_dump(mb_ereg_search_getpos());
32    } catch (\ValueError $e) {
33        echo $e->getMessage() . \PHP_EOL;
34    }
35}
36?>
37--EXPECT--
38bool(true)
39mb_ereg_search_setpos(): Argument #1 ($offset) is out of range
40
41* Position: 5 :
42bool(true)
43int(5)
44
45* Position: 20 :
46bool(true)
47int(20)
48
49* Position: 21 :
50mb_ereg_search_setpos(): Argument #1 ($offset) is out of range
51int(20)
52
53* Position: 25 :
54mb_ereg_search_setpos(): Argument #1 ($offset) is out of range
55int(20)
56
57* Position: 0 :
58bool(true)
59int(0)
60
61* Position: -5 :
62bool(true)
63int(15)
64
65* Position: -20 :
66bool(true)
67int(0)
68
69* Position: -30 :
70mb_ereg_search_setpos(): Argument #1 ($offset) is out of range
71int(0)
72