@@ -298,6 +298,7 @@ public function testGetRegex(){
298
298
299
299
/**
300
300
* @depends testGetRegex
301
+ * @todo Refactor VerbalExpressions::multiple() for 100% coverage
301
302
*/
302
303
public function testGetRegex_multiple (){
303
304
$ regex = new VerbalExpressions ();
@@ -452,4 +453,113 @@ public function testRange_sha1(){
452
453
$ this ->assertFalse ($ sha1 ->test (md5 ('' )));
453
454
$ this ->assertTrue ($ sha1 ->test (sha1 ('' )));
454
455
}
456
+
457
+ /**
458
+ * @depends testGetRegex
459
+ */
460
+ public function testRemoveModifier (){
461
+ $ regex = new VerbalExpressions ();
462
+ $ regex ->range ('a ' , 'z ' );
463
+
464
+ $ this ->assertEquals ('/[a-z]/m ' , $ regex ->getRegex ());
465
+
466
+ $ regex ->removeModifier ('m ' );
467
+
468
+ $ this ->assertEquals ('/[a-z]/ ' , $ regex ->getRegex ());
469
+ }
470
+
471
+ /**
472
+ * @depends testRemoveModifier
473
+ */
474
+ public function testWithAnyCase (){
475
+ $ regex = new VerbalExpressions ();
476
+ $ regex ->range ('a ' , 'z ' )
477
+ ->searchOneLine (false )
478
+ ->withAnyCase ();
479
+
480
+ $ this ->assertEquals ('/[a-z]/i ' , $ regex ->getRegex ());
481
+
482
+ $ regex ->withAnyCase (false );
483
+
484
+ $ this ->assertEquals ('/[a-z]/ ' , $ regex ->getRegex ());
485
+ }
486
+
487
+ /**
488
+ * @depends testGetRegex
489
+ */
490
+ public function testOr (){
491
+ $ regex = new VerbalExpressions ();
492
+ $ regex ->find ('foo ' )
493
+ ->_or ('bar ' );
494
+
495
+ $ this ->assertTrue ($ regex ->test ('foo ' ));
496
+ $ this ->assertTrue ($ regex ->test ('bar ' ));
497
+ $ this ->assertFalse ($ regex ->test ('baz ' ));
498
+ $ this ->assertTrue ($ regex ->test ('food ' ));
499
+
500
+ $ this ->assertEquals ('/(?:(?:foo))|(?:bar)/m ' , $ regex ->getRegex ());
501
+ }
502
+
503
+ /**
504
+ * @depends testGetRegex
505
+ * @todo fix VerbalExpressions::clean() so it matches initial state
506
+ */
507
+ public function testClean (){
508
+ $ regex = new VerbalExpressions ();
509
+ $ regex ->removeModifier ('m ' )
510
+ ->stopAtFirst ()
511
+ ->searchOneLine ();
512
+
513
+ $ regex_at_start = $ regex ->getRegex ();
514
+ $ regex ->find ('something ' )
515
+ ->add ('else ' )
516
+ ->_or ('another ' );
517
+
518
+ $ this ->assertNotEquals ($ regex_at_start , $ regex ->getRegex ());
519
+
520
+ $ regex ->clean ();
521
+
522
+ $ this ->assertEquals ($ regex_at_start , $ regex ->getRegex ());
523
+ }
524
+
525
+ /**
526
+ * @depends testGetRegex
527
+ */
528
+ public function testLimit (){
529
+ $ regex = new VerbalExpressions ();
530
+
531
+ $ regex ->add ('a ' )
532
+ ->limit (1 );
533
+ $ this ->assertEquals ('/a{1}/m ' , $ regex ->getRegex ());
534
+
535
+ $ regex ->add ('b ' )
536
+ ->limit (2 , 1 );
537
+ $ this ->assertEquals ('/a{1}b{2,}/m ' , $ regex ->getRegex ());
538
+
539
+ $ regex ->add ('c ' )
540
+ ->limit (3 , 4 );
541
+ $ this ->assertEquals ('/a{1}b{2,}c{3,4}/m ' , $ regex ->getRegex ());
542
+
543
+ $ regex ->multiple ('d ' );
544
+ $ this ->assertEquals ('/a{1}b{2,}c{3,4}d+/m ' , $ regex ->getRegex ());
545
+
546
+ $ regex ->limit (5 , 6 );
547
+ $ this ->assertEquals ('/a{1}b{2,}c{3,4}d{5,6}/m ' , $ regex ->getRegex ());
548
+ }
549
+
550
+ /**
551
+ * @depends testGetRegex
552
+ */
553
+ public function testReplace (){
554
+ $ regex = new VerbalExpressions ();
555
+ $ regex ->add ('foo ' );
556
+
557
+ $ this ->assertEquals ('/foo/m ' , $ regex ->getRegex ());
558
+ $ this ->assertEquals ('bazbarfoo ' , $ regex ->replace ('foobarfoo ' , 'baz ' ));
559
+
560
+ $ regex ->stopAtFirst ();
561
+
562
+ $ this ->assertEquals ('/foo/mg ' , $ regex ->getRegex ());
563
+ $ this ->assertEquals ('bazbarbaz ' , $ regex ->replace ('foobarfoo ' , 'baz ' ));
564
+ }
455
565
}
0 commit comments