Programs

std.testing

Bool-returning helpers for test blocks and output checks.

When To Use std.testing

In Zerolang, use std.testing inside test blocks for output checks and small boolean assertion helpers.

Runnable today:

APIReturnNotes
std.testing.isTrue(value)BoolPasses through a Bool for readable expect statements.
std.testing.isFalse(value)BoolReturns true when the value is false.
std.testing.equalBool(actual, expected)BoolCompares booleans explicitly.
std.testing.equalUsize(actual, expected)BoolCompares usize values explicitly.
std.testing.equalU32(actual, expected)BoolCompares u32 values explicitly.
std.testing.equalI32(actual, expected)BoolCompares i32 values explicitly.
std.testing.equalBytes(actual, expected)BoolCompares byte spans by value.
std.testing.containsBytes(actual, needle)BoolChecks whether a byte span contains a byte substring.
std.testing.startsWith(actual, prefix)BoolChecks a byte prefix.
std.testing.endsWith(actual, suffix)BoolChecks a byte suffix.
std.testing.notEqualBytes(actual, expected)BoolChecks byte-span inequality.
std.testing.diffIndexBytes(actual, expected)Maybe<usize>Returns the first differing byte index, or null when spans are equal.
std.testing.jsonFieldEquals(actual, key, expected)BoolCompares a raw top-level JSON field value.
std.testing.jsonPathEquals(actual, path, expected)BoolCompares a raw dotted JSON path value.
std.testing.caseName(buffer, suite, index)Maybe<Span<u8>>Writes a stable table-case name like suite[3] into caller storage.

Metadata labels:

  • effects: none for scalar comparisons; memory for byte-span/case-name checks; parse for JSON checks
  • allocation behavior: no allocation
  • target support: target-neutral
  • error behavior: infallible
  • ownership notes: no ownership transfer
  • example: examples/std-testing-log.graph

Example

test "testing helpers support direct test blocks" {    let diff: Maybe<usize> = std.testing.diffIndexBytes("zero", "zeta")    expect std.testing.equalU32(42_u32, 42_u32)    expect std.testing.equalBytes("zero", "zero")    expect std.testing.containsBytes("zerolang", "lang")    expect diff.has && diff.value == 2    expect std.testing.jsonPathEquals("{\"user\":{\"name\":\"zero\"}}", "user.name", "\"zero\"")}

Design Notes

std.testing helpers return Bool; they do not register tests, hide failures, allocate output, or produce process I/O. Use them inside ordinary expect statements so the compiler and zero test keep one visible test model.

The byte helpers are byte-span predicates. They are suitable for output checks, protocol fixtures, and small examples where a full parser would be more complex than the assertion.

JSON helpers compare raw JSON values, so string expectations include their JSON quotes, such as "\"zero\"".