package jsontest
import "github.com/go-json-experiment/json/internal/jsontest"
Package jsontest contains functionality to assist in testing JSON.
Index ¶
Variables ¶
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.gz"), "_") for i := range words { words[i] = strings.Title(words[i]) } entry.Name = strings.Join(words, "") filePath := path.Join("testdata", fi.Name()) f := mustGet(testdataFS.Open(filePath)) defer f.Close() mustGet(f.(io.Seeker).Seek(-4, io.SeekEnd)) b := mustGet(io.ReadAll(f)) entry.Size = int(binary.LittleEndian.Uint32(b[:])) entry.Data = sync.OnceValue(func() []byte { b := mustGet(fs.ReadFile(testdataFS, filePath)) zr := mustGet(gzip.NewReader(bytes.NewReader(b))) data := mustGet(io.ReadAll(zr)) if len(data) != entry.Size { panic(fmt.Sprintf("size mismatch: got %d, want %d", len(data), entry.Size)) } return data }) 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.
Types ¶
type CaseName ¶
CaseName is a case name annotated with a file and line.
func Name ¶
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 ¶
type Entry ¶
type Entry struct { Name string Size int Data func() []byte New func() any // nil if there is no concrete type for this }
Source Files ¶
- Version
- v0.0.0-20250223041408-d3c622f1b874 (latest)
- Published
- Feb 23, 2025
- Platform
- linux/amd64
- Imports
- 14 packages
- Last checked
- 3 months ago –
Tools for package owners.