lezertest

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT, MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package lezertest checks a port against what the real Lezer gives: the goldens internal/lezer/gen/golden.mjs writes, one per fixture.

Index

Constants

View Source
const CorpusEnv = "LEZER_INCREMENTAL_CORPUS"

CorpusEnv names the directory of a randomized edit corpus written by gen/incremental.mjs, too big for the repository: one subdirectory of sessions and goldens per grammar. MatchCorpus skips when it is unset.

Variables

This section is empty.

Functions

func Apply

func Apply(units []uint16, edits []Edit) ([]uint16, []lezer.ChangedRange)

Apply makes the edits, in order and not overlapping, to units, and returns the result with the ChangedRanges they are.

func CompareLines

func CompareLines(t *testing.T, got, want []string)

CompareLines fails at the first line where got and want differ, then on a difference in their length.

func Describe

func Describe(tree *lezer.Tree, text []uint16) []string

Describe is what golden.mjs writes for tree, parsed from text: the tree, then its spans.

func MatchCorpus

func MatchCorpus(t *testing.T, p *lezer.Parser, grammar string)

MatchCorpus is MatchIncremental over the subdirectory grammar of the corpus CorpusEnv names, reporting how many sessions and parses it checked and at how many steps Lezer's incremental parse highlights otherwise than a fresh one.

func MatchGoldens

func MatchGoldens(t *testing.T, p *lezer.Parser, dir string)

MatchGoldens parses and highlights every fixture in dir that has a .golden next to it, each in its own subtest, and fails at the first line that differs from it. A dir with no goldens fails: it is a mistyped path, not a pass.

func MatchIncremental

func MatchIncremental(t *testing.T, p *lezer.Parser, dir string)

MatchIncremental runs every session in dir that has a .golden next to it, each in its own subtest, and fails at the first parse whose tree, layout or spans, or the spans of a fresh parse of the same text, differ from what the real Lezer gave. A dir with no goldens fails.

Types

type Edit

type Edit struct {
	From   int    `json:"from"`
	To     int    `json:"to"`
	Insert string `json:"insert"`
}

Edit replaces [From, To) with Insert.

type Session

type Session struct {
	Text  string   `json:"text"`
	Steps [][]Edit `json:"steps"`
}

Session is an edit session as gen/incremental.mjs reads it: a document and the steps of edits made to it, positions in UTF-16 code units into the document as it was before the step.

Jump to

Keyboard shortcuts

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