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

Merged
merged 5 commits into from
Jan 29, 2025

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

codecov-commenter commented Jan 25, 2025

⚠️ 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.44%. Comparing base (ebac66a) to head (a7a39c4).
Report is 4 commits behind head on main.

❗ 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.44%   -0.01%     
- Complexity     3255     3271      +16     
============================================
  Files           324      325       +1     
  Lines          6387     6437      +50     
  Branches        623      625       +2     
============================================
+ Hits           5905     5951      +46     
+ Misses          336      335       -1     
- Partials        146      151       +5     

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

README.md Show resolved Hide resolved
@asolntsev asolntsev requested a review from snuyanzin January 28, 2025 16:57
@asolntsev asolntsev added this to the 2.4.3 milestone Jan 29, 2025
@kingthorin kingthorin merged commit bfc93c4 into main Jan 29, 2025
10 checks passed
@kingthorin kingthorin deleted the refactor/country-specific-properties branch January 29, 2025 11:05
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.

4 participants