example/_helpers.primi

Summary

Maintainability
Test Coverage
function assert_not(truth, *args) {
    // Assert that the first argument is false.
    // Using *args workaround to make second argument (desc) optional,
    // because Primi doesn't currently support having argument defaults.
    desc = args[0] if (args) else ''
    assert(!truth, desc)
}

function assert_error(fn, *args) {
    // Assert that the call to passed function resulted in an error.
    // Using *args workaround to make second argument (desc) optional.
    desc  = args[0] if (args) else ''

    was_error = true
    try {
        fn()
        was_error = false
    } catch {
        // Pass.
    }

    assert(was_error, desc)
}