2021-07-30 17:53:27 +00:00
|
|
|
package tester
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-12-09 21:36:19 +00:00
|
|
|
"git.maride.cc/maride/php-parser/pkg/conf"
|
|
|
|
"git.maride.cc/maride/php-parser/pkg/errors"
|
|
|
|
"git.maride.cc/maride/php-parser/pkg/parser"
|
|
|
|
"git.maride.cc/maride/php-parser/pkg/version"
|
2021-07-30 17:53:27 +00:00
|
|
|
"gotest.tools/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ParserErrorTestSuite struct {
|
|
|
|
t *testing.T
|
|
|
|
|
|
|
|
Code string
|
|
|
|
Expected []*errors.Error
|
|
|
|
|
|
|
|
Version version.Version
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewParserErrorTestSuite(t *testing.T) *ParserErrorTestSuite {
|
|
|
|
return &ParserErrorTestSuite{
|
|
|
|
t: t,
|
|
|
|
Version: version.Version{
|
|
|
|
Major: 7,
|
|
|
|
Minor: 4,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ParserErrorTestSuite) UsePHP8() {
|
|
|
|
p.Version = version.Version{Major: 8, Minor: 0}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ParserErrorTestSuite) Run() {
|
2023-03-26 00:54:00 +00:00
|
|
|
p.t.Helper()
|
2021-07-30 17:53:27 +00:00
|
|
|
config := conf.Config{
|
|
|
|
Version: &p.Version,
|
|
|
|
}
|
|
|
|
|
|
|
|
var errs []*errors.Error
|
|
|
|
|
|
|
|
config.ErrorHandlerFunc = func(e *errors.Error) {
|
|
|
|
errs = append(errs, e)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := parser.Parse([]byte(p.Code), config)
|
|
|
|
if err != nil {
|
|
|
|
p.t.Fatalf("Error parse: %v", err)
|
|
|
|
}
|
|
|
|
assert.DeepEqual(p.t, p.Expected, errs)
|
|
|
|
}
|