Updated tests in utils

This commit is contained in:
adragusin
2019-12-18 15:15:21 +02:00
parent b53ee5f19f
commit b0f99c471a
3 changed files with 31 additions and 2 deletions

View File

@@ -547,9 +547,13 @@ func TestPhoneNumberConverter(t *testing.T) {
} else if !reflect.DeepEqual(nil, rcv) {
t.Errorf("Expecting: %+v, received: %+v", nil, rcv)
}
eLc := &PhoneNumberConverter{CountryCode: "9786679", Format: phonenumbers.NATIONAL}
if _, err := eLc.Convert("8976wedf"); err == nil || err.Error() != "invalid country code" {
t.Errorf("Expecting: 'invalid country code', received: %+v", err)
}
// US/National
eLc := &PhoneNumberConverter{CountryCode: "US", Format: phonenumbers.NATIONAL}
eLc = &PhoneNumberConverter{CountryCode: "US", Format: phonenumbers.NATIONAL}
d, err := NewDataConverter("*libphonenumber:US")
if err != nil {
t.Error(err)

View File

@@ -62,7 +62,7 @@ func (ys Years) Contains(year int) (result bool) {
// Parse Years elements from string separated by sep.
func (ys *Years) Parse(input, sep string) {
switch input {
case "*any", "":
case META_ANY, "":
*ys = []int{}
default:
elements := strings.Split(input, sep)

View File

@@ -68,6 +68,31 @@ func TestYearsLess(t *testing.T) {
}
}
func TestYearsContains(t *testing.T) {
ys := &Years{2019, 2010, 2020, 2005, 2018, 2007}
if rcv := ys.Contains(2019); !rcv {
t.Errorf("Expecting true received: %+v", rcv)
}
if rcv := ys.Contains(1989); rcv {
t.Errorf("Expecting false received: %+v", rcv)
}
}
func TestYearsParse(t *testing.T) {
ys := &Years{}
eOut := &Years{}
ys.Parse(META_ANY, EmptyString)
if !reflect.DeepEqual(eOut, ys) {
t.Errorf("Expecting %+v received: %+v", eOut, ys)
}
ys = &Years{2019, 2010, 2020, 2005, 2018, 2007}
eOut = &Years{2019, 2010, 2020, 2005, 2018, 2007, 2010, 2011, 2012, 2013}
ys.Parse("2010,2011,2012,2013", ",")
if !reflect.DeepEqual(eOut, ys) {
t.Errorf("Expecting %+v received: %+v", eOut, ys)
}
}
func TestDateseriesMonthStoreRestoreJson(t *testing.T) {
m := Months{5, 6, 7, 8}
r, _ := json.Marshal(m)