assert

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package assert provides assertion helpers for comparing SVG outputs against SVGO test fixture expectations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeCanonical

func NormalizeCanonical(s string) string

NormalizeCanonical applies the full L2 normalization pipeline:

  1. Unify line endings (LF)
  2. Remove trailing whitespace per line
  3. Remove excess blank lines (max 1 consecutive blank line)
  4. Trim leading/trailing whitespace

Note: Attribute sorting and numeric normalization are deferred to when we have the XAST parser available (Phase 2+). For now, L2 provides text-level normalization only.

func NormalizeLF

func NormalizeLF(s string) string

NormalizeLF converts all line endings to LF and trims the string. This matches SVGO's normalize: file.trim().replaceAll(EOL, '\n')

Types

type L1Result

type L1Result struct {
	Pass bool
	Diff string // human-readable diff description, empty if pass
}

L1Result holds the result of an L1 strict comparison.

func L1StrictEqual

func L1StrictEqual(got, expected string) L1Result

L1StrictEqual performs L1 (strict snapshot) comparison.

It normalizes both strings (trim + LF) and then compares them byte-for-byte. This matches SVGO's test assertion: expect(normalize(result.data)).toStrictEqual(should)

type L2Result

type L2Result struct {
	Pass bool
	Diff string // human-readable diff description, empty if pass
}

L2Result holds the result of an L2 canonical comparison.

func L2CanonicalEqual

func L2CanonicalEqual(got, expected string) L2Result

L2CanonicalEqual performs L2 (canonical equivalence) comparison.

It applies the full normalization pipeline to both strings and compares. This is more lenient than L1: it tolerates trailing whitespace differences, extra blank lines, etc.

Note: Full L2 normalization (attribute sorting, numeric normalization) will be enhanced once the XAST parser is available. Currently provides text-level normalization.

Jump to

Keyboard shortcuts

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