CParser::PARSE_SUCCESS, 'match' => ' ', 'macros' => [] ] ], [ ' a ', 0, [], [ 'rc' => CParser::PARSE_SUCCESS, 'match' => ' a ', 'macros' => [] ] ], [ ' abc{#ABC}def~!@#$%^&*()[]-_+={};:\'"?<>', 0, [], [ 'rc' => CParser::PARSE_SUCCESS, 'match' => ' abc{#ABC}def~!@#$%^&*()[]-_+={};:\'"?<>', 'macros' => [] ] ], [ '/abc{#ABC}//def~!@#$%^&*()[]-_+={};:\'"?<>|\\', 12, [], [ 'rc' => CParser::PARSE_SUCCESS, 'match' => 'def~!@#$%^&*()[]-_+={};:\'"?<>|\\', 'macros' => [] ] ], [ ' a{#B}c ', 0, ['lldmacros' => true], [ 'rc' => CParser::PARSE_SUCCESS, 'match' => ' a{#B}c ', 'macros' => ['{#B}'] ] ], [ ' a{#B}c / {#D}e/f ', 0, ['lldmacros' => true], [ 'rc' => CParser::PARSE_SUCCESS, 'match' => ' a{#B}c / {#D}e/f ', 'macros' => ['{#B}', '{#D}'] ] ], [ ' a{#B}{{#C}.regsub("^([0-9]+)", "{#C}: \1")}{#D}/e ', 0, ['lldmacros' => true], [ 'rc' => CParser::PARSE_SUCCESS, 'match' => ' a{#B}{{#C}.regsub("^([0-9]+)", "{#C}: \1")}{#D}/e ', 'macros' => ['{#B}', '{{#C}.regsub("^([0-9]+)", "{#C}: \1")}', '{#D}'] ] ], [ ' a{#B}{{#C}.regsub("^([0-9]+\/[A-Za-z])", "{#C}: \1")}{#D}/e ', 0, ['lldmacros' => true], [ 'rc' => CParser::PARSE_SUCCESS, 'match' => ' a{#B}{{#C}.regsub("^([0-9]+\/[A-Za-z])", "{#C}: \1")}{#D}/e ', 'macros' => ['{#B}', '{{#C}.regsub("^([0-9]+\/[A-Za-z])", "{#C}: \1")}', '{#D}'] ] ], [ '{#A}/{#B}/{#C}/{{#D}.regsub()}', 0, ['lldmacros' => true], [ 'rc' => CParser::PARSE_SUCCESS, 'match' => '{#A}/{#B}/{#C}/{{#D}.regsub()}', 'macros' => ['{#A}', '{#B}', '{#C}', '{{#D}.regsub()}'] ] ], // partial success [ ' /', 0, [], [ 'rc' => CParser::PARSE_SUCCESS_CONT, 'match' => ' ', 'macros' => [] ] ], [ ' abc// edf', 0, [], [ 'rc' => CParser::PARSE_SUCCESS_CONT, 'match' => ' abc', 'macros' => [] ] ], [ 'abc /', 0, [], [ 'rc' => CParser::PARSE_SUCCESS_CONT, 'match' => 'abc ', 'macros' => [] ] ], [ 'abc/def/ghi/', 0, [], [ 'rc' => CParser::PARSE_SUCCESS_CONT, 'match' => 'abc/def/ghi', 'macros' => [] ] ], [ 'abc/def/ghi// ', 0, [], [ 'rc' => CParser::PARSE_SUCCESS_CONT, 'match' => 'abc/def/ghi', 'macros' => [] ] ], [ 'abc / def // ghi // ', 0, [], [ 'rc' => CParser::PARSE_SUCCESS_CONT, 'match' => 'abc / def ', 'macros' => [] ] ], [ 'abc/def/{#GHI}/', 0, [], [ 'rc' => CParser::PARSE_SUCCESS_CONT, 'match' => 'abc/def/{#GHI}', 'macros' => [] ] ], [ 'abc/def/{#GHI}/{#JKL}/', 0, ['lldmacros' => true], [ 'rc' => CParser::PARSE_SUCCESS_CONT, 'match' => 'abc/def/{#GHI}/{#JKL}', 'macros' => ['{#GHI}', '{#JKL}'] ] ], [ ' a / {#B}{{#C}.regsub("^([0-9]+)", "{#C}: \1")} ~!@#$%^&*()[]{};:\'"|\\ \/', 0, ['lldmacros' => true], [ 'rc' => CParser::PARSE_SUCCESS_CONT, 'match' => ' a / {#B}{{#C}.regsub("^([0-9]+)", "{#C}: \1")} ~!@#$%^&*()[]{};:\'"|\\ \\', 'macros' => ['{#B}', '{{#C}.regsub("^([0-9]+)", "{#C}: \1")}'] ] ], [ '{#A}/{#B}/{#C}//{{#D}.regsub()}', 0, ['lldmacros' => true], [ 'rc' => CParser::PARSE_SUCCESS_CONT, 'match' => '{#A}/{#B}/{#C}', 'macros' => ['{#A}', '{#B}', '{#C}'] ] ], // fail [ '', 0, [], [ 'rc' => CParser::PARSE_FAIL, 'match' => '', 'macros' => [] ] ], [ '/', 0, [], [ 'rc' => CParser::PARSE_FAIL, 'match' => '', 'macros' => [] ] ], [ '//', 0, [], [ 'rc' => CParser::PARSE_FAIL, 'match' => '', 'macros' => [] ] ], [ '/abc', 0, [], [ 'rc' => CParser::PARSE_FAIL, 'match' => '', 'macros' => [] ] ], [ '/ abc{#ABC}/', 0, ['lldmacros' => true], [ 'rc' => CParser::PARSE_FAIL, 'match' => '', 'macros' => [] ] ] ]; } /** * @dataProvider dataProvider * * @param string $source * @param int $pos * @param array $options * @param array $expected */ public function testParse($source, $pos, $options, $expected) { $parser = new CHostGroupNameParser($options); $this->assertSame($expected, [ 'rc' => $parser->parse($source, $pos), 'match' => $parser->getMatch(), 'macros' => $parser->getMacros() ]); $this->assertSame(strlen($expected['match']), $parser->getLength()); } }