conformance

package
v6.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package conformance generates the cross-language corpus: cases produced by this implementation, with the result it produces, so another implementation can check that it agrees.

The model types carry generated code deliberately. The generator emits paths using JSON names ("/status"), which is what a JSON document's keys are called in every language; the reflection engine emits Go field names ("/Status"), which only Go can resolve. Generated code is therefore the interop contract, and the corpus is generated through it.

Code generated by deep-gen. DO NOT EDIT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Doc

type Doc struct {
	Title  string            `json:"title"`
	Status string            `json:"status"`
	Score  int               `json:"score"`
	Meta   Meta              `json:"meta"`
	Items  []Item            `json:"items"`
	Tags   []string          `json:"tags"`
	Fields map[string]string `json:"fields"`
}

Doc is the corpus model: scalars, a nested struct, a keyed slice, a plain slice, and a map — one of each shape a patch has to address.

No field uses `omitempty`, deliberately. It makes a zero value and an absent field the same bytes, so a patch that sets a field to its zero produces JSON a receiver cannot distinguish from one where the field was never there — and a JavaScript replica then disagrees with Go about the document while both applied the same operations. A model that syncs across languages should leave it off; see docs/wire-patch.md.

func (*Doc) Clone

func (t *Doc) Clone() *Doc

Clone returns a deep copy of t.

func (*Doc) Diff

func (t *Doc) Diff(other *Doc) deep.Patch[Doc]

Diff compares t with other and returns a Patch.

func (*Doc) Equal

func (t *Doc) Equal(other *Doc) bool

Equal returns true if t and other are deeply equal.

func (*Doc) Patch

func (t *Doc) Patch(p deep.Patch[Doc], logger *slog.Logger) error

Patch applies p to t using the generated fast path.

type Item

type Item struct {
	ID    string `deep:"key" json:"id"`
	Label string `json:"label"`
	Count int    `json:"count"`
	Done  bool   `json:"done"`
}

Item is an element with an identity: diffs address it as /items/<id>.

func (*Item) Clone

func (t *Item) Clone() *Item

Clone returns a deep copy of t.

func (*Item) Diff

func (t *Item) Diff(other *Item) deep.Patch[Item]

Diff compares t with other and returns a Patch.

func (*Item) Equal

func (t *Item) Equal(other *Item) bool

Equal returns true if t and other are deeply equal.

func (*Item) Patch

func (t *Item) Patch(p deep.Patch[Item], logger *slog.Logger) error

Patch applies p to t using the generated fast path.

type Meta

type Meta struct {
	Owner string `json:"owner"`
	Level int    `json:"level"`
}

Meta is a nested object.

func (*Meta) Clone

func (t *Meta) Clone() *Meta

Clone returns a deep copy of t.

func (*Meta) Diff

func (t *Meta) Diff(other *Meta) deep.Patch[Meta]

Diff compares t with other and returns a Patch.

func (*Meta) Equal

func (t *Meta) Equal(other *Meta) bool

Equal returns true if t and other are deeply equal.

func (*Meta) Patch

func (t *Meta) Patch(p deep.Patch[Meta], logger *slog.Logger) error

Patch applies p to t using the generated fast path.

type Odd

type Odd struct {
	Ratio int    `json:"a/b"`
	Tilde int    `json:"c~d"`
	Plain string `json:"plain"`
}

Odd carries JSON names that need RFC 6901 escaping when they become path tokens. It is generated, so its case covers the generator's escaping; the reflection engine's is covered by a unit test in the root package. Both must produce the same paths, or a patch means one thing to a Go peer and another to everyone else.

func (*Odd) Clone

func (t *Odd) Clone() *Odd

Clone returns a deep copy of t.

func (*Odd) Diff

func (t *Odd) Diff(other *Odd) deep.Patch[Odd]

Diff compares t with other and returns a Patch.

func (*Odd) Equal

func (t *Odd) Equal(other *Odd) bool

Equal returns true if t and other are deeply equal.

func (*Odd) Patch

func (t *Odd) Patch(p deep.Patch[Odd], logger *slog.Logger) error

Patch applies p to t using the generated fast path.

type Plain

type Plain struct {
	Label  string         `json:"label"`
	Depth  int            `json:"depth"`
	Nested PlainNested    `json:"nested"`
	Values map[string]int `json:"values"`
	// No json tag: there is nothing to call this but its Go name.
	Untagged string
	// Kept out of the document, and so out of patches, equality and clones.
	Secret string `json:"-"`
}

Plain is deliberately absent from the go:generate list above, so a diff of it goes through the reflection engine. Its cases prove that both engines name fields the same way — a reflection engine that named them the Go way would produce patches no other language could apply.

type PlainNested

type PlainNested struct {
	Owner string `json:"owner"`
}

PlainNested is likewise ungenerated.

Jump to

Keyboard shortcuts

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