Make use of the new feature to run without sanity check on the parser, to make the big testfiles-based test suite faster.
This commit is contained in:
parent
9680c2b844
commit
a28269800a
|
@ -254,8 +254,8 @@ func testAST(t *testing.T, code func() (error, *ast.Document), expectedError str
|
||||||
|
|
||||||
func Test_NewArray(t *testing.T) {
|
func Test_NewArray(t *testing.T) {
|
||||||
a := ast.NewArray()
|
a := ast.NewArray()
|
||||||
if a.Type != "" {
|
if a.ItemType != "" {
|
||||||
t.Fatalf("New array unexpectedly has a Type set to %q", a.Type)
|
t.Fatalf("New array unexpectedly has a Type set to %q", a.ItemType)
|
||||||
}
|
}
|
||||||
if a.First != nil {
|
if a.First != nil {
|
||||||
t.Fatalf("New array unexpectedly has the First item set")
|
t.Fatalf("New array unexpectedly has the First item set")
|
||||||
|
|
|
@ -2,6 +2,7 @@ package parse
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.makaay.nl/mauricem/go-parsekit/parse"
|
"git.makaay.nl/mauricem/go-parsekit/parse"
|
||||||
|
"git.makaay.nl/mauricem/go-toml/ast"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The primary building block of a TOML document is the table.
|
// The primary building block of a TOML document is the table.
|
||||||
|
@ -35,7 +36,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (t *parser) startKeyValuePair(p *parse.API) {
|
func (t *parser) startKeyValuePair(p *parse.API) {
|
||||||
key, ok := t.parseKey(p, []string{})
|
key, ok := t.parseKey(p, ast.NewKey())
|
||||||
if ok && p.Handle(t.startAssignment) {
|
if ok && p.Handle(t.startAssignment) {
|
||||||
if value, ok := t.parseValue(p); ok {
|
if value, ok := t.parseValue(p); ok {
|
||||||
err := t.doc.SetKeyValuePair(key, value)
|
err := t.doc.SetKeyValuePair(key, value)
|
||||||
|
@ -57,7 +58,7 @@ func (t *parser) startKeyValuePair(p *parse.API) {
|
||||||
// is to use bare keys except when absolutely necessary.
|
// is to use bare keys except when absolutely necessary.
|
||||||
// A bare key must be non-empty, but an empty quoted key is allowed (though
|
// A bare key must be non-empty, but an empty quoted key is allowed (though
|
||||||
// discouraged).
|
// discouraged).
|
||||||
func (t *parser) parseKey(p *parse.API, key []string) ([]string, bool) {
|
func (t *parser) parseKey(p *parse.API, key ast.Key) (ast.Key, bool) {
|
||||||
var keyPart string
|
var keyPart string
|
||||||
var ok bool
|
var ok bool
|
||||||
switch {
|
switch {
|
||||||
|
@ -82,7 +83,7 @@ func (t *parser) parseKey(p *parse.API, key []string) ([]string, bool) {
|
||||||
// This allows for grouping similar properties together.
|
// This allows for grouping similar properties together.
|
||||||
// Whitespace around dot-separated parts is ignored, however, best
|
// Whitespace around dot-separated parts is ignored, however, best
|
||||||
// practice is to not use any extraneous whitespace.
|
// practice is to not use any extraneous whitespace.
|
||||||
func (t *parser) parseEndOfKeyOrDot(p *parse.API, key []string) ([]string, bool) {
|
func (t *parser) parseEndOfKeyOrDot(p *parse.API, key ast.Key) (ast.Key, bool) {
|
||||||
if p.Accept(keySeparatorDot) {
|
if p.Accept(keySeparatorDot) {
|
||||||
return t.parseKey(p, key)
|
return t.parseKey(p, key)
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,3 +58,11 @@ func Run(input interface{}) (ast.Table, error) {
|
||||||
err := parse.New(p.startDocument)(input)
|
err := parse.New(p.startDocument)(input)
|
||||||
return p.doc.Root, err
|
return p.doc.Root, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RunWithoutSanityChecks runs the TOML parser against the provided input data.
|
||||||
|
// The parsekit sanity checks are disabled during the parse run.
|
||||||
|
func RunWithoutSanityChecks(input interface{}) (ast.Table, error) {
|
||||||
|
p := newParser()
|
||||||
|
err := parse.NewWithoutSanityChecks(p.startDocument)(input)
|
||||||
|
return p.doc.Root, err
|
||||||
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.makaay.nl/mauricem/go-toml/parse"
|
"git.makaay.nl/mauricem/go-toml/parse"
|
||||||
|
"github.com/pkg/profile"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_Invalid(t *testing.T) {
|
func Test_Invalid(t *testing.T) {
|
||||||
|
@ -37,6 +38,7 @@ func Test_Invalid(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_Valid(t *testing.T) {
|
func Test_Valid(t *testing.T) {
|
||||||
|
defer profile.Start().Stop()
|
||||||
for _, suite := range getTestSuites("valid") {
|
for _, suite := range getTestSuites("valid") {
|
||||||
success := 0
|
success := 0
|
||||||
fail := 0
|
fail := 0
|
||||||
|
@ -45,7 +47,7 @@ func Test_Valid(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("Cannot open toml file for test (%v): %s", testCase, err))
|
panic(fmt.Sprintf("Cannot open toml file for test (%v): %s", testCase, err))
|
||||||
}
|
}
|
||||||
tomlTable, err := parse.Run(input)
|
tomlTable, err := parse.RunWithoutSanityChecks(input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("[%s] parse failed unexpectedly: %s", name, err)
|
t.Errorf("[%s] parse failed unexpectedly: %s", name, err)
|
||||||
fail++
|
fail++
|
||||||
|
@ -160,13 +162,15 @@ func cmpJsonObjects(key string, expected map[string]interface{}, a interface{})
|
||||||
actual, _ := a.(map[string]interface{})
|
actual, _ := a.(map[string]interface{})
|
||||||
|
|
||||||
// Check to make sure both or neither are values.
|
// Check to make sure both or neither are values.
|
||||||
if isValue(expected) && !isValue(actual) {
|
eIsVal := isValue(expected)
|
||||||
|
aIsVal := isValue(actual)
|
||||||
|
if eIsVal && !aIsVal {
|
||||||
return fmt.Errorf("Key '%s' is supposed to be a value, but the parser reports it as a table.", key)
|
return fmt.Errorf("Key '%s' is supposed to be a value, but the parser reports it as a table.", key)
|
||||||
}
|
}
|
||||||
if !isValue(expected) && isValue(actual) {
|
if !eIsVal && aIsVal {
|
||||||
return fmt.Errorf("Key '%s' is supposed to be a table, but the parser reports it as a value.", key)
|
return fmt.Errorf("Key '%s' is supposed to be a table, but the parser reports it as a value.", key)
|
||||||
}
|
}
|
||||||
if isValue(expected) && isValue(actual) {
|
if eIsVal && aIsVal {
|
||||||
return cmpJsonValues(key, expected, actual)
|
return cmpJsonValues(key, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue