FIND YOUR NEXT FEW LINES

The snippet library.

Small, practical examples. Search by task or narrow things down below.

10 snippets foundClear filters
GoTesting & reusable helpers

Check a function with table-driven cases

Check a function with table-driven cases using a complete Go program with explicit sample inputs.

Go✓ Tested
GoTesting & reusable helpers

Check whether bytes contain valid JSON

Check whether bytes contain valid JSON using a complete Go program with explicit sample inputs.

Go✓ Tested
GoTesting & reusable helpers

Clamp a value to an allowed interval

Clamp a value to an allowed interval using a complete Go program with explicit sample inputs.

Go✓ Tested
GoTesting & reusable helpers

Compare floats within a tolerance

Compare floats within a tolerance using a complete Go program with explicit sample inputs.

Go✓ Tested
GoTesting & reusable helpers

Compare two byte buffers

Compare two byte buffers using a complete Go program with explicit sample inputs.

Go✓ Tested
GoTesting & reusable helpers

Distinguish end-of-input from other errors

Distinguish end-of-input from other errors using a complete Go program with explicit sample inputs.

Go✓ Tested
GoTesting & reusable helpers

Limit the bytes read from a stream

Limit the bytes read from a stream using a complete Go program with explicit sample inputs.

Go✓ Tested
GoTesting & reusable helpers

Read a fixed-size stream prefix

Read a fixed-size stream prefix using a complete Go program with explicit sample inputs.

Go✓ Tested
GoTesting & reusable helpers

Scan whitespace-separated tokens

Scan whitespace-separated tokens using a complete Go program with explicit sample inputs.

Go✓ Tested
GoTesting & reusable helpers

Sort records by a selected field

Sort records by a selected field using a complete Go program with explicit sample inputs.

Go✓ Tested