From 14681a7eefbfd352afcc15586632197989ab54bd Mon Sep 17 00:00:00 2001 From: Guilliam Xavier Date: Fri, 31 Aug 2018 14:29:45 +0200 Subject: [PATCH] Expand tests for StringMatchesFormat --- .../StringMatchesFormatDescriptionTest.php | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/tests/Framework/Constraint/StringMatchesFormatDescriptionTest.php b/tests/Framework/Constraint/StringMatchesFormatDescriptionTest.php index 98f55f3696a..bc9fe7a6131 100644 --- a/tests/Framework/Constraint/StringMatchesFormatDescriptionTest.php +++ b/tests/Framework/Constraint/StringMatchesFormatDescriptionTest.php @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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");