Make column info 1-based

This commit is contained in:
Nikita Popov 2015-04-18 21:20:45 +02:00
parent 62f83a0dc2
commit c8454271e1
9 changed files with 35 additions and 35 deletions

View File

@ -93,7 +93,7 @@ class Error extends \RuntimeException
}
/**
* Gets the start column (0-based) into the line where the error started.
* Gets the start column (1-based) into the line where the error started.
*
* @param string $code Source code of the file
* @return int
@ -107,7 +107,7 @@ class Error extends \RuntimeException
}
/**
* Gets the end column (0-based) into the line where the error ended.
* Gets the end column (1-based) into the line where the error ended.
*
* @param string $code Source code of the file
* @return int
@ -130,7 +130,7 @@ class Error extends \RuntimeException
$lineStartPos = -1;
}
return $pos - $lineStartPos - 1;
return $pos - $lineStartPos;
}
/**

View File

@ -49,21 +49,21 @@ class ErrorTest extends \PHPUnit_Framework_TestCase
public function provideTestColumnInfo() {
return array(
// Error at "bar"
array("<?php foo bar baz", 10, 12, 10, 12),
array("<?php\nfoo bar baz", 10, 12, 4, 6),
array("<?php foo\nbar baz", 10, 12, 0, 2),
array("<?php foo bar\nbaz", 10, 12, 10, 12),
array("<?php\r\nfoo bar baz", 11, 13, 4, 6),
array("<?php foo bar baz", 10, 12, 11, 13),
array("<?php\nfoo bar baz", 10, 12, 5, 7),
array("<?php foo\nbar baz", 10, 12, 1, 3),
array("<?php foo bar\nbaz", 10, 12, 11, 13),
array("<?php\r\nfoo bar baz", 11, 13, 5, 7),
// Error at "baz"
array("<?php foo bar baz", 14, 16, 14, 16),
array("<?php foo bar\nbaz", 14, 16, 0, 2),
array("<?php foo bar baz", 14, 16, 15, 17),
array("<?php foo bar\nbaz", 14, 16, 1, 3),
// Error at string literal
array("<?php foo 'bar\nbaz' xyz", 10, 18, 10, 3),
array("<?php\nfoo 'bar\nbaz' xyz", 10, 18, 4, 3),
array("<?php foo\n'\nbarbaz\n'\nxyz", 10, 19, 0, 0),
array("<?php foo 'bar\nbaz' xyz", 10, 18, 11, 4),
array("<?php\nfoo 'bar\nbaz' xyz", 10, 18, 5, 4),
array("<?php foo\n'\nbarbaz\n'\nxyz", 10, 19, 1, 1),
// Error over full string
array("<?php", 0, 4, 0, 4),
array("<?\nphp", 0, 5, 0, 2),
array("<?php", 0, 4, 1, 5),
array("<?\nphp", 0, 5, 1, 3),
);
}

View File

@ -3,4 +3,4 @@ New without a class
<?php
new;
-----
Syntax error, unexpected ';' from 2:3 to 2:3
Syntax error, unexpected ';' from 2:4 to 2:4

View File

@ -26,7 +26,7 @@ Cannot use the final modifier on an abstract class member on line 1
-----
<?php abstract final class A { }
-----
Syntax error, unexpected T_FINAL, expecting T_CLASS from 1:15 to 1:19
Syntax error, unexpected T_FINAL, expecting T_CLASS from 1:16 to 1:20
-----
<?php class A { abstract $a; }
-----

View File

@ -10,31 +10,31 @@ Cannot use 'parent' as class name as it is reserved on line 1
-----
<?php class static {}
-----
Syntax error, unexpected T_STATIC, expecting T_STRING from 1:12 to 1:17
Syntax error, unexpected T_STATIC, expecting T_STRING from 1:13 to 1:18
-----
<?php class A extends self {}
-----
Cannot use 'self' as class name as it is reserved from 1:22 to 1:25
Cannot use 'self' as class name as it is reserved from 1:23 to 1:26
-----
<?php class A extends parent {}
-----
Cannot use 'parent' as class name as it is reserved from 1:22 to 1:27
Cannot use 'parent' as class name as it is reserved from 1:23 to 1:28
-----
<?php class A extends static {}
-----
Syntax error, unexpected T_STATIC, expecting T_STRING or T_NAMESPACE or T_NS_SEPARATOR from 1:22 to 1:27
Syntax error, unexpected T_STATIC, expecting T_STRING or T_NAMESPACE or T_NS_SEPARATOR from 1:23 to 1:28
-----
<?php class A implements self {}
-----
Cannot use 'self' as interface name as it is reserved from 1:25 to 1:28
Cannot use 'self' as interface name as it is reserved from 1:26 to 1:29
-----
<?php class A implements parent {}
-----
Cannot use 'parent' as interface name as it is reserved from 1:25 to 1:30
Cannot use 'parent' as interface name as it is reserved from 1:26 to 1:31
-----
<?php class A implements static {}
-----
Syntax error, unexpected T_STATIC, expecting T_STRING or T_NAMESPACE or T_NS_SEPARATOR from 1:25 to 1:30
Syntax error, unexpected T_STATIC, expecting T_STRING or T_NAMESPACE or T_NS_SEPARATOR from 1:26 to 1:31
-----
<?php interface self {}
-----
@ -46,16 +46,16 @@ Cannot use 'parent' as class name as it is reserved on line 1
-----
<?php interface static {}
-----
Syntax error, unexpected T_STATIC, expecting T_STRING from 1:16 to 1:21
Syntax error, unexpected T_STATIC, expecting T_STRING from 1:17 to 1:22
-----
<?php interface A extends self {}
-----
Cannot use 'self' as interface name as it is reserved from 1:26 to 1:29
Cannot use 'self' as interface name as it is reserved from 1:27 to 1:30
-----
<?php interface A extends parent {}
-----
Cannot use 'parent' as interface name as it is reserved from 1:26 to 1:31
Cannot use 'parent' as interface name as it is reserved from 1:27 to 1:32
-----
<?php interface A extends static {}
-----
Syntax error, unexpected T_STATIC, expecting T_STRING or T_NAMESPACE or T_NS_SEPARATOR from 1:26 to 1:31
Syntax error, unexpected T_STATIC, expecting T_STRING or T_NAMESPACE or T_NS_SEPARATOR from 1:27 to 1:32

View File

@ -3,4 +3,4 @@ Invalid variadic function
<?php
function foo(...$foo = []) {}
-----
Variadic parameter cannot have a default value from 2:23 to 2:24
Variadic parameter cannot have a default value from 2:24 to 2:25

View File

@ -5,4 +5,4 @@ if (true) {
__halt_compiler();
}
-----
__HALT_COMPILER() can only be used from the outermost scope from 3:4 to 3:18
__HALT_COMPILER() can only be used from the outermost scope from 3:5 to 3:19

View File

@ -2,15 +2,15 @@ Invalid namespace names
-----
<?php namespace self;
-----
Cannot use 'self' as namespace name from 1:16 to 1:19
Cannot use 'self' as namespace name from 1:17 to 1:20
-----
<?php namespace parent;
-----
Cannot use 'parent' as namespace name from 1:16 to 1:21
Cannot use 'parent' as namespace name from 1:17 to 1:22
-----
<?php namespace static;
-----
Syntax error, unexpected T_STATIC, expecting T_STRING or T_NS_SEPARATOR or '{' from 1:16 to 1:21
Syntax error, unexpected T_STATIC, expecting T_STRING or T_NS_SEPARATOR or '{' from 1:17 to 1:22
-----
<?php use A as self;
-----
@ -22,4 +22,4 @@ Cannot use B as parent because 'parent' is a special class name on line 1
-----
<?php use C as static;
-----
Syntax error, unexpected T_STATIC, expecting T_STRING from 1:15 to 1:20
Syntax error, unexpected T_STATIC, expecting T_STRING from 1:16 to 1:21

View File

@ -7,4 +7,4 @@ namespace A {
}
}
-----
Namespace declarations cannot be nested from 3:4 to 5:4
Namespace declarations cannot be nested from 3:5 to 5:5