Add function to get next strpos of any of a specified set of needles
This commit is contained in:
@ -706,4 +706,41 @@ final class MD_STD_Test extends TestCase {
|
||||
self::assertEquals("en", MD_STD::get_user_lang_no_cookie(["de", "en"], "en"));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for returning a tmp file.
|
||||
*
|
||||
* @return array<string, array{0: non-empty-string, 1: non-empty-array<non-empty-string>, 2: int}>
|
||||
*/
|
||||
public static function strpos_multi_provider():array {
|
||||
|
||||
return [
|
||||
"Search quotation markes on when='" => ["when='", ['"', '\''], 5],
|
||||
"Search quotation markes on when=\"" => ["when=\"", ['"', '\''], 5],
|
||||
"Search quotation markes on when=\"'" => ["when=\"'", ['"', '\''], 5],
|
||||
"Search quotation markes on when= (non-existent)" => ["when=", ['"', '\''], -1],
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks unlink_if_exists works.
|
||||
*
|
||||
* @param non-empty-string $haystack Haystack.
|
||||
* @param non-empty-array<non-empty-string> $needles Needles.
|
||||
* @param integer $expected Expected position.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
#[DataProvider('strpos_multi_provider')]
|
||||
public function test_strpos_multi(string $haystack, array $needles, int $expected):void {
|
||||
|
||||
if ($expected === -1) {
|
||||
self::assertEmpty(MD_STD::strpos_multi($haystack, $needles));
|
||||
}
|
||||
else {
|
||||
self::assertEquals($expected, MD_STD::strpos_multi($haystack, $needles)['position']);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user