CParser::PARSE_SUCCESS, 'match' => 'labelname123' ] ], [ 'labelname123', 8, [], [ 'rc' => CParser::PARSE_SUCCESS, 'match' => 'e123' ] ], [ '{$M}', 0, ['usermacros' => true], [ 'rc' => CParser::PARSE_SUCCESS, 'match' => '{$M}' ] ], [ '{$FS_MAX: "/home"}', 0, ['usermacros' => true], [ 'rc' => CParser::PARSE_SUCCESS, 'match' => '{$FS_MAX: "/home"}' ] ], [ '{#LLD}', 0, ['lldmacros' => true], [ 'rc' => CParser::PARSE_SUCCESS, 'match' => '{#LLD}' ] ], [ '{{#LLD_MACRO}.regsub("(.*)_([0-9]+)", \1)}', 0, ['lldmacros' => true], [ 'rc' => CParser::PARSE_SUCCESS, 'match' => '{{#LLD_MACRO}.regsub("(.*)_([0-9]+)", \1)}' ] ], // partial success [ 'label1=', 0, [], [ 'rc' => CParser::PARSE_SUCCESS_CONT, 'match' => 'label1' ] ], [ 'label1 ', 0, [], [ 'rc' => CParser::PARSE_SUCCESS_CONT, 'match' => 'label1' ] ], [ 'label1 ', 4, [], [ 'rc' => CParser::PARSE_SUCCESS_CONT, 'match' => 'l1' ] ], [ '{$MACRO} label1 ', 0, ['usermacros' => true], [ 'rc' => CParser::PARSE_SUCCESS_CONT, 'match' => '{$MACRO}' ] ], [ '{#LLD_MACRO} label1 ', 0, ['lldmacros' => true], [ 'rc' => CParser::PARSE_SUCCESS_CONT, 'match' => '{#LLD_MACRO}' ] ], [ '{{#LLD_MACRO}.regsub("(.*)_([0-9]+)", \1)} label1 ', 0, ['lldmacros' => true], [ 'rc' => CParser::PARSE_SUCCESS_CONT, 'match' => '{{#LLD_MACRO}.regsub("(.*)_([0-9]+)", \1)}' ] ], // fail [ '', 0, [], [ 'rc' => CParser::PARSE_FAIL, 'match' => '' ] ], [ '{', 0, [], [ 'rc' => CParser::PARSE_FAIL, 'match' => '' ] ], [ '0', 0, [], [ 'rc' => CParser::PARSE_FAIL, 'match' => '' ] ], [ '09label', 0, [], [ 'rc' => CParser::PARSE_FAIL, 'match' => '' ] ], [ 'label123', 5, [], [ 'rc' => CParser::PARSE_FAIL, 'match' => '' ] ], // User macros not enabled. [ '{$M}', 0, [], [ 'rc' => CParser::PARSE_FAIL, 'match' => '' ] ], // LLD macros are not enabled. [ '{#LLD}', 0, [], [ 'rc' => CParser::PARSE_FAIL, 'match' => '' ] ], [ '{{#LLD_MACRO}.regsub("(.*)_([0-9]+)", \1)', 0, ['lldmacros' => true], [ 'rc' => CParser::PARSE_FAIL, 'match' => '' ] ], [ '{{#LLD_MACRO}.regsub("(.*)_([0-9]+)", \1)}', 0, [], [ 'rc' => CParser::PARSE_FAIL, 'match' => '' ] ] ]; } /** * @dataProvider dataProvider * * @param string $source * @param int $pos * @param array $options * @param array $expected */ public function testParse($source, $pos, $options, $expected) { $parser = new CPrometheusOutputParser($options); $this->assertSame($expected, [ 'rc' => $parser->parse($source, $pos), 'match' => $parser->getMatch() ]); $this->assertSame(strlen($expected['match']), $parser->getLength()); } }