Add assert to stdlib #24

Open
opened 2026-06-03 10:28:17 -04:00 by noClaps · 1 comment
Owner

Definition:

fn assert(bool check, str[] args...) -> ! {
    if check {
        true -> {}
        false -> { panic("Assertion failed: {args}") }
    }
}

Usage:

import { "std/assert" as assert }

test "passing test" {
    try assert.assert(2 + 2 == 4, "This test should pass")
}
test "failing test" {
    try assert.assert(2 + 2 == 5, "This test should fail")
}
Definition: ```nc fn assert(bool check, str[] args...) -> ! { if check { true -> {} false -> { panic("Assertion failed: {args}") } } } ``` Usage: ```nc import { "std/assert" as assert } test "passing test" { try assert.assert(2 + 2 == 4, "This test should pass") } test "failing test" { try assert.assert(2 + 2 == 5, "This test should fail") } ```
Author
Owner

Also replace all instances of assert(...) in the docs with try assert.assert(...)

Also replace all instances of `assert(...)` in the docs with `try assert.assert(...)`
Sign in to join this conversation.
No labels
stdlib
syntax
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
nclang/design#24
No description provided.