Skip to content

Commit

Permalink
Removed pattern()->is()->delimited(), because automatic detection n…
Browse files Browse the repository at this point in the history
…o longer happens #55
  • Loading branch information
danon committed Nov 2, 2019
1 parent 6f2b639 commit 24a4f75
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 252 deletions.
41 changes: 0 additions & 41 deletions src/TRegx/CleanRegex/Internal/Delimiter/DelimiterParser.php

This file was deleted.

8 changes: 0 additions & 8 deletions src/TRegx/CleanRegex/Internal/Delimiter/Delimiterer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,17 @@ class Delimiterer
{
/** @var Delimiters */
private $delimiters;
/** @var DelimiterParser */
private $parser;
/** @var DelimiterStrategy */
private $delimiterStrategy;

public function __construct(DelimiterStrategy $strategy = null)
{
$this->delimiters = new Delimiters();
$this->parser = new DelimiterParser();
$this->delimiterStrategy = $strategy ?? new IdentityDelimiterStrategy();
}

public function delimiter(string $pattern): string
{
$delimiter = $this->parser->getDelimiter($pattern);
if ($delimiter !== null) {
return $this->delimiterStrategy->alreadyDelimited($pattern, $delimiter);
}

$delimiterNext = $this->getPossibleDelimiter($pattern);
if ($delimiterNext !== null) {
return $this->delimiterStrategy->delimiter($pattern, $delimiterNext);
Expand Down
8 changes: 0 additions & 8 deletions src/TRegx/CleanRegex/IsPattern.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php
namespace TRegx\CleanRegex;

use TRegx\CleanRegex\Internal\Delimiter\DelimiterParser;
use TRegx\CleanRegex\Internal\InternalPattern;
use TRegx\SafeRegex\preg;

class IsPattern
{
Expand All @@ -24,10 +22,4 @@ public function usable(): bool
{
return (new ValidPattern($this->pattern->pattern))->isValid();
}

public function delimited(): bool
{
preg::match($this->pattern->pattern, '');
return (new DelimiterParser())->isDelimited($this->pattern->originalPattern);
}
}
2 changes: 1 addition & 1 deletion test/Feature/TRegx/CleanRegex/ErrorCleanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function shouldNotInterfereWithFurtherMatches()
}

// when
$valid = pattern('/[a-z]/')->test("a");
$valid = pattern('[a-z]')->test("a");

// then
$this->assertTrue($valid);
Expand Down
46 changes: 0 additions & 46 deletions test/Integration/TRegx/CleanRegex/IsPatternTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,50 +98,4 @@ public function shouldNotBeUsable_invalid_notDelimited()
// then
$this->assertFalse($usable);
}

/**
* @test
*/
public function shouldBeDelimited()
{
// given
$is = new IsPattern(InternalPattern::manual('/valid/'));

// when
$delimited = $is->delimited();

// then
$this->assertTrue($delimited);
}

/**
* @test
*/
public function shouldNotBeDelimited()
{
// given
$is = new IsPattern(InternalPattern::automatic('/invalid'));

// when
$delimited = $is->delimited();

// then
$this->assertFalse($delimited);
}

/**
* @test
*/
public function shouldThrow_onInvalidPattern()
{
// given
$is = new IsPattern(InternalPattern::automatic('invalid)'));

// then
$this->expectException(MalformedPatternException::class);
$this->expectExceptionMessageRegExp(PhpVersionDependent::getUnmatchedParenthesisMessage(7));

// when
$is->delimited();
}
}
119 changes: 0 additions & 119 deletions test/Unit/TRegx/CleanRegex/Internal/Delimiter/DelimiterParserTest.php

This file was deleted.

29 changes: 0 additions & 29 deletions test/Unit/TRegx/CleanRegex/Internal/Delimiter/DelimitererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,35 +51,6 @@ public function shouldDelimiterPattern(string $input)
$this->assertTrue(preg::match($pattern, $input) === 1, "Failed asserting that $pattern matches $input");
}

public function alreadyDelimited()
{
return [
['/a/'],
['#a#'],
['%a%'],
['~a~'],
['+a+'],
['!a!'],
];
}

/**
* @test
* @dataProvider alreadyDelimited
* @param string $pattern
*/
public function shouldDelimiterAlreadyDelimited(string $pattern)
{
// given
$delimited = new Delimiterer();

// when
$result = $delimited->delimiter($pattern);

// then
$this->assertEquals($pattern, $result);
}

/**
* @test
*/
Expand Down

0 comments on commit 24a4f75

Please sign in to comment.