jsontest

package standard library
go1.25rc2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2025 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package jsontest contains functionality to assist in testing JSON.

Index

Constants

This section is empty.

Variables

View Source
var Data = func() (entries []Entry) {
	fis := mustGet(fs.ReadDir(testdataFS, "testdata"))
	slices.SortFunc(fis, func(x, y fs.DirEntry) int { return strings.Compare(x.Name(), y.Name()) })
	for _, fi := range fis {
		var entry Entry

		words := strings.Split(strings.TrimSuffix(fi.Name(), ".json.zst"), "_")
		for i := range words {
			words[i] = strings.Title(words[i])
		}
		entry.Name = strings.Join(words, "")

		entry.Data = sync.OnceValue(func() []byte {
			filePath := path.Join("testdata", fi.Name())
			b := mustGet(fs.ReadFile(testdataFS, filePath))
			zr := zstd.NewReader(bytes.NewReader(b))
			return mustGet(io.ReadAll(zr))
		})

		switch entry.Name {
		case "CanadaGeometry":
			entry.New = func() any { return new(canadaRoot) }
		case "CitmCatalog":
			entry.New = func() any { return new(citmRoot) }
		case "GolangSource":
			entry.New = func() any { return new(golangRoot) }
		case "StringEscaped":
			entry.New = func() any { return new(stringRoot) }
		case "StringUnicode":
			entry.New = func() any { return new(stringRoot) }
		case "SyntheaFhir":
			entry.New = func() any { return new(syntheaRoot) }
		case "TwitterStatus":
			entry.New = func() any { return new(twitterRoot) }
		}

		entries = append(entries, entry)
	}
	return entries
}()

Data is a list of JSON testdata.

Functions

This section is empty.

Types

type CaseName

type CaseName struct {
	Name  string
	Where CasePos
}

CaseName is a case name annotated with a file and line.

func Name

func Name(s string) (c CaseName)

Name annotates a case name with the file and line of the caller.

type CasePos

type CasePos struct {
	// contains filtered or unexported fields
}

CasePos represents a file and line number.

func (CasePos) String

func (pos CasePos) String() string

type Entry

type Entry struct {
	Name string
	Data func() []byte
	New  func() any // nil if there is no concrete type for this
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL