Skip to content

Commit

Permalink
Expand tests for StringMatchesFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
guilliamxavier authored and sebastianbergmann committed Aug 31, 2018
1 parent 5676d8e commit 14681a7
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions tests/Framework/Constraint/StringMatchesFormatDescriptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ public function testConstraintStringMatchesDirectorySeparator(): void
$constraint = new StringMatchesFormatDescription('*%e*');

$this->assertFalse($constraint->evaluate('**', '', true));
$this->assertFalse($constraint->evaluate('*a*', '', true));

$this->assertTrue($constraint->evaluate('*' . \DIRECTORY_SEPARATOR . '*', '', true));

$this->assertEquals('matches PCRE pattern "/^\*\\' . \DIRECTORY_SEPARATOR . '\*$/s"', $constraint->toString());
$this->assertCount(1, $constraint);
}
Expand All @@ -28,7 +31,11 @@ public function testConstraintStringMatchesString(): void
$constraint = new StringMatchesFormatDescription('*%s*');

$this->assertFalse($constraint->evaluate('**', '', true));
$this->assertFalse($constraint->evaluate("*\n*", '', true));

$this->assertTrue($constraint->evaluate('***', '', true));
$this->assertTrue($constraint->evaluate('*foo 123 bar*', '', true));

$this->assertEquals('matches PCRE pattern "/^\*[^\r\n]+\*$/s"', $constraint->toString());
$this->assertCount(1, $constraint);
}
Expand All @@ -38,7 +45,12 @@ public function testConstraintStringMatchesOptionalString(): void
$constraint = new StringMatchesFormatDescription('*%S*');

$this->assertFalse($constraint->evaluate('*', '', true));
$this->assertFalse($constraint->evaluate("*\n*", '', true));

$this->assertTrue($constraint->evaluate('***', '', true));
$this->assertTrue($constraint->evaluate('*foo 123 bar*', '', true));
$this->assertTrue($constraint->evaluate('**', '', true));

$this->assertEquals('matches PCRE pattern "/^\*[^\r\n]*\*$/s"', $constraint->toString());
$this->assertCount(1, $constraint);
}
Expand All @@ -48,7 +60,11 @@ public function testConstraintStringMatchesAnything(): void
$constraint = new StringMatchesFormatDescription('*%a*');

$this->assertFalse($constraint->evaluate('**', '', true));

$this->assertTrue($constraint->evaluate('***', '', true));
$this->assertTrue($constraint->evaluate('*foo 123 bar*', '', true));
$this->assertTrue($constraint->evaluate("*\n*", '', true));

$this->assertEquals('matches PCRE pattern "/^\*.+\*$/s"', $constraint->toString());
$this->assertCount(1, $constraint);
}
Expand All @@ -58,7 +74,12 @@ public function testConstraintStringMatchesOptionalAnything(): void
$constraint = new StringMatchesFormatDescription('*%A*');

$this->assertFalse($constraint->evaluate('*', '', true));

$this->assertTrue($constraint->evaluate('***', '', true));
$this->assertTrue($constraint->evaluate('*foo 123 bar*', '', true));
$this->assertTrue($constraint->evaluate("*\n*", '', true));
$this->assertTrue($constraint->evaluate('**', '', true));

$this->assertEquals('matches PCRE pattern "/^\*.*\*$/s"', $constraint->toString());
$this->assertCount(1, $constraint);
}
Expand All @@ -68,7 +89,12 @@ public function testConstraintStringMatchesWhitespace(): void
$constraint = new StringMatchesFormatDescription('*%w*');

$this->assertFalse($constraint->evaluate('*', '', true));
$this->assertFalse($constraint->evaluate('*a*', '', true));

$this->assertTrue($constraint->evaluate('* *', '', true));
$this->assertTrue($constraint->evaluate("*\t\n*", '', true));
$this->assertTrue($constraint->evaluate('**', '', true));

$this->assertEquals('matches PCRE pattern "/^\*\s*\*$/s"', $constraint->toString());
$this->assertCount(1, $constraint);
}
Expand All @@ -78,7 +104,14 @@ public function testConstraintStringMatchesInteger(): void
$constraint = new StringMatchesFormatDescription('*%i*');

$this->assertFalse($constraint->evaluate('**', '', true));
$this->assertFalse($constraint->evaluate('*a*', '', true));
$this->assertFalse($constraint->evaluate('*1.0*', '', true));

$this->assertTrue($constraint->evaluate('*0*', '', true));
$this->assertTrue($constraint->evaluate('*12*', '', true));
$this->assertTrue($constraint->evaluate('*-1*', '', true));
$this->assertTrue($constraint->evaluate('*+2*', '', true));

$this->assertEquals('matches PCRE pattern "/^\*[+-]?\d+\*$/s"', $constraint->toString());
$this->assertCount(1, $constraint);
}
Expand All @@ -88,7 +121,14 @@ public function testConstraintStringMatchesUnsignedInt(): void
$constraint = new StringMatchesFormatDescription('*%d*');

$this->assertFalse($constraint->evaluate('**', '', true));
$this->assertFalse($constraint->evaluate('*a*', '', true));
$this->assertFalse($constraint->evaluate('*1.0*', '', true));
$this->assertFalse($constraint->evaluate('*-1*', '', true));
$this->assertFalse($constraint->evaluate('*+2*', '', true));

$this->assertTrue($constraint->evaluate('*0*', '', true));
$this->assertTrue($constraint->evaluate('*12*', '', true));

$this->assertEquals('matches PCRE pattern "/^\*\d+\*$/s"', $constraint->toString());
$this->assertCount(1, $constraint);
}
Expand All @@ -98,7 +138,17 @@ public function testConstraintStringMatchesHexadecimal(): void
$constraint = new StringMatchesFormatDescription('*%x*');

$this->assertFalse($constraint->evaluate('**', '', true));
$this->assertFalse($constraint->evaluate('***', '', true));
$this->assertFalse($constraint->evaluate('*g*', '', true));
$this->assertFalse($constraint->evaluate('*1.0*', '', true));
$this->assertFalse($constraint->evaluate('*-1*', '', true));
$this->assertFalse($constraint->evaluate('*+2*', '', true));

$this->assertTrue($constraint->evaluate('*0f0f0f*', '', true));
$this->assertTrue($constraint->evaluate('*0*', '', true));
$this->assertTrue($constraint->evaluate('*12*', '', true));
$this->assertTrue($constraint->evaluate('*a*', '', true));

$this->assertEquals('matches PCRE pattern "/^\*[0-9a-fA-F]+\*$/s"', $constraint->toString());
$this->assertCount(1, $constraint);
}
Expand All @@ -108,7 +158,18 @@ public function testConstraintStringMatchesFloat(): void
$constraint = new StringMatchesFormatDescription('*%f*');

$this->assertFalse($constraint->evaluate('**', '', true));
$this->assertFalse($constraint->evaluate('***', '', true));
$this->assertFalse($constraint->evaluate('*a*', '', true));

$this->assertTrue($constraint->evaluate('*1.0*', '', true));
$this->assertTrue($constraint->evaluate('*0*', '', true));
$this->assertTrue($constraint->evaluate('*12*', '', true));
$this->assertTrue($constraint->evaluate('*.1*', '', true));
$this->assertTrue($constraint->evaluate('*1.*', '', true));
$this->assertTrue($constraint->evaluate('*2e3*', '', true));
$this->assertTrue($constraint->evaluate('*-2.34e-56*', '', true));
$this->assertTrue($constraint->evaluate('*+2.34e+56*', '', true));

$this->assertEquals('matches PCRE pattern "/^\*[+-]?\.?\d+\.?\d*(?:[Ee][+-]?\d+)?\*$/s"', $constraint->toString());
$this->assertCount(1, $constraint);
}
Expand All @@ -118,11 +179,50 @@ public function testConstraintStringMatchesCharacter(): void
$constraint = new StringMatchesFormatDescription('*%c*');

$this->assertFalse($constraint->evaluate('**', '', true));
$this->assertFalse($constraint->evaluate('*ab*', '', true));

$this->assertTrue($constraint->evaluate('***', '', true));
$this->assertTrue($constraint->evaluate('*a*', '', true));
$this->assertTrue($constraint->evaluate('*g*', '', true));
$this->assertTrue($constraint->evaluate('*0*', '', true));
$this->assertTrue($constraint->evaluate('*2*', '', true));
$this->assertTrue($constraint->evaluate('* *', '', true));
$this->assertTrue($constraint->evaluate("*\n*", '', true));

$this->assertEquals('matches PCRE pattern "/^\*.\*$/s"', $constraint->toString());
$this->assertCount(1, $constraint);
}

public function testConstraintStringMatchesSlash(): void
{
$constraint = new StringMatchesFormatDescription('/');

$this->assertFalse($constraint->evaluate('\\/', '', true));
$this->assertTrue($constraint->evaluate('/', '', true));
$this->assertEquals('matches PCRE pattern "/^\\/$/s"', $constraint->toString());
$this->assertCount(1, $constraint);
}

public function testConstraintStringMatchesBackslash(): void
{
$constraint = new StringMatchesFormatDescription('\\');

$this->assertFalse($constraint->evaluate('\\\\', '', true));
$this->assertTrue($constraint->evaluate('\\', '', true));
$this->assertEquals('matches PCRE pattern "/^\\\\$/s"', $constraint->toString());
$this->assertCount(1, $constraint);
}

public function testConstraintStringMatchesBackslashSlash(): void
{
$constraint = new StringMatchesFormatDescription('\\/');

$this->assertFalse($constraint->evaluate('/', '', true));
$this->assertTrue($constraint->evaluate('\\/', '', true));
$this->assertEquals('matches PCRE pattern "/^\\\\\\/$/s"', $constraint->toString());
$this->assertCount(1, $constraint);
}

public function testConstraintStringMatchesNewline(): void
{
$constraint = new StringMatchesFormatDescription("\r\n");
Expand Down

0 comments on commit 14681a7

Please sign in to comment.