Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor country-specific properties #1489

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

asolntsev
Copy link
Collaborator

@asolntsev asolntsev commented Jan 25, 2025

Move country-specific properties from lang.yml to _COUNTRY.yml files.

These are settings that depend on country, not language (e.g. postal code, building numbers, passport numbers, internet domains).

The primary test showing the difference is AddressTest.usingOnlyCountryCodeWithoutLanguage().

For example,

assertThat(new Faker(new Locale("et", "AL")).address().countryCode()).isEqualTo("AL");
  // was: EE
  // now: AL

And:

assertThat(new Faker(new Locale("et", "BY")).address().postcode()).matches("\\d{6}");
  // was: <5 digits> (Estonian postal code)
  // now: <6 digits> (Belorussian postal code)

In this PR, I had to introduce concept of "language's default country".
In the case when only the language is given, we need to detect the country:

assertThat(new Faker(new Locale("et")).address().countryCode()).isEqualTo("EE"); // for Estonian language, we use Estonia settings by default
assertThat(new Faker(new Locale("hy")).address().countryCode()).isEqualTo("AM"); // for Armenian language, we use Armenia settings by default

The list of "language's default countries" is located in FakerContext.LANGUAGE_DEFAULT_COUNTRY.

Apparently, it was occasionally commented out in commit f073184
these are settings that depend on country, not language (e.g. postal code, building numbers, passport numbers, internet domains).

The primary test showing the difference is `AddressTest.usingOnlyCountryCodeWithoutLanguage()`. E.g. `new Faker(new Locale("et", "AL")).address().countryCode()` should return "AL" (Albania), not "EE" (Estonia).
There is no such a locale. The proper locale is "de_DE" ("de" means German language, and "DE" means country Germany).
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.35%. Comparing base (ebac66a) to head (e0218e6).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1489      +/-   ##
============================================
- Coverage     92.45%   92.35%   -0.11%     
- Complexity     3255     3256       +1     
============================================
  Files           324      324              
  Lines          6387     6407      +20     
  Branches        623      623              
============================================
+ Hits           5905     5917      +12     
- Misses          336      339       +3     
- Partials        146      151       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants