Fix Unquoted String scanning
This commit is contained in:
@ -1,6 +1,9 @@
|
||||
package nbt
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
_ "embed"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSNBT_number(t *testing.T) {
|
||||
goods := []string{
|
||||
@ -9,10 +12,6 @@ func TestSNBT_number(t *testing.T) {
|
||||
"255B", "1234s", "6666L",
|
||||
"314F", "3.14f", "3.14159265358979323846264D",
|
||||
}
|
||||
bads := []string{
|
||||
".0", "1234.5678.90",
|
||||
"25-5B", "1234.s",
|
||||
}
|
||||
var s scanner
|
||||
scan := func(str string) bool {
|
||||
s.reset()
|
||||
@ -29,36 +28,29 @@ func TestSNBT_number(t *testing.T) {
|
||||
t.Errorf("scan valid data %q error: %v", str, s.err)
|
||||
}
|
||||
}
|
||||
for _, str := range bads {
|
||||
if scan(str) {
|
||||
t.Errorf("scan invalid data %q success", str)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//go:embed bigTest_test.snbt
|
||||
var bigTest string
|
||||
|
||||
func TestSNBT_compound(t *testing.T) {
|
||||
goods := []string{
|
||||
`{}`, `{name:3.14f}`, `{ "name" : 12345 }`,
|
||||
`{ abc: { }}`, `{ "ab\"c": {}, def: 12345}`,
|
||||
`{ abc: { }}`, `{ "a b\"c": {}, def: 12345}`,
|
||||
bigTest,
|
||||
}
|
||||
var s scanner
|
||||
scan := func(str string) bool {
|
||||
for _, str := range goods {
|
||||
s.reset()
|
||||
for _, c := range []byte(str) {
|
||||
for i, c := range []byte(str) {
|
||||
res := s.step(c)
|
||||
if res == scanError {
|
||||
return false
|
||||
t.Errorf("scan valid data %q error: %v at [%d]", str[:i], s.err, i)
|
||||
break
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
for _, str := range goods {
|
||||
if scan(str) == false {
|
||||
t.Errorf("scan valid data %q error: %v", str, s.err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSNBT_list(t *testing.T) {
|
||||
goods := []string{
|
||||
`[]`, `[a, 'b', "c", d]`, // List of string
|
||||
|
Reference in New Issue
Block a user