Documentation
¶
Overview ¶
Package fixture decodes and validates the immutable upstream fixtures used by Untie's conformance tests.
This package is intentionally outside the renderer's runtime pipeline. It decodes Typlet's compact CST and diagnostics, then adapts fixture-only encodings, such as UTF-16 offsets and points, at one boundary so parser, IR, layout, and output packages never inherit them.
Index ¶
- Constants
- Variables
- func CanonicalJSON(value any) ([]byte, error)
- func ConvertUTF16Range(src string, r UTF16Range) (source.Range, error)
- func CorpusRoot(start string) (string, error)
- func DIPToPoints(dip float64) (float64, error)
- func NormalizeJSON(data []byte) ([]byte, error)
- func PointsToDIP(points float64) (float64, error)
- func SHA256File(filePath string) (checksum string, err error)
- func UTF16OffsetsToByteRange(src string, start, end int) (source.Range, error)
- func VerifySHA256Manifest(root, manifestFile string) error
- type CMapEntry
- type CSTNode
- type Case
- type Classification
- type Corpus
- type CorpusFormat
- type CorpusManifest
- type CorpusSpec
- type Fixture
- type FixtureDiagnostic
- type FontAssembly
- type FontAssemblyPart
- type FontCMap
- type FontDump
- type FontGlyph
- type FontHeader
- type FontKern
- type FontLineMetric
- type FontMetrics
- type FontScriptMetric
- type FontShape
- type FontShapingResult
- type Formula
- type Frame
- type FrameBox
- type FrameDiff
- type FrameGlyph
- type FrameLayout
- type FrameShape
- type GlyphConstruction
- type GlyphPlacement
- type GoldenMismatch
- type KaTeXCase
- type KnownDifferenceEntry
- type ManifestEntry
- type Outcome
- type PathInfo
- type Report
- type ResolvedDiagnostic
- type ResolvedFixture
- type Result
- type RunFunc
- type RunOptions
- type ShapeStroke
- type ShapedGlyph
- type SourceCSTNode
- type TypletSelection
- type UTF16BoundaryError
- type UTF16Range
Constants ¶
const DIPPerPoint = 4.0 / 3.0
DIPPerPoint is the CSS conversion factor for physical points.
const TypletFrameToleranceDIP = TypletFrameTolerancePoints * DIPPerPoint
TypletFrameToleranceDIP is the same tolerance after conversion to DIP.
const TypletFrameTolerancePoints = 0.0015
TypletFrameTolerancePoints is Typlet's reviewed frame comparison tolerance.
Variables ¶
var ErrInvalidUTF8 = errors.New("fixture: source is not valid UTF-8")
ErrInvalidUTF8 reports a fixture source that cannot be represented as a JavaScript/TypeScript string. UTF-16 offsets have no meaning for such input.
Functions ¶
func CanonicalJSON ¶
CanonicalJSON marshals value with stable map ordering, no HTML escaping, and one trailing newline. It is intended for reviewed test snapshots only.
func ConvertUTF16Range ¶
func ConvertUTF16Range(src string, r UTF16Range) (source.Range, error)
ConvertUTF16Range converts r to UTF-8 byte offsets.
func CorpusRoot ¶
CorpusRoot resolves the tracked fixture root relative to any working directory by finding the nearest go.mod.
func DIPToPoints ¶
DIPToPoints converts device-independent pixels to fixture points.
func NormalizeJSON ¶
NormalizeJSON validates JSON and returns its canonical representation.
func PointsToDIP ¶
Points converts fixture points to device-independent pixels.
func SHA256File ¶
SHA256File returns the lowercase hexadecimal SHA-256 of a file.
func UTF16OffsetsToByteRange ¶
UTF16OffsetsToByteRange converts a half-open UTF-16 range to UTF-8 byte offsets. The complete source must be valid UTF-8. Both offsets must be on code-point boundaries and within the source.
func VerifySHA256Manifest ¶
VerifySHA256Manifest verifies every listed file and rejects unlisted files. The manifest itself is the only excluded path below root.
Types ¶
type CMapEntry ¶
CMapEntry maps text to one glyph ID.
func (*CMapEntry) UnmarshalJSON ¶
UnmarshalJSON decodes a [text, glyph] tuple.
type CSTNode ¶
type CSTNode struct {
Kind string
Span UTF16Range
Message string
Hints []string
Children []CSTNode
}
CSTNode is one node in Typlet's compact Typst concrete syntax tree. Its offsets are UTF-16 code units; ResolveCST converts them to UTF-8 byte ranges.
func (CSTNode) MarshalJSON ¶
MarshalJSON restores a deterministic compact node array.
func (*CSTNode) UnmarshalJSON ¶
UnmarshalJSON decodes Typlet's compact node arrays:
[kind, start, end] [kind, start, end, children] ["Error", start, end, message, hints]
type Case ¶
type Case struct {
Index int
ID string
Source string
Display bool
Preamble string
TeX string
Category string
Fixture *Fixture
CST *SourceCSTNode
Diagnostics []ResolvedDiagnostic
Meta json.RawMessage
}
Case is one loaded corpus record. Index is one-based and follows source order. A case without a frame fixture is still runnable; it is never omitted.
type Classification ¶
type Classification string
Classification is the required disposition of every corpus case.
const ( Pass Classification = "pass" DiagnosticExpected Classification = "diagnostic-expected" UnsupportedByScope Classification = "unsupported-by-scope" KnownDifference Classification = "known-difference" Bug Classification = "bug" )
type Corpus ¶
type Corpus struct {
Name string
Spec CorpusSpec
Cases []Case
}
Corpus is a manifest-backed, ordered set of cases.
func LoadAllCorpora ¶
func LoadAllCorpora(root string, manifest *CorpusManifest) ([]*Corpus, error)
LoadAllCorpora loads every corpus in declaration order.
func LoadCorpus ¶
func LoadCorpus(root string, spec CorpusSpec) (*Corpus, error)
LoadCorpus loads every case declared by spec and enforces exact counts.
type CorpusFormat ¶
type CorpusFormat string
CorpusFormat identifies a supported corpus encoding.
const ( TypletJSONL CorpusFormat = "typlet-jsonl" RawLines CorpusFormat = "raw-lines" KaTeXJSONL CorpusFormat = "katex-jsonl" )
type CorpusManifest ¶
type CorpusManifest struct {
SchemaVersion int `json:"schemaVersion"`
Corpora []CorpusSpec `json:"corpora"`
}
CorpusManifest is the tracked declaration of all importable corpora.
func LoadCorpusManifest ¶
func LoadCorpusManifest(filePath string) (*CorpusManifest, error)
LoadCorpusManifest decodes and validates manifests/corpora.json.
func (*CorpusManifest) Validate ¶
func (m *CorpusManifest) Validate() error
Validate checks corpus declarations for ambiguity and missing count data.
type CorpusSpec ¶
type CorpusSpec struct {
Name string `json:"name"`
Format CorpusFormat `json:"format"`
CorpusFile string `json:"corpusFile"`
FixtureFile string `json:"fixtureFile,omitempty"`
ExpectedCount int `json:"expectedCount"`
ExpectedFixtureCount int `json:"expectedFixtureCount,omitempty"`
ExpectedFrameCount *int `json:"expectedFrameCount,omitempty"`
SelectionFile string `json:"selectionFile,omitempty"`
SelectionKey string `json:"selectionKey,omitempty"`
KnownDifferences []KnownDifferenceEntry `json:"knownDifferences,omitempty"`
}
CorpusSpec declares one loadable corpus and its exact expected counts.
func (CorpusSpec) KnownDifferenceFor ¶
func (s CorpusSpec) KnownDifferenceFor(id string) (string, bool)
KnownDifferenceFor returns the reviewed reason for id, if any.
type Fixture ¶
type Fixture struct {
ID string `json:"id"`
CST *CSTNode `json:"cst,omitempty"`
Frame *Frame `json:"frame"`
Diagnostics []FixtureDiagnostic `json:"diagnostics,omitempty"`
}
Fixture is one Typlet fixture record. ID, CST, diagnostics, and the flattened frame are decoded; unrelated semantic payloads remain opaque.
func LoadFixtures ¶
LoadFixtures decodes a Typlet JSON Lines fixture file.
type FixtureDiagnostic ¶
type FixtureDiagnostic struct {
Raw json.RawMessage
At string
Message string
Severity string
Hints []string
Span *UTF16Range
}
FixtureDiagnostic is an upstream diagnostic with its stable fields decoded. Raw is retained because diagnostics from different Typst layers do not share one complete shape.
func (FixtureDiagnostic) MarshalJSON ¶
func (d FixtureDiagnostic) MarshalJSON() ([]byte, error)
MarshalJSON restores the complete diagnostic record.
func (*FixtureDiagnostic) UnmarshalJSON ¶
func (d *FixtureDiagnostic) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes the stable diagnostic fields and retains the complete record. A span, when present, is a UTF-16 half-open range.
func (FixtureDiagnostic) Validate ¶
func (d FixtureDiagnostic) Validate() error
Validate checks stable diagnostic fields without a source string.
type FontAssembly ¶
type FontAssembly struct {
Italic float64 `json:"italic"`
Parts []FontAssemblyPart `json:"parts"`
}
FontAssembly is a MATH glyph assembly.
type FontAssemblyPart ¶
type FontAssemblyPart struct {
Glyph uint16
StartConnector float64
EndConnector float64
FullAdvance float64
Extender bool
}
FontAssemblyPart is one connector part of an assembly.
func (*FontAssemblyPart) UnmarshalJSON ¶
func (p *FontAssemblyPart) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes Typst's compact five-element assembly part tuple.
type FontCMap ¶
type FontCMap struct {
Kind string `json:"kind"`
Chars []CMapEntry `json:"chars"`
Sequences []CMapEntry `json:"sequences"`
}
FontCMap is the font's character and variation-sequence mapping.
type FontDump ¶
type FontDump struct {
Header *FontHeader
Glyphs []FontGlyph
CMap *FontCMap
Shapes []FontShape
}
FontDump is Typlet's NewCM metric and shaping dump.
func LoadFontDump ¶
LoadFontDump decodes a Typlet font JSON Lines dump.
type FontGlyph ¶
type FontGlyph struct {
Kind string `json:"kind"`
ID uint16 `json:"id"`
Advance *float64 `json:"advance,omitempty"`
BBox *[4]float64 `json:"bbox,omitempty"`
Italic *float64 `json:"italic,omitempty"`
Accent *float64 `json:"accent,omitempty"`
Extended bool `json:"extended,omitempty"`
Vertical *GlyphConstruction `json:"vertical,omitempty"`
Horizontal *GlyphConstruction `json:"horizontal,omitempty"`
Kern map[string]FontKern `json:"kern,omitempty"`
}
FontGlyph is one glyph record.
type FontHeader ¶
type FontHeader struct {
Kind string `json:"kind"`
GlyphCount int `json:"glyphCount"`
GSUBFeatures []string `json:"gsubFeatures"`
Math map[string]float64 `json:"math"`
Metrics FontMetrics `json:"metrics"`
MinConnectorOverlap int `json:"minConnectorOverlap"`
PostScriptName string `json:"postScriptName"`
UnitsPerEm int `json:"unitsPerEm"`
}
FontHeader holds face-wide metrics and the OpenType MATH constants observed by Typst. MATH constants are in ems; glyph metrics are in font design units.
type FontLineMetric ¶
type FontLineMetric struct {
Position float64 `json:"position"`
Thickness float64 `json:"thickness"`
}
FontLineMetric is a decoration position and thickness.
type FontMetrics ¶
type FontMetrics struct {
Ascender float64 `json:"ascender"`
CapHeight float64 `json:"capHeight"`
Descender float64 `json:"descender"`
Overline FontLineMetric `json:"overline"`
Strikethrough FontLineMetric `json:"strikethrough"`
Subscript FontScriptMetric `json:"subscript"`
Superscript FontScriptMetric `json:"superscript"`
Underline FontLineMetric `json:"underline"`
XHeight float64 `json:"xHeight"`
}
FontMetrics is the text metric subset recorded by Typlet.
type FontScriptMetric ¶
type FontScriptMetric struct {
Height float64 `json:"height"`
HorizontalOffset float64 `json:"horizontalOffset"`
VerticalOffset float64 `json:"verticalOffset"`
Width float64 `json:"width"`
}
FontScriptMetric is an OpenType script-line metric.
type FontShape ¶
type FontShape struct {
Kind string `json:"kind"`
Features []string `json:"features"`
Results []FontShapingResult `json:"results"`
}
FontShape is one HarfBuzz shaping result observed by Typst.
type FontShapingResult ¶
type FontShapingResult struct {
Text string
Glyphs []ShapedGlyph
}
FontShapingResult maps input text to an output glyph run.
func (*FontShapingResult) UnmarshalJSON ¶
func (r *FontShapingResult) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes a [text, glyph run] tuple.
type Formula ¶
type Formula struct {
ID string `json:"id"`
Source string `json:"src"`
Display bool `json:"display"`
Preamble string `json:"preamble,omitempty"`
TeX string `json:"tex,omitempty"`
Category string `json:"cat,omitempty"`
Meta json.RawMessage `json:"meta,omitempty"`
}
Formula is one record from a Typlet formula corpus.
func LoadFormulas ¶
LoadFormulas decodes a Typlet JSON Lines formula corpus.
type Frame ¶
type Frame struct {
Box *FrameBox `json:"box"`
FontSize float64 `json:"fontSize"`
Fonts []string `json:"fonts"`
Glyphs []FrameGlyph `json:"glyphs"`
Page [2]float64 `json:"page"`
Shapes []FrameShape `json:"shapes"`
}
Frame is Typlet's flattened layout frame, in fixture points.
func FlattenFrame ¶
func FlattenFrame(layout FrameLayout) (Frame, error)
FlattenFrame converts named fonts to Typlet's first-use font indices and validates the resulting fixture frame. It preserves glyph and shape order.
func FrameToDIP ¶
FrameToDIP is the sole frame-unit adapter. Geometry, widths, positions, sizes, and stroke thicknesses become DIP. Linear transform coefficients and colors are unitless and remain unchanged.
func (Frame) MarshalJSON ¶
MarshalJSON makes the custom array and object encoders reachable through encoding/json without losing the outer frame shape.
func (*Frame) UnmarshalJSON ¶
UnmarshalJSON decodes a frame and validates that every glyph references a declared font.
type FrameBox ¶
type FrameBox struct {
Anchor string `json:"anchor"`
Width *float64 `json:"width"`
Height *float64 `json:"height,omitempty"`
Ascent *float64 `json:"ascent,omitempty"`
Descent *float64 `json:"descent,omitempty"`
}
FrameBox is either baseline-anchored (width/ascent/descent) or top-anchored (width/height).
func (*FrameBox) UnmarshalJSON ¶
UnmarshalJSON decodes and validates a frame box.
type FrameDiff ¶
FrameDiff is the first deterministic difference between two frames.
func CompareFrames ¶
CompareFrames compares frames in the same unit using tolerance. A non-nil result is deterministic: it always reports the first differing field in box, glyph, then shape order.
type FrameGlyph ¶
type FrameGlyph struct {
Font int
Glyph uint32
X float64
Y float64
Size float64
Text string
Fill string
HasFill bool
Transform [4]float64
HasTransform bool
}
FrameGlyph is one entry of Typlet's compact glyph tuple: [font, glyph, x, y, size, text, fill?, transform?].
func (FrameGlyph) MarshalJSON ¶
func (g FrameGlyph) MarshalJSON() ([]byte, error)
MarshalJSON restores the compact array representation.
func (*FrameGlyph) UnmarshalJSON ¶
func (g *FrameGlyph) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes the compact array representation.
type FrameLayout ¶
type FrameLayout struct {
Box FrameBox
FontSize float64
Page [2]float64
Glyphs []GlyphPlacement
Shapes []FrameShape
}
FrameLayout is an already-flattened paint-order glyph and shape stream. It is the fixture-side interface used by layout tests before encoding to JSON.
func (FrameLayout) Validate ¶
func (l FrameLayout) Validate() error
Validate checks a frame layout without encoding it.
type FrameShape ¶
type FrameShape struct {
Line []float64
Rect []float64
Box []float64
Fill string
HasFill bool
Stroke *ShapeStroke
}
FrameShape is one flattened line, rectangle, or box shape.
func (FrameShape) MarshalJSON ¶
func (s FrameShape) MarshalJSON() ([]byte, error)
MarshalJSON restores a deterministic frame shape object.
func (FrameShape) ShapeGeometry ¶
func (s FrameShape) ShapeGeometry() string
ShapeGeometry reports which geometry a shape carries.
func (FrameShape) ShapeGeometryValues ¶
func (s FrameShape) ShapeGeometryValues() []float64
ShapeGeometryValues returns the selected geometry values.
func (*FrameShape) UnmarshalJSON ¶
func (s *FrameShape) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes and validates a frame shape.
type GlyphConstruction ¶
type GlyphConstruction struct {
Variants [][2]int `json:"variants"`
Assembly *FontAssembly `json:"assembly"`
}
GlyphConstruction holds size variants and an optional assembly.
type GlyphPlacement ¶
type GlyphPlacement struct {
Font string
Glyph uint32
X float64
Y float64
Size float64
Text string
Fill *string
Transform *[4]float64
}
GlyphPlacement is one already-positioned glyph in fixture points. Font is a face name because Typlet fixture glyphs refer to faces by an index.
type GoldenMismatch ¶
type GoldenMismatch struct {
Name string
Format string
Line int
Byte int
Expected string
Actual string
}
GoldenMismatch is the first deterministic difference between golden data and actual output.
func CompareGolden ¶
func CompareGolden(name string, got, want []byte) *GoldenMismatch
CompareGolden compares text or byte output and reports the first differing line. It never writes or updates golden files.
func CompareJSONGolden ¶
func CompareJSONGolden(name string, got, want []byte) (*GoldenMismatch, error)
CompareJSONGolden validates both inputs and compares canonical JSON.
func (*GoldenMismatch) String ¶
func (m *GoldenMismatch) String() string
String reports a stable, bounded diagnostic suitable for test output.
type KaTeXCase ¶
type KaTeXCase struct {
ID string `json:"id"`
Source string `json:"source"`
Kind string `json:"kind"`
Expected string `json:"expected"`
Position *int `json:"position,omitempty"`
Strict bool `json:"strict,omitempty"`
Upstream string `json:"upstream"`
}
KaTeXCase is one normalized parser or error test transcribed from KaTeX.
type KnownDifferenceEntry ¶
KnownDifferenceEntry is an explicit, reviewed exclusion from strict matching.
type ManifestEntry ¶
ManifestEntry is one SHA-256 manifest row.
func LoadSHA256Manifest ¶
func LoadSHA256Manifest(filePath string) (entries []ManifestEntry, err error)
LoadSHA256Manifest decodes a strict "hash relative/path" manifest.
type Outcome ¶
type Outcome struct {
Classification Classification
Frame *Frame
Detail string
}
Outcome is returned for every case. There is deliberately no skip state.
type Report ¶
type Report struct {
Corpus string
Total int
Pass int
DiagnosticExpected int
UnsupportedByScope int
KnownDifference int
Bug int
Results []Result
}
Report accounts for every attempted case. Validate proves that the counts sum to Total and that no result is missing or duplicated.
func RunCorpus ¶
func RunCorpus(ctx context.Context, corpus *Corpus, options RunOptions, run RunFunc) (Report, error)
RunCorpus invokes run for every case in source order. A callback error and a wrong frame become explicit Bug results rather than omitted cases. Invalid classifications and undeclared known differences are programmer errors and stop the run.
type ResolvedDiagnostic ¶
type ResolvedDiagnostic struct {
Raw json.RawMessage
At string
Message string
Severity string
Hints []string
HasSpan bool
Span source.Range
}
ResolvedDiagnostic is a diagnostic whose optional span has been converted to a UTF-8 byte range. At identifies whether Span addresses Src or Preamble.
type ResolvedFixture ¶
type ResolvedFixture struct {
CST *SourceCSTNode
Diagnostics []ResolvedDiagnostic
}
ResolvedFixture contains the fixture payloads that use source offsets.
func ResolveFixture ¶
func ResolveFixture(src, preamble string, fixture *Fixture) (*ResolvedFixture, error)
ResolveFixture converts all CST and diagnostic UTF-16 offsets to UTF-8 byte ranges. Diagnostics with At set to "src" use src; "preamble" diagnostics use preamble.
type Result ¶
type Result struct {
Index int
ID string
Classification Classification
Detail string
}
Result is the deterministic result for one case.
type RunOptions ¶
type RunOptions struct {
Tolerance float64
}
RunOptions controls frame comparison and report size.
type ShapeStroke ¶
ShapeStroke is a fixture stroke: color and thickness in points.
func (ShapeStroke) MarshalJSON ¶
func (s ShapeStroke) MarshalJSON() ([]byte, error)
MarshalJSON restores the compact [color, thickness] representation.
type ShapedGlyph ¶
ShapedGlyph is one glyph and its shaping displacement in design units.
type SourceCSTNode ¶
type SourceCSTNode struct {
Kind string
Span source.Range
Message string
Hints []string
Children []SourceCSTNode
}
SourceCSTNode is a CST node with a validated UTF-8 byte range.
func ResolveCST ¶
func ResolveCST(src string, root *CSTNode) (*SourceCSTNode, error)
ResolveCST converts every node offset in the UTF-16 CST to a UTF-8 byte range.
type TypletSelection ¶
type TypletSelection struct {
SchemaVersion int `json:"schemaVersion"`
Source string `json:"source"`
Datasets map[string][]string `json:"datasets"`
}
TypletSelection records the IDs retained from each larger Typlet corpus.
func LoadTypletSelection ¶
func LoadTypletSelection(filePath string) (*TypletSelection, error)
LoadTypletSelection decodes and validates the curated Typlet ID list.
type UTF16BoundaryError ¶
UTF16BoundaryError reports a UTF-16 offset that does not lie on a code-point boundary, typically the middle of a surrogate pair.
func (*UTF16BoundaryError) Error ¶
func (e *UTF16BoundaryError) Error() string
type UTF16Range ¶
UTF16Range is a half-open range in UTF-16 code units.
func (UTF16Range) MarshalJSON ¶
func (r UTF16Range) MarshalJSON() ([]byte, error)
MarshalJSON restores the compact [start, end] representation.
func (*UTF16Range) UnmarshalJSON ¶
func (r *UTF16Range) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes a compact [start, end] UTF-16 range.
func (UTF16Range) Validate ¶
func (r UTF16Range) Validate() error
Validate checks that the range is non-negative and ordered.