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

test(locale): check for duplicated entries #1137

Merged
merged 29 commits into from
Oct 8, 2022

Conversation

xDivisionByZerox
Copy link
Member

@xDivisionByZerox xDivisionByZerox commented Jul 8, 2022

This PR will introduce a test that checks every LocaleDefinition for duplicated entries.

The most important file that needs review is test/locales.spec.ts. Everything else are just changes that are required by this test case.

@xDivisionByZerox xDivisionByZerox added c: feature Request for new feature c: test labels Jul 8, 2022
@xDivisionByZerox xDivisionByZerox added this to the v7 - Current Major milestone Jul 8, 2022
@xDivisionByZerox xDivisionByZerox self-assigned this Jul 8, 2022
@xDivisionByZerox
Copy link
Member Author

I expect the test pipeline to fail for demonstration purposes.

@ST-DDT would you have a look at the implementation and the error log in general? I trust in you and your abilities on such things.

@ST-DDT
Copy link
Member

ST-DDT commented Jul 9, 2022

The implementation looks good, maybe you could use this expectation:

expect(
  uniqueDuplication,
  `Found duplicate entries: [${uniqueDuplication
    .sort()
    .join(', ')}]`
).toBe([]);
// The sort should probably be outside of the string template

The toBe check focuses more on the content of the array than the length.

grafik

What do you think?

(PS: We have to check if there are/should be exceptions to this rule)

test/locales.spec.ts Outdated Show resolved Hide resolved
@xDivisionByZerox xDivisionByZerox changed the title test(locales): check for duplicated entries WIP: test(locales): check for duplicated entries Jul 9, 2022
@xDivisionByZerox xDivisionByZerox requested a review from a team July 9, 2022 12:55
@xDivisionByZerox
Copy link
Member Author

So I need to change about 1,4k locale files since they contain duplicates. Is it reasonable to fix all of this in one (THIS) PR? My current workflow is:

  1. sort all entries in a locale files
  2. commit with message 'chore(locales): *localeName* *fileName* sort alphabetically'
  3. remove duplicated entries
  4. commit with message 'chore(locales): *localeName* *fileName* remove duplicates'

My question: Should I provide an additional PR where I sort ALL locale files alphabetically first. This could be much clearer for the git history.

I use the Tyriar.sort-lines VS Code extension to sort locale file entries.

@Shinigami92
Copy link
Member

Shinigami92 commented Jul 9, 2022

@xDivisionByZerox yes, for me that sounds more safe

  1. PR for sort
  2. PR for dedup

That way we have a better commit history in main branch

@Shinigami92 Shinigami92 changed the title WIP: test(locales): check for duplicated entries WIP: test(locale): check for duplicated entries Aug 12, 2022
@xDivisionByZerox xDivisionByZerox added s: accepted Accepted feature / Confirmed bug c: refactor PR that affects the runtime behavior, but doesn't add new features or fixes bugs c: locale Permutes locale definitions labels Sep 25, 2022
@codecov
Copy link

codecov bot commented Sep 25, 2022

Codecov Report

Merging #1137 (f999ba9) into main (f0b60b9) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

❗ Current head f999ba9 differs from pull request most recent head e418402. Consider uploading reports for the commit e418402 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1137      +/-   ##
==========================================
- Coverage   99.63%   99.61%   -0.02%     
==========================================
  Files        2165     2165              
  Lines      241432   237194    -4238     
  Branches     1021     1017       -4     
==========================================
- Hits       240549   236287    -4262     
- Misses        862      886      +24     
  Partials       21       21              
Impacted Files Coverage Δ
src/locales/af_ZA/name/female_first_name.ts 100.00% <ø> (ø)
src/locales/af_ZA/name/first_name.ts 100.00% <ø> (ø)
src/locales/af_ZA/name/last_name.ts 100.00% <ø> (ø)
src/locales/af_ZA/name/male_first_name.ts 100.00% <ø> (ø)
src/locales/ar/address/city_name.ts 100.00% <ø> (ø)
src/locales/ar/commerce/department.ts 100.00% <ø> (ø)
src/locales/ar/name/female_first_name.ts 100.00% <ø> (ø)
src/locales/ar/name/last_name.ts 100.00% <ø> (ø)
src/locales/ar/phone_number/formats.ts 100.00% <ø> (ø)
src/locales/ar/team/creature.ts 100.00% <ø> (ø)
... and 213 more

Copy link
Member

@ST-DDT ST-DDT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check itself looks good, but duplicated. You might want to want to move the "describe if array ..." block into a helper method allowing recursive calls to it.
I could provide a patch/diff, if my explanation isn't easy to understand.

test/locales.spec.ts Outdated Show resolved Hide resolved
@ST-DDT
Copy link
Member

ST-DDT commented Sep 25, 2022

It looks like this PR doesn't really reduce the line count: +10,463 -4,859
(not that it is important)

@Shinigami92
Copy link
Member

It looks like this PR doesn't really reduce the line count: +10,463 -4,859 (not that it is important)

Yeah, you are right
Somehow some files are generated with fully new content 🤔
Example:
image

@xDivisionByZerox
Copy link
Member Author

Somehow some files are generated with fully new content 🤔

Oh damn. Good catch. I will revert those files. I guess they slipped through as I played with the generate-locales script.

@xDivisionByZerox
Copy link
Member Author

Those "additions" should be reverted now. They happened due to those files being implemented in a dynamic/logical way, not with a static data set.

@ST-DDT
Copy link
Member

ST-DDT commented Sep 26, 2022

@xDivisionByZerox I found a way to simplify the test a bit, feel free to merge: diff

ST-DDT
ST-DDT previously approved these changes Sep 29, 2022
@ST-DDT
Copy link
Member

ST-DDT commented Sep 29, 2022

@xDivisionByZerox Did you see my comment here: #1137 (comment)

@ST-DDT ST-DDT enabled auto-merge (squash) October 8, 2022 10:47
@ST-DDT ST-DDT merged commit 5dc8f0e into main Oct 8, 2022
@Shinigami92 Shinigami92 deleted the test/locales/duplicated-entries branch October 8, 2022 14:02
wael-fadlallah pushed a commit to wael-fadlallah/faker that referenced this pull request Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: feature Request for new feature c: locale Permutes locale definitions c: refactor PR that affects the runtime behavior, but doesn't add new features or fixes bugs c: test p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants