From b8353749741033f5791d6401d702af1177e9a618 Mon Sep 17 00:00:00 2001 From: Charlie Tonneslan Date: Sat, 16 May 2026 19:16:31 -0400 Subject: [PATCH] add a test for the mod helper mod has been documented since the math docs were written but never covered by tests, so a regression would have slipped through. Drop in a TestMod that exercises a couple of representative inputs to match the surrounding TestDiv/TestMul style and pin down the operand order (the piped value is the right-hand operand). Closes #458. Signed-off-by: Charlie Tonneslan --- numeric_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/numeric_test.go b/numeric_test.go index 1252cd73..93f29933 100644 --- a/numeric_test.go +++ b/numeric_test.go @@ -249,6 +249,25 @@ func TestDivf(t *testing.T) { } } +func TestMod(t *testing.T) { + // {{ y | mod x }} computes x % y, matching the convention used by + // the other arithmetic helpers (the piped value is the right-hand + // operand). #458 noted that mod was documented but not covered. + tests := []struct { + tpl string + want string + }{ + {`{{ 3 | mod 10 }}`, `1`}, + {`{{ 5 | mod 20 }}`, `0`}, + {`{{ 4 | mod 7 }}`, `3`}, + } + for _, tc := range tests { + if err := runt(tc.tpl, tc.want); err != nil { + t.Errorf("%s: %v", tc.tpl, err) + } + } +} + func TestMul(t *testing.T) { tpl := `{{ 1 | mul "2" 3 "4"}}` if err := runt(tpl, `24`); err != nil {