Lines
100 %
Functions
Branches
//! Arithmetic edge cases beyond the basic `arithmetic_runtime` set:
//! constant folding of MOD, integer/ratio mix, division-by-zero
//! refusal, etc.
use super::common::{compile_and_validate, compile_expect_error, wrap_with_runtime_ratio};
#[test]
fn mod_constant_folds() {
compile_and_validate("(mod 10 3)");
}
fn mod_with_runtime_operand_errors() {
// MOD currently refuses runtime args at compile time. Locks in the
// "not yet supported" path so a future implementation either drops
// the refusal or this test flips to compile_and_validate.
let err = compile_expect_error(&wrap_with_runtime_ratio("(mod X 2)"));
assert!(err.contains("MOD") || err.contains("runtime"), "got: {err}",);
fn unary_negation_constant() {
compile_and_validate("(- 5)");
fn unary_negation_runtime() {
compile_and_validate(&wrap_with_runtime_ratio("(- X)"));
fn add_no_args_is_zero() {
compile_and_validate("(+)");
fn multiply_no_args_is_one() {
compile_and_validate("(*)");
fn single_arg_subtraction_is_negation() {
compile_and_validate("(- 7)");
fn nested_arithmetic_with_runtime() {
compile_and_validate(&wrap_with_runtime_ratio("(+ (* (- X 1) 2) (/ X 4))"));
fn division_by_zero_static_errors() {
let err = compile_expect_error("(/ 1 0)");
assert!(err.contains("zero") || err.contains("/"), "got: {err}");