-
Notifications
You must be signed in to change notification settings - Fork 651
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: introduce literal float methods to
Union
type
- Added `Psalm\Type\Union#isSingleFloatLiteral` - Added `Psalm\Type\Union#getSingleFloatLiteral` - Added `Psalm\Type\Union#hasLiteralFloat` Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Psalm\Tests\Type; | ||
|
||
use InvalidArgumentException; | ||
use Psalm\Tests\TestCase; | ||
use Psalm\Type\Atomic\TFloat; | ||
use Psalm\Type\Atomic\TLiteralFloat; | ||
use Psalm\Type\Union; | ||
|
||
final class UnionTest extends TestCase | ||
{ | ||
|
||
public function testWillDetectSingleLiteralFloat(): void | ||
{ | ||
$literalFloat = new TLiteralFloat(1.0); | ||
$union = new Union([$literalFloat]); | ||
|
||
self::assertTrue($union->isSingleFloatLiteral()); | ||
self::assertTrue($union->hasLiteralFloat()); | ||
self::assertSame($literalFloat, $union->getSingleFloatLiteral()); | ||
} | ||
|
||
public function testWillThrowInvalidArgumentExceptionWhenSingleFloatLiteralIsRequestedButNoneExists(): void | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
$union = new Union([new TFloat()]); | ||
$union->getSingleFloatLiteral(); | ||
} | ||
} |