Skip to content

Commit

Permalink
Add countryCode (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirobertod committed Dec 22, 2022
1 parent d9e5b3b commit 062deca
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
33 changes: 33 additions & 0 deletions address.go
Expand Up @@ -78,6 +78,34 @@ var (
"VCT", "VEN", "VGB", "VIR", "VNM", "VUT", "WLF", "WSM", "YEM", "ZAF", "ZMB", "ZWE",
}

countryCode = []string{
"AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ",
"BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ",
"CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ",
"DE", "DJ", "DK", "DM", "DO", "DZ",
"EC", "EE", "EG", "EH", "ER", "ES", "ET",
"FI", "FJ", "FK", "FM", "FO", "FR",
"GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY",
"HK", "HM", "HN", "HR", "HT", "HU",
"ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT",
"JE", "JM", "JO", "JP",
"KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ",
"LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY",
"MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ",
"NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ",
"OM",
"PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY",
"QA",
"RE", "RO", "RS", "RU", "RW",
"SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ",
"TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ",
"UA", "UG", "UM", "US", "UY", "UZ",
"VA", "VC", "VE", "VG", "VI", "VN", "VU",
"WF", "WS",
"YE", "YT",
"ZA", "ZM", "ZW",
}

cityFormats = []string{
"{{cityPrefix}} {{firstName}}{{citySuffix}}",
"{{cityPrefix}} {{firstName}}",
Expand Down Expand Up @@ -232,6 +260,11 @@ func (a Address) CountryAbbr() string {
return a.Faker.RandomStringElement(countryAbbr)
}

// CountryCode returns a fake country code for Address
func (a Address) CountryCode() string {
return a.Faker.RandomStringElement(countryCode)
}

// Latitude returns a fake latitude for Address
func (a Address) Latitude() (latitude float64) {
latitude, _ = strconv.ParseFloat(a.Faker.Numerify("##.######"), 64)
Expand Down
5 changes: 5 additions & 0 deletions address_test.go
Expand Up @@ -104,6 +104,11 @@ func TestCountryAbbr(t *testing.T) {
Expect(t, true, len(a.CountryAbbr()) > 0)
}

func TestCountryCode(t *testing.T) {
a := New().Address()
Expect(t, true, len(a.CountryCode()) > 0)
}

func TestLatitude(t *testing.T) {
a := New().Address()
Expect(t, true, a.Latitude() > 0)
Expand Down

0 comments on commit 062deca

Please sign in to comment.