xref: /PHP-8.0/ext/spl/tests/bug66702.phpt (revision 7aacc705)
1--TEST--
2Bug #66702 (RegexIterator inverted result works as expected)
3--FILE--
4<?php
5/**
6 * @author Joshua Thijssen <jthijssen+php@noxlogic.nl>
7 */
8
9$it = new \ArrayIterator(array("foo", "bar", "baz"));
10$it2 = new \RegexIterator($it, "/^ba/", \RegexIterator::MATCH);
11print_r(iterator_to_array($it2));
12$it2 = new \RegexIterator($it, "/^ba/", \RegexIterator::MATCH, \RegexIterator::INVERT_MATCH);
13print_r(iterator_to_array($it2));
14
15$it = new \ArrayIterator(array("foo" => 1, "bar" => 2, "baz" => 3));
16$it2 = new \RegexIterator($it, "/^ba/", \RegexIterator::MATCH, \RegexIterator::USE_KEY);
17print_r(iterator_to_array($it2));
18$it2 = new \RegexIterator($it, "/^ba/", \RegexIterator::MATCH, \RegexIterator::USE_KEY | \RegexIterator::INVERT_MATCH);
19print_r(iterator_to_array($it2));
20?>
21--EXPECT--
22Array
23(
24    [1] => bar
25    [2] => baz
26)
27Array
28(
29    [0] => foo
30)
31Array
32(
33    [bar] => 2
34    [baz] => 3
35)
36Array
37(
38    [foo] => 1
39)
40