Skip to content

Commit

Permalink
test(compiler): add additional i18n serialization tests (angular#38484)
Browse files Browse the repository at this point in the history
The addiational tests check that ICUs containing interpolations
are serialized correctly.

PR Close angular#38484
  • Loading branch information
petebacondarwin authored and atscott committed Aug 17, 2020
1 parent cb05c01 commit be96510
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions packages/compiler/test/render3/view/i18n_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ describe('serializeI18nMessageForLocalize', () => {
});


it('should serialize ICU with nested HTML for `$localize()`', () => {
it('should serialize ICU with embedded HTML for `$localize()`', () => {
expect(serialize('{age, plural, 10 {<b>ten</b>} other {<div class="A">other</div>}}')).toEqual({
messageParts: [
'{VAR_PLURAL, plural, 10 {{START_BOLD_TEXT}ten{CLOSE_BOLD_TEXT}} other {{START_TAG_DIV}other{CLOSE_TAG_DIV}}}'
Expand All @@ -424,6 +424,15 @@ describe('serializeI18nMessageForLocalize', () => {
});
});

it('should serialize ICU with embedded interpolation for `$localize()`', () => {
expect(serialize('{age, plural, 10 {<b>ten</b>} other {{{age}} years old}}')).toEqual({
messageParts: [
'{VAR_PLURAL, plural, 10 {{START_BOLD_TEXT}ten{CLOSE_BOLD_TEXT}} other {{INTERPOLATION} years old}}'
],
placeHolders: []
});
});

it('should serialize ICU with nested HTML containing further ICUs for `$localize()`', () => {
expect(
serialize(
Expand All @@ -433,6 +442,18 @@ describe('serializeI18nMessageForLocalize', () => {
placeHolders: ['ICU', 'START_TAG_DIV', 'ICU', 'CLOSE_TAG_DIV']
});
});

it('should serialize nested ICUs with embedded interpolation for `$localize()`', () => {
expect(
serialize(
'{age, plural, 10 {ten {size, select, 1 {{{ varOne }}} 2 {{{ varTwo }}} other {2+}}} other {other}}'))
.toEqual({
messageParts: [
'{VAR_PLURAL, plural, 10 {ten {VAR_SELECT, select, 1 {{INTERPOLATION}} 2 {{INTERPOLATION_1}} other {2+}}} other {other}}'
],
placeHolders: []
});
});
});

describe('serializeIcuNode', () => {
Expand All @@ -447,7 +468,7 @@ describe('serializeIcuNode', () => {
.toEqual('{VAR_PLURAL, plural, 10 {ten} other {other}}');
});

it('should serialize a next ICU', () => {
it('should serialize a nested ICU', () => {
expect(serialize(
'{age, plural, 10 {ten {size, select, 1 {one} 2 {two} other {2+}}} other {other}}'))
.toEqual(
Expand All @@ -459,4 +480,9 @@ describe('serializeIcuNode', () => {
.toEqual(
'{VAR_PLURAL, plural, 10 {{START_BOLD_TEXT}ten{CLOSE_BOLD_TEXT}} other {{START_TAG_DIV}other{CLOSE_TAG_DIV}}}');
});

it('should serialize an ICU with embedded interpolations', () => {
expect(serialize('{age, select, 10 {ten} other {{{age}} years old}}'))
.toEqual('{VAR_SELECT, select, 10 {ten} other {{INTERPOLATION} years old}}');
});
});

0 comments on commit be96510

Please sign in to comment.