Files
iptvc/app/web/templates_test.go
T
2026-07-19 19:14:55 +08:00

81 lines
2.3 KiB
Go

package web
import (
"testing"
"time"
)
func TestGetNounForm(t *testing.T) {
cases := []struct {
n int
f1 string
f2 string
f5 string
want string
}{
{1, "минуту", "минуты", "минут", "минуту"},
{2, "минуту", "минуты", "минут", "минуты"},
{5, "минуту", "минуты", "минут", "минут"},
{11, "минуту", "минуты", "минут", "минут"},
{21, "минуту", "минуты", "минут", "минуту"},
{22, "минуту", "минуты", "минут", "минуты"},
{25, "минуту", "минуты", "минут", "минут"},
{101, "минуту", "минуты", "минут", "минуту"},
{111, "минуту", "минуты", "минут", "минут"},
{0, "минуту", "минуты", "минут", "минут"},
}
for _, c := range cases {
got := getNounForm(c.n, c.f1, c.f2, c.f5)
if got != c.want {
t.Errorf("getNounForm(%d) = %q, want %q", c.n, got, c.want)
}
}
}
func TestFormatTimeAgo_Zero(t *testing.T) {
if formatTimeAgo(0) != "неизвестно" {
t.Errorf("expected 'неизвестно' for ts=0")
}
}
func TestFormatTimeAgo_JustNow(t *testing.T) {
now := time.Now().Unix()
got := formatTimeAgo(now)
if got != "только что" {
t.Errorf("expected 'только что', got '%s'", got)
}
}
func TestFormatTimeAgo_Minutes(t *testing.T) {
ts := time.Now().Unix() - 120 // 2 minutes ago
got := formatTimeAgo(ts)
if got == "неизвестно" || got == "только что" {
t.Errorf("expected minutes format, got '%s'", got)
}
}
func TestFormatTimeAgo_Hours(t *testing.T) {
ts := time.Now().Unix() - 7200 // 2 hours ago
got := formatTimeAgo(ts)
if got == "неизвестно" || got == "только что" {
t.Errorf("expected hours format, got '%s'", got)
}
}
func TestFormatTimeAgo_Days(t *testing.T) {
ts := time.Now().Unix() - 172800 // 2 days ago
got := formatTimeAgo(ts)
if got == "неизвестно" || got == "только что" {
t.Errorf("expected days format, got '%s'", got)
}
}
func TestFormatTimeAgo_Future(t *testing.T) {
ts := time.Now().Unix() + 100
got := formatTimeAgo(ts)
// future → diff clamped to 0 → "только что"
if got != "только что" {
t.Errorf("expected 'только что' for future, got '%s'", got)
}
}