Program StructureDoctests
Blorp by Example

Doctests

Doctests keep examples next to the API they describe.

Docstrings

A doc block uses --- before a declaration.

docstring.brp
---
Clamp a value.
---
pure func clamp(x: Int) -> Int:
    x

Named Doctests

Each doctest can include a readable name after ::.

doctest.brp
doctests:
    :: clamps low value
    clamp(2, 5, 10) == 5

Examples As Api Contracts

Doctests are examples that the test runner can execute.

contract.brp
doctests:
    :: keeps in-range value
    clamp(7, 5, 10) == 7

Example

clamp.brp
---
Clamp x into the inclusive [low, high] range.

doctests:
    :: below range
    clamp(2, 5, 10) == 5

    :: inside range
    clamp(7, 5, 10) == 7

    :: above range
    clamp(20, 5, 10) == 10
---
pure func clamp(x: Int, low: Int, high: Int) -> Int:
	if x < low:
		low
	else if x > high:
		high
	else:
		x

Try It

terminal
blorp check clamp.brp