1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 09:37:59 +01:00
psalm/tests/TypeParseTest.php
Jon Ursenbach 11bc153deb Rewriting and streamlining every unit test with data providers. (#147)
* Rewriting and streamlining every unit test with data providers.

All unit tests have been rewritten into PHPUnit data providers
to reduce the amount of unnecessary code-reuse through out the
test suite.
2017-04-24 23:45:02 -04:00

65 lines
2.0 KiB
PHP

<?php
namespace Psalm\Tests;
use Psalm\Type;
class TypeParseTest extends TestCase
{
/**
* @return void
*/
public function testIntOrString()
{
$this->assertEquals('int|string', (string) Type::parseString('int|string'));
}
/**
* @return void
*/
public function testArray()
{
$this->assertEquals('array<int, int>', (string) Type::parseString('array<int, int>'));
$this->assertEquals('array<int, string>', (string) Type::parseString('array<int, string>'));
$this->assertEquals('array<int, static>', (string) Type::parseString('array<int, static>'));
$this->assertEquals('array<int|string, string>', (string) Type::parseString('array<int|string, string>'));
}
/**
* @return void
*/
public function testGeneric()
{
$this->assertEquals('B<int>', (string) Type::parseString('B<int>'));
}
/**
* @return void
*/
public function testPhpDocStyle()
{
$this->assertEquals('array<mixed, A>', (string) Type::parseString('A[]'));
$this->assertEquals('array<mixed, A|B>', (string) Type::parseString('(A|B)[]'));
$this->assertEquals('array<mixed, array<mixed, A>>', (string) Type::parseString('A[][]'));
$this->assertEquals('array<mixed, array<mixed, A|B>>', (string) Type::parseString('(A|B)[][]'));
$this->assertEquals('array<mixed, A|B>', (string) Type::parseString('A[]|B[]'));
$this->assertEquals('array<mixed, A|B>|C', (string) Type::parseString('A[]|B[]|C'));
}
/**
* @return void
*/
public function testObjectLike()
{
$this->assertEquals('array{a:int, b:string}', (string) Type::parseString('array{a:int, b:string}'));
$this->assertEquals(
'array{a:int|string, b:string}',
(string) Type::parseString('array{a:int|string, b:string}')
);
$this->assertEquals(
'array{a:array<int, string|int>, b:string}',
(string) Type::parseString('array{a:array<int, string|int>, b:string}')
);
}
}