CParser::PARSE_SUCCESS, 'match' => '{host:item[0, param1, "param2"].func(0, param1, "param2")}', 'host' => 'host', 'item' => 'item[0, param1, "param2"]', 'function' => 'func(0, param1, "param2")' ] ], [ '0 <> {host:item[0, param1, "param2"].func(, param1, "param2")} or ...', 5, [ 'rc' => CParser::PARSE_SUCCESS_CONT, 'match' => '{host:item[0, param1, "param2"].func(, param1, "param2")}', 'host' => 'host', 'item' => 'item[0, param1, "param2"]', 'function' => 'func(, param1, "param2")' ] ], [ '{hostitem[0, param1, "param2"].func(0, param1, "param2")}', 0, [ 'rc' => CParser::PARSE_FAIL, 'match' => '', 'host' => '', 'item' => '', 'function' => '' ] ] ]; } /** * @dataProvider dataProviderParseExpression() * * @param string $source * @param array $expected */ public function testParseExpression($source, $pos, array $expected) { static $parser = null; if ($parser === null) { $parser = $this->getParser(); } $this->assertSame($expected, [ 'rc' => $parser->parse($source, $pos), 'match' => $parser->getMatch(), 'host' => $parser->getHost(), 'item' => $parser->getItem(), 'function' => $parser->getFunction() ]); } public function dataProviderParseExpression18() { return [ [ '{host:ssh,21.last(0)}=0', 0, [ 'rc' => CParser::PARSE_SUCCESS_CONT, 'match' => '{host:ssh,21.last(0)}', 'host' => 'host', 'item' => 'ssh,21', 'function' => 'last(0)' ] ], [ '{host:ssh,{$PORT}.last(0)}=0 | {$MACRO} | {TRIGGER.VALUE} | {host:ssh,{$PORT}.last(0)}=1', 60, [ 'rc' => CParser::PARSE_SUCCESS_CONT, 'match' => '{host:ssh,{$PORT}.last(0)}', 'host' => 'host', 'item' => 'ssh,{$PORT}', 'function' => 'last(0)' ] ] ]; } /** * @dataProvider dataProviderParseExpression18() * * @param string $source * @param array $expected */ public function testParseExpression18($source, $pos, array $expected) { static $parser = null; if ($parser === null) { $parser = new C10FunctionMacroParser(['18_simple_checks' => true]); } $this->assertSame($expected, [ 'rc' => $parser->parse($source, $pos), 'match' => $parser->getMatch(), 'host' => $parser->getHost(), 'item' => $parser->getItem(), 'function' => $parser->getFunction() ]); } }