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 ¶
- func AssertEquals(t *testing.T, expected, actual any)
- func AssertFalse(t *testing.T, condition bool, msg string)
- func AssertNoError(t *testing.T, err error)
- func AssertTrue(t *testing.T, condition bool, msg string)
- func GeneratorContractTest(t *testing.T, gen qrcode.Generator)
- func QRCodeIsValid(t *testing.T, qr *encoding.QRCode)
- func RandomString(n int) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertEquals ¶
AssertEquals fails the test immediately if expected != actual using reflect.DeepEqual.
func AssertFalse ¶
AssertFalse fails the test immediately if condition is true, printing the provided message.
func AssertNoError ¶
AssertNoError fails the test immediately if err is non-nil, printing the error value.
func AssertTrue ¶
AssertTrue fails the test immediately if condition is false, printing the provided message.
func GeneratorContractTest ¶
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 ¶
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 ¶
RandomString generates a random alphanumeric string of length n using lowercase, uppercase, and digit characters.
Types ¶
This section is empty.