Use table specs in getDate tests

This commit is contained in:
Deluan 2023-05-19 17:03:14 -04:00
parent 20462c52a5
commit 8faaa3cf91
1 changed files with 18 additions and 46 deletions

View File

@ -6,53 +6,25 @@ import (
)
var _ = Describe("Tags", func() {
Describe("getDate", func() {
It("parses the year correctly", func() {
var examplesYear = map[string]int{
"1985": 1985,
"2002-01": 2002,
"1969.06": 1969,
"1980.07.25": 1980,
"2004-00-00": 2004,
"2016-12-31": 2016,
"2013-May-12": 2013,
"May 12, 2016": 2016,
"01/10/1990": 1990,
}
for tag, expected := range examplesYear {
md := &Tags{}
md.tags = map[string][]string{"date": {tag}}
testYear, _ := md.Date()
Expect(testYear).To(Equal(expected))
}
})
It("parses the date correctly", func() {
var examplesDate = map[string]string{
"1985": "1985",
"2002-01": "2002-01",
"1969.06": "1969",
"1980.07.25": "1980",
"2004-00-00": "2004",
"2016-12-31": "2016-12-31",
"2013-May-12": "2013",
"May 12, 2016": "2016",
"01/10/1990": "1990",
}
for tag, expected := range examplesDate {
md := &Tags{}
md.tags = map[string][]string{"date": {tag}}
_, testDate := md.Date()
Expect(testDate).To(Equal(expected))
}
})
It("returns 0 if year is invalid", func() {
DescribeTable("getDate",
func(tag string, expectedYear int, expectedDate string) {
md := &Tags{}
md.tags = map[string][]string{"date": {"invalid"}}
testYear, _ := md.Date()
Expect(testYear).To(Equal(0))
})
})
md.tags = map[string][]string{"date": {tag}}
testYear, testDate := md.Date()
Expect(testYear).To(Equal(expectedYear))
Expect(testDate).To(Equal(expectedDate))
},
Entry(nil, "1985", 1985, "1985"),
Entry(nil, "2002-01", 2002, "2002-01"),
Entry(nil, "1969.06", 1969, "1969"),
Entry(nil, "1980.07.25", 1980, "1980"),
Entry(nil, "2004-00-00", 2004, "2004"),
Entry(nil, "2016-12-31", 2016, "2016-12-31"),
Entry(nil, "2013-May-12", 2013, "2013"),
Entry(nil, "May 12, 2016", 2016, "2016"),
Entry(nil, "01/10/1990", 1990, "1990"),
Entry(nil, "invalid", 0, ""),
)
Describe("getMbzID", func() {
It("return a valid MBID", func() {