2021-07-30 17:53:27 +00:00
|
|
|
package tester
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-03-31 14:50:08 +00:00
|
|
|
"github.com/laytan/php-parser/internal/php7"
|
|
|
|
"github.com/laytan/php-parser/internal/php8"
|
|
|
|
"github.com/laytan/php-parser/pkg/conf"
|
|
|
|
"github.com/laytan/php-parser/pkg/version"
|
2021-07-30 17:53:27 +00:00
|
|
|
"gotest.tools/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
type LexerTokenStringTestSuite struct {
|
|
|
|
t *testing.T
|
|
|
|
|
|
|
|
Code string
|
|
|
|
Expected []string
|
|
|
|
|
|
|
|
Version version.Version
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewLexerTokenStringTestSuite(t *testing.T) *LexerTokenStringTestSuite {
|
|
|
|
return &LexerTokenStringTestSuite{
|
|
|
|
t: t,
|
|
|
|
Version: version.Version{
|
|
|
|
Major: 7,
|
|
|
|
Minor: 4,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *LexerTokenStringTestSuite) UsePHP8() {
|
|
|
|
l.Version = version.Version{Major: 8, Minor: 0}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *LexerTokenStringTestSuite) Run() {
|
|
|
|
config := conf.Config{
|
|
|
|
Version: &l.Version,
|
|
|
|
}
|
|
|
|
|
|
|
|
var lexer Lexer
|
|
|
|
|
|
|
|
if l.Version.Less(&version.Version{Major: 8, Minor: 0}) {
|
2023-03-25 14:02:34 +00:00
|
|
|
lexer = php7.NewLexer([]byte(l.Code), config)
|
2021-07-30 17:53:27 +00:00
|
|
|
} else {
|
|
|
|
lexer = php8.NewLexer([]byte(l.Code), config)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, expected := range l.Expected {
|
|
|
|
tkn := lexer.Lex()
|
|
|
|
actual := string(tkn.Value)
|
|
|
|
assert.DeepEqual(l.t, expected, actual)
|
|
|
|
}
|
|
|
|
}
|