website/pkg/utility/dob_test.go
Noah de3d6e9315 User Profile and Settings Pages
* Vendor fontawesome icons
* User settings page: to edit profile details (other features not hooked
  up yet)
* Initial user profile page
2022-08-10 20:59:59 -07:00

75 lines
1.0 KiB
Go

package utility_test
import (
"testing"
"time"
"git.kirsle.net/apps/gosocial/pkg/utility"
)
func TestAge(t *testing.T) {
var now = time.Date(2022, 6, 15, 12, 0, 0, 0, time.UTC)
var tests = []struct {
In string
Expect int
}{
{
In: "1987-10-12",
Expect: 34,
},
{
In: "2022-06-15",
Expect: 0,
},
{
In: "1993-07-04",
Expect: 28,
},
{
In: "1996-06-17",
Expect: 26,
},
{
In: "1996-06-15",
Expect: 26,
},
{
In: "1996-06-14",
Expect: 25,
},
{
In: "2000-01-01",
Expect: 22,
},
{
In: "2000-05-30",
Expect: 22,
},
{
In: "2000-06-12",
Expect: 21,
},
{
In: "2000-06-14",
Expect: 21,
},
{
In: "2000-06-15",
Expect: 22,
},
{
In: "2000-06-16",
Expect: 22,
},
}
for _, test := range tests {
dob, _ := time.Parse("2006-01-02", test.In)
actual := utility.AgeAt(dob, now)
if actual != test.Expect {
t.Errorf("Expected %s to be age %d but got %d", test.In, test.Expect, actual)
}
}
}