2016-09-09 16:38:32 -04:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
2016-11-02 02:29:00 -04:00
|
|
|
use Psalm\Type;
|
2016-09-09 16:38:32 -04:00
|
|
|
|
2017-04-24 23:45:02 -04:00
|
|
|
class TypeParseTest extends TestCase
|
2016-09-09 16:38:32 -04:00
|
|
|
{
|
2017-01-13 14:07:23 -05:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-09-09 16:38:32 -04:00
|
|
|
public function testIntOrString()
|
|
|
|
{
|
2017-05-26 20:05:57 -04:00
|
|
|
$this->assertSame('int|string', (string) Type::parseString('int|string'));
|
2016-09-22 00:31:07 -04:00
|
|
|
}
|
2016-09-09 16:38:32 -04:00
|
|
|
|
2017-01-13 14:07:23 -05:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-09-22 00:31:07 -04:00
|
|
|
public function testArray()
|
|
|
|
{
|
2017-05-26 20:05:57 -04:00
|
|
|
$this->assertSame('array<int, int>', (string) Type::parseString('array<int, int>'));
|
|
|
|
$this->assertSame('array<int, string>', (string) Type::parseString('array<int, string>'));
|
|
|
|
$this->assertSame('array<int, static>', (string) Type::parseString('array<int, static>'));
|
|
|
|
$this->assertSame('array<int|string, string>', (string) Type::parseString('array<int|string, string>'));
|
2016-09-22 00:31:07 -04:00
|
|
|
}
|
2016-09-09 16:38:32 -04:00
|
|
|
|
2017-01-13 14:07:23 -05:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-09-22 00:31:07 -04:00
|
|
|
public function testGeneric()
|
|
|
|
{
|
2017-05-26 20:05:57 -04:00
|
|
|
$this->assertSame('B<int>', (string) Type::parseString('B<int>'));
|
2016-09-09 16:38:32 -04:00
|
|
|
}
|
|
|
|
|
2017-01-13 14:07:23 -05:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-10-29 20:57:03 -04:00
|
|
|
public function testPhpDocStyle()
|
|
|
|
{
|
2017-05-26 20:05:57 -04:00
|
|
|
$this->assertSame('array<mixed, A>', (string) Type::parseString('A[]'));
|
|
|
|
$this->assertSame('array<mixed, A|B>', (string) Type::parseString('(A|B)[]'));
|
|
|
|
$this->assertSame('array<mixed, array<mixed, A>>', (string) Type::parseString('A[][]'));
|
|
|
|
$this->assertSame('array<mixed, array<mixed, A|B>>', (string) Type::parseString('(A|B)[][]'));
|
|
|
|
$this->assertSame('array<mixed, A|B>', (string) Type::parseString('A[]|B[]'));
|
|
|
|
$this->assertSame('array<mixed, A|B>|C', (string) Type::parseString('A[]|B[]|C'));
|
2016-10-29 20:57:03 -04:00
|
|
|
}
|
|
|
|
|
2017-01-13 14:07:23 -05:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-09-22 00:31:07 -04:00
|
|
|
public function testObjectLike()
|
|
|
|
{
|
2017-05-26 20:05:57 -04:00
|
|
|
$this->assertSame('array{a:int, b:string}', (string) Type::parseString('array{a:int, b:string}'));
|
|
|
|
$this->assertSame(
|
2016-11-13 11:24:25 -05:00
|
|
|
'array{a:int|string, b:string}',
|
2016-11-02 02:29:00 -04:00
|
|
|
(string) Type::parseString('array{a:int|string, b:string}')
|
|
|
|
);
|
|
|
|
|
2017-05-26 20:05:57 -04:00
|
|
|
$this->assertSame(
|
2016-11-13 11:24:25 -05:00
|
|
|
'array{a:array<int, string|int>, b:string}',
|
2016-11-02 02:29:00 -04:00
|
|
|
(string) Type::parseString('array{a:array<int, string|int>, b:string}')
|
|
|
|
);
|
2016-09-22 00:31:07 -04:00
|
|
|
}
|
2016-09-09 16:38:32 -04:00
|
|
|
}
|