PHP 8 (#1)
PHP 8 Update
- nullsafe operator (?->)
- Remove (real) cast
- Named arguments
- Remove (unset) cast
- Remove {} access
- match expression
- Union types in type hints and static typehint
- Block catch without variable
- Trailing comma in parameter lists
- throw can be used as an expression
- Concatenation precedence
- Declaring properties in the constructor
- Attributes
- Names in the namespace are treated as a single token
- Trailing comma in closure use list
- Check that ::class on object works
- Deferencable changes and arbitrary expressions in new/instanceof
This commit is contained in:
@@ -22,6 +22,9 @@ var (
|
||||
|
||||
php7RangeStart = &Version{Major: 7}
|
||||
php7RangeEnd = &Version{Major: 7, Minor: 4}
|
||||
|
||||
php8RangeStart = &Version{Major: 8}
|
||||
php8RangeEnd = &Version{Major: 8, Minor: 1}
|
||||
)
|
||||
|
||||
func New(v string) (*Version, error) {
|
||||
@@ -48,7 +51,9 @@ func New(v string) (*Version, error) {
|
||||
}
|
||||
|
||||
func (v *Version) Validate() error {
|
||||
if !v.InRange(php5RangeStart, php5RangeEnd) && !v.InRange(php7RangeStart, php7RangeEnd) {
|
||||
if !v.InRange(php5RangeStart, php5RangeEnd) &&
|
||||
!v.InRange(php7RangeStart, php7RangeEnd) &&
|
||||
!v.InRange(php8RangeStart, php8RangeEnd) {
|
||||
return ErrUnsupportedVer
|
||||
}
|
||||
|
||||
@@ -75,7 +80,7 @@ func (v *Version) GreaterOrEqual(o *Version) bool {
|
||||
return v.Compare(o) >= 0
|
||||
}
|
||||
|
||||
// GreaterOrEqual tests if one version is greater than another one or equal
|
||||
// InRange tests if version is in range in another one
|
||||
func (v *Version) InRange(s, e *Version) bool {
|
||||
return v.Compare(s) >= 0 && v.Compare(e) <= 0
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package version_test
|
||||
|
||||
import (
|
||||
"gotest.tools/assert"
|
||||
"testing"
|
||||
|
||||
"gotest.tools/assert"
|
||||
|
||||
"github.com/z7zmey/php-parser/pkg/version"
|
||||
)
|
||||
|
||||
@@ -46,3 +47,19 @@ func TestInRange(t *testing.T) {
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, ver.InRange(s, e))
|
||||
}
|
||||
|
||||
func TestInRangePHP8(t *testing.T) {
|
||||
s, err := version.New("8.0")
|
||||
assert.NilError(t, err)
|
||||
|
||||
e, err := version.New("8.1")
|
||||
assert.NilError(t, err)
|
||||
|
||||
ver, err := version.New("8.0")
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, ver.InRange(s, e))
|
||||
|
||||
ver, err = version.New("8.1")
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, ver.InRange(s, e))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user