Skip to content
Permalink
Browse files

Allow empty string parsing

  • Loading branch information
muglug committed Dec 11, 2019
1 parent 3a7dd61 commit 79f3a5d37175d26f0b4b696d94428ca687c9eca7
Showing with 34 additions and 1 deletion.
  1. +1 −1 src/Psalm/Type.php
  2. +33 −0 tests/TypeParseTest.php
@@ -812,7 +812,7 @@ public static function tokenize($string_type, $ignore_space = true)
}

if ($quote_char) {
if ($char === $quote_char && $i > 1 && !$escaped) {
if ($char === $quote_char && $i > 0 && !$escaped) {
$quote_char = null;

$type_tokens[$rtc][0] .= $char;
@@ -834,6 +834,39 @@ public function testEnum()
$this->assertSame($resolved_type->getId(), $docblock_type->getId());
}

public function testEmptyString()
{
$docblock_type = Type::parseString('""|"admin"|"fun"');

$resolved_type = new Type\Union([
new Type\Atomic\TLiteralString(''),
new Type\Atomic\TLiteralString('admin'),
new Type\Atomic\TLiteralString('fun'),
]);

$this->assertSame($resolved_type->getId(), $docblock_type->getId());

$docblock_type = Type::parseString('"admin"|""|"fun"');

$resolved_type = new Type\Union([
new Type\Atomic\TLiteralString('admin'),
new Type\Atomic\TLiteralString(''),
new Type\Atomic\TLiteralString('fun'),
]);

$this->assertSame($resolved_type->getId(), $docblock_type->getId());

$docblock_type = Type::parseString('"admin"|"fun"|""');

$resolved_type = new Type\Union([
new Type\Atomic\TLiteralString('admin'),
new Type\Atomic\TLiteralString('fun'),
new Type\Atomic\TLiteralString(''),
]);

$this->assertSame($resolved_type->getId(), $docblock_type->getId());
}

/**
* @return void
*/

0 comments on commit 79f3a5d

Please sign in to comment.
You can’t perform that action at this time.