2020-12-29 19:23:22 +00:00
|
|
|
package version_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-07-30 17:53:27 +00:00
|
|
|
"gotest.tools/assert"
|
|
|
|
|
2021-07-30 18:01:34 +00:00
|
|
|
"github.com/VKCOM/php-parser/pkg/version"
|
2020-12-29 19:23:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func Test(t *testing.T) {
|
|
|
|
ver, err := version.New("7.4")
|
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
assert.Equal(t, *ver, version.Version{
|
|
|
|
Major: 7,
|
|
|
|
Minor: 4,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLeadingZero(t *testing.T) {
|
|
|
|
ver, err := version.New("07.04")
|
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
assert.Equal(t, *ver, version.Version{
|
|
|
|
Major: 7,
|
|
|
|
Minor: 4,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInRange(t *testing.T) {
|
|
|
|
s, err := version.New("7.0")
|
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
e, err := version.New("7.4")
|
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
ver, err := version.New("7.0")
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Assert(t, ver.InRange(s, e))
|
|
|
|
|
|
|
|
ver, err = version.New("7.2")
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Assert(t, ver.InRange(s, e))
|
|
|
|
|
|
|
|
ver, err = version.New("7.4")
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Assert(t, ver.InRange(s, e))
|
|
|
|
}
|
2021-07-30 17:53:27 +00:00
|
|
|
|
|
|
|
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))
|
|
|
|
}
|