package util import ( "testing" "github.com/stretchr/testify/assert" ) // TC-0234: page=2, pageSize=10 func TestNormalizePage(t *testing.T) { tests := []struct { name string page, pageSize int64 wantP, wantSize int64 }{ {"normal values", 2, 10, 2, 10}, {"page=0", 0, 10, 1, 10}, {"page=-1", -1, 10, 1, 10}, {"pageSize=0", 1, 0, 1, 20}, {"pageSize=-5", 1, -5, 1, 20}, {"pageSize>100", 1, 500, 1, 100}, {"pageSize=100 boundary", 1, 100, 1, 100}, {"pageSize=101 boundary", 1, 101, 1, 100}, {"both zero", 0, 0, 1, 20}, {"both negative", -3, -10, 1, 20}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p, s := NormalizePage(tt.page, tt.pageSize) assert.Equal(t, tt.wantP, p) assert.Equal(t, tt.wantSize, s) }) } } // TC-0242: `user@example.com` func TestIsValidEmail(t *testing.T) { tests := []struct { name string email string want bool }{ {"standard email", "user@example.com", true}, {"with dots", "user.name@example.com", true}, {"with plus", "user+tag@example.com", true}, {"with hyphen domain", "user@my-domain.com", true}, {"missing @", "userexample.com", false}, {"missing domain", "user@", false}, {"missing TLD", "user@example", false}, {"empty string", "", false}, {"double @", "user@@example.com", false}, {"space in email", "user @example.com", false}, {"short TLD", "user@example.c", false}, {"subdomain", "user@sub.example.com", true}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { assert.Equal(t, tt.want, IsValidEmail(tt.email)) }) } } // TC-0249: `13800138000` func TestIsValidPhone(t *testing.T) { tests := []struct { name string phone string want bool }{ {"chinese mobile", "13800138000", true}, {"with country code", "+8613800138000", true}, {"too short 6 digits", "123456", false}, {"min 7 digits", "1234567", true}, {"max 15 digits", "+123456789012345", true}, {"over 16 digits", "1234567890123456", false}, {"contains letters", "1380013abc", false}, {"empty string", "", false}, {"only plus", "+", false}, {"plus with short", "+123456", false}, {"leading zero not first", "01234567890", false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { assert.Equal(t, tt.want, IsValidPhone(tt.phone)) }) } }