From a05a726dc5febb1a688b16221b84a21edd4de5eb Mon Sep 17 00:00:00 2001 From: bejaratommy Date: Thu, 19 Mar 2026 12:47:09 +0100 Subject: [PATCH] test(math): add missing mod function tests and improve docs The mod function was missing test coverage in numeric_test.go, even though it was documented in docs/math.md. Add tests covering basic modulo, even divisors, and equality cases. Also expand the mod documentation to show a concrete example and clarify argument ordering, which is non-obvious in piped template syntax. Fixes #458 Signed-off-by: Tommy --- docs/math.md | 9 ++++++++- numeric_test.go | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/docs/math.md b/docs/math.md index b08d0a2f..0d19e1e0 100644 --- a/docs/math.md +++ b/docs/math.md @@ -24,7 +24,14 @@ Perform integer division with `div` ## mod -Modulo with `mod` +Perform modulo with `mod`. The result is the remainder of dividing the first +argument by the second. + +``` +mod 10 3 +``` + +The above will return `1`, because `10 % 3 = 1`. ## mul diff --git a/numeric_test.go b/numeric_test.go index 1252cd73..44915c7f 100644 --- a/numeric_test.go +++ b/numeric_test.go @@ -249,6 +249,28 @@ func TestDivf(t *testing.T) { } } +func TestMod(t *testing.T) { + tpl := `{{ mod 10 3 }}` + if err := runt(tpl, `1`); err != nil { + t.Error(err) + } + + tpl = `{{ mod 10 2 }}` + if err := runt(tpl, `0`); err != nil { + t.Error(err) + } + + tpl = `{{ mod 10 10 }}` + if err := runt(tpl, `0`); err != nil { + t.Error(err) + } + + tpl = `{{ mod 7 3 }}` + if err := runt(tpl, `1`); err != nil { + t.Error(err) + } +} + func TestMul(t *testing.T) { tpl := `{{ 1 | mul "2" 3 "4"}}` if err := runt(tpl, `24`); err != nil {