testing

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package testing provides contract tests and test utilities for the QR code library.

The GeneratorContractTest function validates that any qrcode.Generator implementation satisfies the core contract (Generate, GenerateWithOptions, GenerateToWriter, Close). Assertion helpers like AssertNoError, AssertEquals, AssertTrue, and AssertFalse simplify test expectations.

func TestMyGenerator(t *testing.T) {
    gen := my.NewGenerator()
    testing.GeneratorContractTest(t, gen)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertEquals

func AssertEquals(t *testing.T, expected, actual any)

AssertEquals fails the test immediately if expected != actual using reflect.DeepEqual.

func AssertFalse

func AssertFalse(t *testing.T, condition bool, msg string)

AssertFalse fails the test immediately if condition is true, printing the provided message.

func AssertNoError

func AssertNoError(t *testing.T, err error)

AssertNoError fails the test immediately if err is non-nil, printing the error value.

func AssertTrue

func AssertTrue(t *testing.T, condition bool, msg string)

AssertTrue fails the test immediately if condition is false, printing the provided message.

func GeneratorContractTest

func GeneratorContractTest(t *testing.T, gen qrcode.Generator)

GeneratorContractTest runs a suite of contract tests on a QR code Generator.

It validates TextPayload and WiFiPayload generation, error handling for invalid payloads, options passthrough (error correction level), writer output, and proper Close lifecycle behavior.

func QRCodeIsValid

func QRCodeIsValid(t *testing.T, qr *encoding.QRCode)

QRCodeIsValid checks that the QR code matrix is well-formed, verifying that Version (1–40), Size (≥ 21), ECLevel (0–3), MaskPattern (0–7), and the Modules matrix dimensions are all valid.

func RandomString

func RandomString(n int) string

RandomString generates a random alphanumeric string of length n using lowercase, uppercase, and digit characters.

Types

This section is empty.

Jump to

Keyboard shortcuts

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