ruchy 4.2.1

A systems scripting language that transpiles to idiomatic Rust with extreme quality engineering
Documentation
// 16_testing.ruchy - Writing tests in Ruchy using @test decorator

// Module with functions to test
mod calculator {
    pub fun add(a, b) {
        a + b
    }

    pub fun subtract(a, b) {
        a - b
    }

    pub fun multiply(a, b) {
        a * b
    }
}

// Tests using @test decorator
@test("addition works correctly")
fun test_addition() {
    assert(calculator::add(2, 3) == 5)
    assert(calculator::add(-1, 1) == 0)
    assert(calculator::add(0, 0) == 0)
}

@test("subtraction works correctly")
fun test_subtraction() {
    assert(calculator::subtract(5, 3) == 2)
    assert(calculator::subtract(0, 5) == -5)
    assert(calculator::subtract(10, 10) == 0)
}

@test("multiplication works correctly")
fun test_multiplication() {
    assert(calculator::multiply(3, 4) == 12)
    assert(calculator::multiply(0, 100) == 0)
    assert(calculator::multiply(-2, 5) == -10)
}

fun main() {
    println("Testing Framework Demo")
    println("Use 'ruchy test' to run @test decorated functions")

    // Direct test of calculator
    println(f"2 + 3 = {calculator::add(2, 3)}")
    println(f"5 - 3 = {calculator::subtract(5, 3)}")
    println(f"3 * 4 = {calculator::multiply(3, 4)}")
}