示例#1
0
 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());
 }
示例#2
0
 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());
 }
示例#3
0
 public function testObjectGenerationNegate()
 {
     $regex = REBuilder\REBuilder::create();
     $regex->addUnicodeCharClass("C", true)->setRepetition("?");
     $this->assertSame("/\\P{C}?/", $regex->render());
 }
示例#4
0
 public function testObjectGeneration()
 {
     $regex = REBuilder\REBuilder::create();
     $regex->addCharClass(true)->setRepetition("+")->addChar("a");
     $this->assertSame("/[^a]+/", $regex->render());
 }
示例#5
0
 public function testObjectGeneration()
 {
     $regex = REBuilder\REBuilder::create();
     $regex->addControlChar("a");
     $this->assertSame("/\\ca/", $regex->render());
 }
示例#6
0
 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 . "");
 }
示例#8
0
 public function testObjectGeneration()
 {
     $regex = REBuilder\REBuilder::create();
     $regex->addNonPrintingChar("a")->setRepetition(2);
     $this->assertSame("/\\a{2}/", $regex->render());
 }
示例#9
0
 public function testObjectGeneration()
 {
     $regex = REBuilder\REBuilder::create();
     $regex->addChar("a")->setRepetition("*")->getParent()->addComment("comment");
     $this->assertSame("/a*(?#comment)/", $regex->render());
 }
示例#10
0
 public function testObjectGeneration()
 {
     $regex = REBuilder\REBuilder::create();
     $regex->addInternalOptionAndContinue("i-m")->addChar("test");
     $this->assertSame("/(?i-m)test/", $regex->render());
 }
示例#11
0
 public function testObjectGeneration()
 {
     $regex = REBuilder\REBuilder::create();
     $regex->addHexChar("aa")->setRepetition(1, 2);
     $this->assertSame("/\\xaa{1,2}/", $regex->render());
 }
示例#12
0
 public function testObjectGeneration()
 {
     $regex = REBuilder\REBuilder::create();
     $regex->addRecursivePattern("1");
     $this->assertSame('/(?1)/', $regex->render());
 }
示例#13
0
 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"));
 }
示例#14
0
 public function testObjectGeneration()
 {
     $regex = REBuilder\REBuilder::create();
     $regex->addBackReference("1");
     $this->assertSame('/\\g{1}/', $regex->render());
 }
示例#15
0
 public function testObjectGeneration()
 {
     $regex = REBuilder\REBuilder::create();
     $regex->addAlternationGroup()->addAlternation()->addCharAndContinue("a")->getParent()->addAlternation()->addCharAndContinue("b")->getParent()->setRepetition("*");
     $this->assertSame("/(?:a|b)*/", $regex->render());
 }
示例#16
0
 public function testObjectGeneration()
 {
     $regex = REBuilder\REBuilder::create("x");
     $regex->addByte()->setRepetition("*");
     $this->assertSame("/\\C*/x", $regex->render());
 }
示例#17
0
 public function testObjectGeneration()
 {
     $regex = REBuilder\REBuilder::create();
     $regex->addGenericCharType("w");
     $this->assertSame("/\\w/", $regex->render());
 }
示例#18
0
 public function testObjectGeneration()
 {
     $regex = REBuilder\REBuilder::create();
     $regex->addCharClass()->addCharAndContinue("a")->addPosixCharClass("ascii");
     $this->assertSame("/[a[:ascii:]]/", $regex->render());
 }
示例#19
0
 public function testObjectGeneration()
 {
     $regex = REBuilder\REBuilder::create("i");
     $regex->addChar("abc");
     $this->assertSame("/abc/i", $regex->render());
 }
示例#20
0
 public function testObjectGeneration()
 {
     $regex = REBuilder\REBuilder::create();
     $regex->addOctalChar("01");
     $this->assertSame('/\\01/', $regex->render());
 }
示例#21
0
 public function testObjectGeneration()
 {
     $regex = REBuilder\REBuilder::create();
     $regex->addSimpleAssertionAndContinue("b")->addChar("abc");
     $this->assertSame("/\\babc/", $regex->render());
 }
示例#22
0
 public function testObjectGeneration()
 {
     $regex = REBuilder\REBuilder::create();
     $regex->addAssertion(false, true)->addCharAndContinue("a")->getParent()->addChar("b");
     $this->assertSame("/(?<!a)b/", $regex . "");
 }
示例#23
0
 public function testObjectGeneration()
 {
     $regex = REBuilder\REBuilder::create();
     $regex->addSubpattern(false)->addControlChar(";")->setRepetition("+", true);
     $this->assertSame("/(?:\\c;+?)/", $regex . "");
 }
示例#24
0
 /**
  * @dataProvider invalidRepetitions
  * @expectedException REBuilder\Exception\InvalidRepetition
  */
 public function testInvalidRepetition($pattern)
 {
     REBuilder\REBuilder::parse("/{$pattern}/");
 }