public function testInvalidNumberNotParsedAsRepetition() { $regex = REBuilder\REBuilder::parse("/a{1,/"); $this->assertInstanceOf("REBuilder\\Pattern\\Regex", $regex); $children = $regex->getChildren(); $this->assertSame(1, count($children)); $this->assertInstanceOf("REBuilder\\Pattern\\Char", $children[0]); $this->assertSame("a{1,", $children[0]->getChar()); }
public function testGeneratedStructureLazy() { $regex = REBuilder\REBuilder::parse("/a+?/"); $this->assertInstanceOf("REBuilder\\Pattern\\Regex", $regex); $children = $regex->getChildren(); $this->assertSame(1, count($children)); $this->assertInstanceOf("REBuilder\\Pattern\\Repetition\\OneOrMore", $children[0]->getRepetition()); $this->assertSame(true, $children[0]->getRepetition()->getLazy()); }
public function testObjectGenerationNegate() { $regex = REBuilder\REBuilder::create(); $regex->addUnicodeCharClass("C", true)->setRepetition("?"); $this->assertSame("/\\P{C}?/", $regex->render()); }
public function testObjectGeneration() { $regex = REBuilder\REBuilder::create(); $regex->addCharClass(true)->setRepetition("+")->addChar("a"); $this->assertSame("/[^a]+/", $regex->render()); }
public function testObjectGeneration() { $regex = REBuilder\REBuilder::create(); $regex->addControlChar("a"); $this->assertSame("/\\ca/", $regex->render()); }
public function testObjectGeneration() { $regex = REBuilder\REBuilder::create("m"); $regex->addDot()->setRepetition("*"); $this->assertSame("/.*/m", $regex->render()); }
public function testObjectGeneration() { $regex = REBuilder\REBuilder::create(); $regex->addCharAndContinue("a")->addConditionalSubPattern()->addAssertion()->addCharAndContinue("c")->getParent()->addConditionalThen()->addCharAndContinue("c")->getParent()->addConditionalElse()->addCharAndContinue("d"); $this->assertSame("/a(?(?=c)c|d)/", $regex . ""); }
public function testObjectGeneration() { $regex = REBuilder\REBuilder::create(); $regex->addNonPrintingChar("a")->setRepetition(2); $this->assertSame("/\\a{2}/", $regex->render()); }
public function testObjectGeneration() { $regex = REBuilder\REBuilder::create(); $regex->addChar("a")->setRepetition("*")->getParent()->addComment("comment"); $this->assertSame("/a*(?#comment)/", $regex->render()); }
public function testObjectGeneration() { $regex = REBuilder\REBuilder::create(); $regex->addInternalOptionAndContinue("i-m")->addChar("test"); $this->assertSame("/(?i-m)test/", $regex->render()); }
public function testObjectGeneration() { $regex = REBuilder\REBuilder::create(); $regex->addHexChar("aa")->setRepetition(1, 2); $this->assertSame("/\\xaa{1,2}/", $regex->render()); }
public function testObjectGeneration() { $regex = REBuilder\REBuilder::create(); $regex->addRecursivePattern("1"); $this->assertSame('/(?1)/', $regex->render()); }
public function testReplaceMethod() { $regex = REBuilder\REBuilder::create(); $regex->addGenericCharType("w"); $this->assertSame("/\\w/", $regex->render()); $this->assertSame("111", $regex->replace("1", "abc")); $this->assertSame("1bc", $regex->replace("1", "abc", 1)); $count = 0; $this->assertSame("123", $regex->replace(function () use(&$count) { $count++; return "{$count}"; }, "abc")); }
public function testObjectGeneration() { $regex = REBuilder\REBuilder::create(); $regex->addBackReference("1"); $this->assertSame('/\\g{1}/', $regex->render()); }
public function testObjectGeneration() { $regex = REBuilder\REBuilder::create(); $regex->addAlternationGroup()->addAlternation()->addCharAndContinue("a")->getParent()->addAlternation()->addCharAndContinue("b")->getParent()->setRepetition("*"); $this->assertSame("/(?:a|b)*/", $regex->render()); }
public function testObjectGeneration() { $regex = REBuilder\REBuilder::create("x"); $regex->addByte()->setRepetition("*"); $this->assertSame("/\\C*/x", $regex->render()); }
public function testObjectGeneration() { $regex = REBuilder\REBuilder::create(); $regex->addGenericCharType("w"); $this->assertSame("/\\w/", $regex->render()); }
public function testObjectGeneration() { $regex = REBuilder\REBuilder::create(); $regex->addCharClass()->addCharAndContinue("a")->addPosixCharClass("ascii"); $this->assertSame("/[a[:ascii:]]/", $regex->render()); }
public function testObjectGeneration() { $regex = REBuilder\REBuilder::create("i"); $regex->addChar("abc"); $this->assertSame("/abc/i", $regex->render()); }
public function testObjectGeneration() { $regex = REBuilder\REBuilder::create(); $regex->addOctalChar("01"); $this->assertSame('/\\01/', $regex->render()); }
public function testObjectGeneration() { $regex = REBuilder\REBuilder::create(); $regex->addSimpleAssertionAndContinue("b")->addChar("abc"); $this->assertSame("/\\babc/", $regex->render()); }
public function testObjectGeneration() { $regex = REBuilder\REBuilder::create(); $regex->addAssertion(false, true)->addCharAndContinue("a")->getParent()->addChar("b"); $this->assertSame("/(?<!a)b/", $regex . ""); }
public function testObjectGeneration() { $regex = REBuilder\REBuilder::create(); $regex->addSubpattern(false)->addControlChar(";")->setRepetition("+", true); $this->assertSame("/(?:\\c;+?)/", $regex . ""); }
/** * @dataProvider invalidRepetitions * @expectedException REBuilder\Exception\InvalidRepetition */ public function testInvalidRepetition($pattern) { REBuilder\REBuilder::parse("/{$pattern}/"); }