Esempio n. 1
0
func TestSetLang(t *testing.T) {
	err := fake.SetLang("ru")
	if err != nil {
		t.Error("SetLang should successfully set lang")
	}

	err = fake.SetLang("sd")
	if err == nil {
		t.Error("SetLang with nonexistent lang should return error")
	}
}
Esempio n. 2
0
func TestFakerRuWithCallback(t *testing.T) {
	fake.SetLang("ru")
	fake.EnFallback(true)
	brand := fake.Brand()
	if brand == "" {
		t.Error("Fake call for name with no samples with callback should not return blank string")
	}
}
Esempio n. 3
0
func TestFakerRuWithoutCallback(t *testing.T) {
	fake.SetLang("ru")
	fake.EnFallback(false)
	brand := fake.Brand()
	if brand != "" {
		t.Error("Fake call with no samples should return blank string")
	}
}
Esempio n. 4
0
func TestAddresses(t *testing.T) {
	for _, lang := range fake.GetLangs() {
		fake.SetLang(lang)

		v := fake.Continent()
		if v == "" {
			t.Errorf("Continent failed with lang %s", lang)
		}

		v = fake.Country()
		if v == "" {
			t.Errorf("Country failed with lang %s", lang)
		}

		v = fake.City()
		if v == "" {
			t.Errorf("City failed with lang %s", lang)
		}

		v = fake.State()
		if v == "" {
			t.Errorf("State failed with lang %s", lang)
		}

		v = fake.StateAbbrev()
		if v == "" && lang == "en" {
			t.Errorf("StateAbbrev failed with lang %s", lang)
		}

		v = fake.Street()
		if v == "" {
			t.Errorf("Street failed with lang %s", lang)
		}

		v = fake.StreetAddress()
		if v == "" {
			t.Errorf("StreetAddress failed with lang %s", lang)
		}

		v = fake.Zip()
		if v == "" {
			t.Errorf("Zip failed with lang %s", lang)
		}

		v = fake.Phone()
		if v == "" {
			t.Errorf("Phone failed with lang %s", lang)
		}
	}
}
Esempio n. 5
0
func TestDates(t *testing.T) {
	for _, lang := range fake.GetLangs() {
		fake.SetLang(lang)

		from, _ := time.Parse("2006-01-02T15:04:05", "2016-01-01T00:00:00")
		to, _ := time.Parse("2006-01-02T15:04:05", "2016-01-31T23:59:59")
		d := fake.Time(from, to)
		if !from.Equal(d) && !from.Before(d) {
			t.Errorf("Time before from date %s", lang)
		}
		if !to.Equal(d) && !to.After(d) {
			t.Errorf("Time after %s to date %s", d, lang)
		}

		v := fake.WeekDay()
		if v == "" {
			t.Errorf("WeekDay failed with lang %s", lang)
		}

		v = fake.WeekDayShort()
		if v == "" {
			t.Errorf("WeekDayShort failed with lang %s", lang)
		}

		n := fake.WeekdayNum()
		if n < 0 || n > 7 {
			t.Errorf("WeekdayNum failed with lang %s", lang)
		}

		v = fake.Month()
		if v == "" {
			t.Errorf("Month failed with lang %s", lang)
		}

		v = fake.MonthShort()
		if v == "" {
			t.Errorf("MonthShort failed with lang %s", lang)
		}

		n = fake.MonthNum()
		if n < 0 || n > 31 {
			t.Errorf("MonthNum failed with lang %s", lang)
		}

		n = fake.Year(1950, 2020)
		if n < 1950 || n > 2020 {
			t.Errorf("Year failed with lang %s", lang)
		}
	}
}
Esempio n. 6
0
func TestCurrencies(t *testing.T) {
	for _, lang := range fake.GetLangs() {
		fake.SetLang(lang)

		v := fake.Currency()
		if v == "" {
			t.Errorf("Currency failed with lang %s", lang)
		}

		v = fake.CurrencyCode()
		if v == "" {
			t.Errorf("CurrencyCode failed with lang %s", lang)
		}
	}
}
Esempio n. 7
0
func TestCreditCards(t *testing.T) {
	for _, lang := range fake.GetLangs() {
		fake.SetLang(lang)

		v := fake.CreditCardType()
		if v == "" {
			t.Errorf("CreditCardType failed with lang %s", lang)
		}

		v = fake.CreditCardNum("")
		if v == "" {
			t.Errorf("CreditCardNum failed with lang %s", lang)
		}

		v = fake.CreditCardNum("visa")
		if v == "" {
			t.Errorf("CreditCardNum failed with lang %s", lang)
		}
	}
}