package tomltest
import "github.com/BurntSushi/toml/internal/toml-test"
Index ¶
- Constants
- func EmbeddedTests() fs.FS
- type CommandParser
- func NewCommandParser(fsys fs.FS, cmd []string) CommandParser
- func (c CommandParser) Decode(ctx context.Context, input string) (string, bool, error)
- func (c CommandParser) Encode(ctx context.Context, input string) (output string, outputIsError bool, err error)
- type Parser
- type Runner
- type Test
- func (r Test) CompareJSON(want, have any) Test
- func (r Test) CompareTOML(want, have any) Test
- func (t Test) Failed() bool
- func (t Test) ReadInput(fsys fs.FS) (path, data string, err error)
- func (t Test) ReadWant(fsys fs.FS) (path, data string, err error)
- func (t *Test) ReadWantJSON(fsys fs.FS) (v any, err error)
- func (t *Test) ReadWantTOML(fsys fs.FS) (v any, err error)
- func (t Test) Run(p Parser, fsys fs.FS) Test
- func (t Test) Type() testType
- type Tests
Constants ¶
const ( TypeValid testType = iota TypeInvalid )
Functions ¶
func EmbeddedTests ¶
EmbeddedTests are the tests embedded in toml-test, rooted to the "test/" directory.
Types ¶
type CommandParser ¶
type CommandParser struct {
// contains filtered or unexported fields
}
CommandParser calls an external command.
func NewCommandParser ¶
func NewCommandParser(fsys fs.FS, cmd []string) CommandParser
func (CommandParser) Decode ¶
func (CommandParser) Encode ¶
func (c CommandParser) Encode(ctx context.Context, input string) (output string, outputIsError bool, err error)
type Parser ¶
type Parser interface { // Encode a JSON string to TOML. // // The output is the TOML string; if outputIsError is true then it's assumed // that an encoding error occurred. // // An error return should only be used in case an unrecoverable error // occurred; failing to encode to TOML is not an error, but the encoder // unexpectedly panicking is. Encode(ctx context.Context, jsonInput string) (output string, outputIsError bool, err error) // Decode a TOML string to JSON. The same semantics as Encode apply. Decode(ctx context.Context, tomlInput string) (output string, outputIsError bool, err error) }
A Parser instance is used to call the TOML parser we test.
By default this is done through an external command.
type Runner ¶
type Runner struct { Files fs.FS // Test files. Encoder bool // Are we testing an encoder? RunTests []string // Tests to run; run all if blank. SkipTests []string // Tests to skip. Parser Parser // Send data to a parser. Version string // TOML version to run tests for. Parallel int // Number of tests to run in parallel Timeout time.Duration // Maximum time for parse. IntAsFloat bool // Int values have type=float. Errors map[string]string // Expected errors list. }
Runner runs a set of tests.
The validity of the parameters is not checked extensively; the caller should verify this if need be. See ./cmd/toml-test for an example.
func (Runner) List ¶
List all tests in Files for the current TOML version.
func (Runner) Run ¶
Run all tests listed in t.RunTests.
TODO: give option to: - Run all tests with \n replaced with \r\n - Run all tests with EOL removed - Run all tests with '# comment' appended to every line.
type Test ¶
type Test struct { Path string // Path of test, e.g. "valid/string-test" Skipped bool // Skipped this test? Failure string // Failure message. Key string // TOML key the failure occured on; may be blank. Encoder bool // Encoder test? Input string // The test case that we sent to the external program. Output string // Output from the external program. Want string // The output we want. OutputFromStderr bool // The Output came from stderr, not stdout. Timeout time.Duration // Maximum time for parse. IntAsFloat bool // Int values have type=float. }
Result is the result of a single test.
func (Test) CompareJSON ¶
CompareJSON compares the given arguments.
The returned value is a copy of Test with Failure set to a (human-readable) description of the first element that is unequal. If both arguments are equal, Test is returned unchanged.
reflect.DeepEqual could work here, but it won't tell us how the two structures are different.
func (Test) CompareTOML ¶
CompareTOML compares the given arguments.
The returned value is a copy of Test with Failure set to a (human-readable) description of the first element that is unequal. If both arguments are equal Test is returned unchanged.
Reflect.DeepEqual could work here, but it won't tell us how the two structures are different.
func (Test) Failed ¶
func (Test) ReadInput ¶
ReadInput reads the file sent to the encoder.
func (Test) ReadWant ¶
func (*Test) ReadWantJSON ¶
func (*Test) ReadWantTOML ¶
func (Test) Run ¶
Run this test.
func (Test) Type ¶
func (t Test) Type() testType
Test type: "valid", "invalid"
type Tests ¶
type Tests struct { Tests []Test Skipped int PassedValid, FailedValid int PassedInvalid, FailedInvalid int }
Tests are tests to run.
Source Files ¶
json.go runner.go toml.go version.go
- Version
- v1.4.0 (latest)
- Published
- May 23, 2024
- Platform
- linux/amd64
- Imports
- 18 packages
- Last checked
- 2 days ago –
Tools for package owners.