Skip to content

Commit

Permalink
fix: create separated test for nested ICU params
Browse files Browse the repository at this point in the history
  • Loading branch information
yuval-zamir committed Jun 19, 2024
1 parent bcb28af commit 64b09fd
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 3 deletions.
3 changes: 3 additions & 0 deletions tests/generateFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export const Entries: Record<string, Partial<Config>> = {
icu: {
singleCurlyBraces: true,
},
'icu-nested': {
singleCurlyBraces: true,
},
nested: {},
flat: {},
'exotic-keys': {},
Expand Down
29 changes: 29 additions & 0 deletions tests/generator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Driver } from './driver';
import * as InterpolationComplexLocaleKeys from './__generated__/pregenerated/interpolation-complex/LocaleKeys';
import * as ICULocaleKeys from './__generated__/pregenerated/icu/LocaleKeys';
import * as ICUNestedLocaleKeys from './__generated__/pregenerated/icu-nested/LocaleKeys';
import * as CustomFnNameLocaleKeys from './__generated__/pregenerated/fn-name/customFnName';
import * as ExoticKeysLocaleKeys from './__generated__/pregenerated/exotic-keys/LocaleKeys';
import * as FlatLocaleKeys from './__generated__/pregenerated/flat/LocaleKeys';
Expand Down Expand Up @@ -406,3 +407,31 @@ test('data interpolation icu', async () => {
);
expect(generatedResultsAsStr).toBe(generatedSnapShotAsStr);
});

test('data interpolation icu with nested params', async () => {
driver.given.namespace('icu-nested');
await driver.when.runsCodegenCommand({
singleCurlyBraces: true,
});

const [{ LocaleKeys }, generatedResultsAsStr, generatedSnapShotAsStr] =
await Promise.all([
driver.get.generatedResults<typeof ICUNestedLocaleKeys>(),
driver.get.generatedResultsAsStr(),
driver.get.generatedSnapShotAsStr(),
]);

const result = LocaleKeys(driver.get.defaultTranslationFn());
expect(
result.common.people.messageNestedParams({
numPersons: 2,
name: 'something',
})
).toBe(
driver.get.expectedTranslationOf('common.people.messageNestedParams', {
numPersons: 2,
name: 'something',
})
);
expect(generatedResultsAsStr).toBe(generatedSnapShotAsStr);
});
14 changes: 14 additions & 0 deletions tests/snapshot/icu-nested/LocaleKeys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* eslint-disable */
/* tslint:disable */
export function LocaleKeys<R extends string>(t: (...args: unknown[]) => R) {
return {
common: {
people: {
message: (data: Record<'numPersons', unknown>) => t('common.people.message', data), /* Hey, {numPersons, plural, =0 {no one} =1 {one person} other {# persons}} */
messageNestedParams: (data: Record<'name' | 'numPersons', unknown>) => t('common.people.messageNestedParams', data), /* Hey, {numPersons, plural, =0 {No one here.} one {{name}. You are the only person here.} other {{name} and # other persons are here.}} */
},
},
};
}

export type ILocaleKeys = ReturnType<typeof LocaleKeys>;
1 change: 0 additions & 1 deletion tests/snapshot/icu/LocaleKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export function LocaleKeys<R extends string>(t: (...args: unknown[]) => R) {
people: {
message: (data: Record<'numPersons', unknown>) => t('common.people.message', data), /* Hey, {numPersons, plural, =0 {no one} =1 {one person} other {# persons}} */
messageComplex: (data: Record<'name' | 'numPersons' | 'productsAmount', unknown>) => t('common.people.messageComplex', data), /* Hey {name}, There are {numPersons, plural, =0 {no one} =1 {one person} other {# persons}} that want to change the {productsAmount, plural, =1 {price of 1 product} other {prices of # products}} */
messageNestingParams: (data: Record<'name' | 'numPersons', unknown>) => t('common.people.messageNestingParams', data), /* Hey, {numPersons, plural, =0 {No one here.} one {{name}. You are the only person here.} other {{name} and # other persons are here.}} */
},
},
};
Expand Down
8 changes: 8 additions & 0 deletions tests/sources/icu-nested.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"common": {
"people": {
"message": "Hey, {numPersons, plural, =0 {no one} =1 {one person} other {# persons}}",
"messageNestedParams": "Hey, {numPersons, plural, =0 {No one here.} one {{name}. You are the only person here.} other {{name} and # other persons are here.}}"
}
}
}
3 changes: 1 addition & 2 deletions tests/sources/icu.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"common": {
"people": {
"message": "Hey, {numPersons, plural, =0 {no one} =1 {one person} other {# persons}}",
"messageComplex": "Hey {name}, There are {numPersons, plural, =0 {no one} =1 {one person} other {# persons}} that want to change the {productsAmount, plural, =1 {price of 1 product} other {prices of # products}}",
"messageNestingParams": "Hey, {numPersons, plural, =0 {No one here.} one {{name}. You are the only person here.} other {{name} and # other persons are here.}}"
"messageComplex": "Hey {name}, There are {numPersons, plural, =0 {no one} =1 {one person} other {# persons}} that want to change the {productsAmount, plural, =1 {price of 1 product} other {prices of # products}}"
}
}
}

0 comments on commit 64b09fd

Please sign in to comment.