Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions numeric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down