diff --git a/src/Error/Error.php b/src/Error/Error.php index ccbd323..06a1d12 100644 --- a/src/Error/Error.php +++ b/src/Error/Error.php @@ -1,6 +1,7 @@ nodes = $nodes; diff --git a/tests/ErrorTest.php b/tests/ErrorTest.php index 8a39970..fc52609 100644 --- a/tests/ErrorTest.php +++ b/tests/ErrorTest.php @@ -37,6 +37,24 @@ class ErrorTest extends \PHPUnit_Framework_TestCase $this->assertEquals([new SourceLocation(2, 7)], $e->getLocations()); } + /** + * @it converts single node to positions and locations + */ + public function testConvertSingleNodeToPositionsAndLocations() + { + $source = new Source('{ + field + }'); + $ast = Parser::parse($source); + $fieldNode = $ast->definitions[0]->selectionSet->selections[0]; + $e = new Error('msg', $fieldNode); // Non-array value. + + $this->assertEquals([$fieldNode], $e->nodes); + $this->assertEquals($source, $e->getSource()); + $this->assertEquals([8], $e->getPositions()); + $this->assertEquals([new SourceLocation(2, 7)], $e->getLocations()); + } + /** * @it converts node with loc.start === 0 to positions and locations */