From 9f662e1313b72108ad4bfa390fcd54bfe129fb2b Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Fri, 18 Dec 2020 09:41:05 +0000 Subject: [PATCH] test(compiler-cli): tidy up the line-ending compliance test TEST_CASES (#40237) Previously the names of the source and expectation files were often reused, which caused potential confusion. There is now a single source file for each test-case, which is important when they are being compiled with different compiler options, since the GOLDEN_PARTIAL file will only contain one copy per file name. The names of the expectation files have now been changed so that is clearer which test-case they are related to. PR Close #40237 --- .../GOLDEN_PARTIAL.js | 36 ++++++------ .../line_ending_normalization/TEST_CASES.json | 58 ++++++++----------- ...external_template_legacy_non_normalized.js | 8 +++ ...xternal_template_legacy_non_normalized.ts} | 0 .../external_template_legacy_normalized.js | 8 +++ .../external_template_non_legacy.js | 7 +++ ...nal_template_non_legacy_non_normalized.ts} | 0 ...external_template_non_legacy_normalized.ts | 15 +++++ ...ormalized.js => inline_template_legacy.js} | 0 ... inline_template_legacy_non_normalized.ts} | 0 ...s => inline_template_legacy_normalized.ts} | 0 ...egacy.js => inline_template_non_legacy.js} | 0 ...line_template_non_legacy_non_normalized.ts | 25 ++++++++ .../inline_template_non_legacy_normalized.ts | 25 ++++++++ .../legacy_nonnormalized.js | 10 ---- .../line_ending_normalization/template.html | 21 ++++--- .../compliance/test_helpers/compile_test.ts | 10 +++- .../test_helpers/sourcemap_helpers.ts | 4 +- 18 files changed, 151 insertions(+), 76 deletions(-) create mode 100644 packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/external_template_legacy_non_normalized.js rename packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/{external_template_legacy.ts => external_template_legacy_non_normalized.ts} (100%) create mode 100644 packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/external_template_legacy_normalized.js create mode 100644 packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/external_template_non_legacy.js rename packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/{external_template_non_legacy.ts => external_template_non_legacy_non_normalized.ts} (100%) create mode 100644 packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/external_template_non_legacy_normalized.ts rename packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/{legacy_normalized.js => inline_template_legacy.js} (100%) rename packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/{inline_template_legacy.ts => inline_template_legacy_non_normalized.ts} (100%) rename packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/{inline_template_non_legacy.ts => inline_template_legacy_normalized.ts} (100%) rename packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/{non_legacy.js => inline_template_non_legacy.js} (100%) create mode 100644 packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/inline_template_non_legacy_non_normalized.ts create mode 100644 packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/inline_template_non_legacy_normalized.ts delete mode 100644 packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/legacy_nonnormalized.js diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/GOLDEN_PARTIAL.js b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/GOLDEN_PARTIAL.js index f4d6f065a4..378e32c273 100644 --- a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/GOLDEN_PARTIAL.js +++ b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/GOLDEN_PARTIAL.js @@ -1,5 +1,5 @@ /**************************************************************************************************** - * PARTIAL FILE: inline_template_non_legacy.js + * PARTIAL FILE: inline_template_non_legacy_normalized.js ****************************************************************************************************/ import { Component, NgModule } from '@angular/core'; import * as i0 from "@angular/core"; @@ -47,7 +47,7 @@ MyModule.ɵinj = i0.ɵɵdefineInjector({ factory: function MyModule_Factory(t) { }], null, null); })(); /**************************************************************************************************** - * PARTIAL FILE: inline_template_non_legacy.d.ts + * PARTIAL FILE: inline_template_non_legacy_normalized.d.ts ****************************************************************************************************/ import * as i0 from "@angular/core"; export declare class MyComponent { @@ -61,7 +61,7 @@ export declare class MyModule { } /**************************************************************************************************** - * PARTIAL FILE: inline_template_non_legacy.js + * PARTIAL FILE: inline_template_non_legacy_non_normalized.js ****************************************************************************************************/ import { Component, NgModule } from '@angular/core'; import * as i0 from "@angular/core"; @@ -109,7 +109,7 @@ MyModule.ɵinj = i0.ɵɵdefineInjector({ factory: function MyModule_Factory(t) { }], null, null); })(); /**************************************************************************************************** - * PARTIAL FILE: inline_template_non_legacy.d.ts + * PARTIAL FILE: inline_template_non_legacy_non_normalized.d.ts ****************************************************************************************************/ import * as i0 from "@angular/core"; export declare class MyComponent { @@ -123,14 +123,14 @@ export declare class MyModule { } /**************************************************************************************************** - * PARTIAL FILE: external_template_non_legacy.js + * PARTIAL FILE: external_template_non_legacy_normalized.js ****************************************************************************************************/ import { Component, NgModule } from '@angular/core'; import * as i0 from "@angular/core"; export class MyComponent { } MyComponent.ɵfac = function MyComponent_Factory(t) { return new (t || MyComponent)(); }; -MyComponent.ɵcmp = i0.ɵɵngDeclareComponent({ version: "0.0.0-PLACEHOLDER", type: MyComponent, selector: "my-component", ngImport: i0, template: { source: "\n
\r\nSome Message\r\n{\r\n value,\r\n select,\r\n =0 {\r\n zero\r\n }\r\n}
", isInline: false } }); +MyComponent.ɵcmp = i0.ɵɵngDeclareComponent({ version: "0.0.0-PLACEHOLDER", type: MyComponent, selector: "my-component", ngImport: i0, template: { source: "\n
\r\n Some Message\r\n {\r\n value,\r\n select,\r\n =0 {\r\n zero\r\n }\r\n }
", isInline: false } }); (function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(MyComponent, [{ type: Component, args: [{ @@ -151,7 +151,7 @@ MyModule.ɵinj = i0.ɵɵdefineInjector({ factory: function MyModule_Factory(t) { }], null, null); })(); /**************************************************************************************************** - * PARTIAL FILE: external_template_non_legacy.d.ts + * PARTIAL FILE: external_template_non_legacy_normalized.d.ts ****************************************************************************************************/ import * as i0 from "@angular/core"; export declare class MyComponent { @@ -165,14 +165,14 @@ export declare class MyModule { } /**************************************************************************************************** - * PARTIAL FILE: external_template_non_legacy.js + * PARTIAL FILE: external_template_non_legacy_non_normalized.js ****************************************************************************************************/ import { Component, NgModule } from '@angular/core'; import * as i0 from "@angular/core"; export class MyComponent { } MyComponent.ɵfac = function MyComponent_Factory(t) { return new (t || MyComponent)(); }; -MyComponent.ɵcmp = i0.ɵɵngDeclareComponent({ version: "0.0.0-PLACEHOLDER", type: MyComponent, selector: "my-component", ngImport: i0, template: { source: "\n
\r\nSome Message\r\n{\r\n value,\r\n select,\r\n =0 {\r\n zero\r\n }\r\n}
", isInline: false } }); +MyComponent.ɵcmp = i0.ɵɵngDeclareComponent({ version: "0.0.0-PLACEHOLDER", type: MyComponent, selector: "my-component", ngImport: i0, template: { source: "\n
\r\n Some Message\r\n {\r\n value,\r\n select,\r\n =0 {\r\n zero\r\n }\r\n }
", isInline: false } }); (function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(MyComponent, [{ type: Component, args: [{ @@ -193,7 +193,7 @@ MyModule.ɵinj = i0.ɵɵdefineInjector({ factory: function MyModule_Factory(t) { }], null, null); })(); /**************************************************************************************************** - * PARTIAL FILE: external_template_non_legacy.d.ts + * PARTIAL FILE: external_template_non_legacy_non_normalized.d.ts ****************************************************************************************************/ import * as i0 from "@angular/core"; export declare class MyComponent { @@ -207,7 +207,7 @@ export declare class MyModule { } /**************************************************************************************************** - * PARTIAL FILE: inline_template_legacy.js + * PARTIAL FILE: inline_template_legacy_normalized.js ****************************************************************************************************/ import { Component, NgModule } from '@angular/core'; import * as i0 from "@angular/core"; @@ -255,7 +255,7 @@ MyModule.ɵinj = i0.ɵɵdefineInjector({ factory: function MyModule_Factory(t) { }], null, null); })(); /**************************************************************************************************** - * PARTIAL FILE: inline_template_legacy.d.ts + * PARTIAL FILE: inline_template_legacy_normalized.d.ts ****************************************************************************************************/ import * as i0 from "@angular/core"; export declare class MyComponent { @@ -269,7 +269,7 @@ export declare class MyModule { } /**************************************************************************************************** - * PARTIAL FILE: inline_template_legacy.js + * PARTIAL FILE: inline_template_legacy_non_normalized.js ****************************************************************************************************/ import { Component, NgModule } from '@angular/core'; import * as i0 from "@angular/core"; @@ -317,7 +317,7 @@ MyModule.ɵinj = i0.ɵɵdefineInjector({ factory: function MyModule_Factory(t) { }], null, null); })(); /**************************************************************************************************** - * PARTIAL FILE: inline_template_legacy.d.ts + * PARTIAL FILE: inline_template_legacy_non_normalized.d.ts ****************************************************************************************************/ import * as i0 from "@angular/core"; export declare class MyComponent { @@ -338,7 +338,7 @@ import * as i0 from "@angular/core"; export class MyComponent { } MyComponent.ɵfac = function MyComponent_Factory(t) { return new (t || MyComponent)(); }; -MyComponent.ɵcmp = i0.ɵɵngDeclareComponent({ version: "0.0.0-PLACEHOLDER", type: MyComponent, selector: "my-component", ngImport: i0, template: { source: "\n
\r\nSome Message\r\n{\r\n value,\r\n select,\r\n =0 {\r\n zero\r\n }\r\n}
", isInline: false } }); +MyComponent.ɵcmp = i0.ɵɵngDeclareComponent({ version: "0.0.0-PLACEHOLDER", type: MyComponent, selector: "my-component", ngImport: i0, template: { source: "\n
\r\n Some Message\r\n {\r\n value,\r\n select,\r\n =0 {\r\n zero\r\n }\r\n }
", isInline: false } }); (function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(MyComponent, [{ type: Component, args: [{ @@ -373,14 +373,14 @@ export declare class MyModule { } /**************************************************************************************************** - * PARTIAL FILE: external_template_legacy.js + * PARTIAL FILE: external_template_legacy_non_normalized.js ****************************************************************************************************/ import { Component, NgModule } from '@angular/core'; import * as i0 from "@angular/core"; export class MyComponent { } MyComponent.ɵfac = function MyComponent_Factory(t) { return new (t || MyComponent)(); }; -MyComponent.ɵcmp = i0.ɵɵngDeclareComponent({ version: "0.0.0-PLACEHOLDER", type: MyComponent, selector: "my-component", ngImport: i0, template: { source: "\n
\r\nSome Message\r\n{\r\n value,\r\n select,\r\n =0 {\r\n zero\r\n }\r\n}
", isInline: false } }); +MyComponent.ɵcmp = i0.ɵɵngDeclareComponent({ version: "0.0.0-PLACEHOLDER", type: MyComponent, selector: "my-component", ngImport: i0, template: { source: "\n
\r\n Some Message\r\n {\r\n value,\r\n select,\r\n =0 {\r\n zero\r\n }\r\n }
", isInline: false } }); (function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(MyComponent, [{ type: Component, args: [{ @@ -401,7 +401,7 @@ MyModule.ɵinj = i0.ɵɵdefineInjector({ factory: function MyModule_Factory(t) { }], null, null); })(); /**************************************************************************************************** - * PARTIAL FILE: external_template_legacy.d.ts + * PARTIAL FILE: external_template_legacy_non_normalized.d.ts ****************************************************************************************************/ import * as i0 from "@angular/core"; export declare class MyComponent { diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/TEST_CASES.json b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/TEST_CASES.json index 9677da1a75..bd6e3d7763 100644 --- a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/TEST_CASES.json +++ b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/TEST_CASES.json @@ -2,9 +2,9 @@ "$schema": "../../test_case_schema.json", "cases": [ { - "description": "should normalize non-legacy message line endings in inline templates where i18nNormalizeLineEndingsInICUs is true", + "description": "should normalize line breaks for non-legacy messages in 'inline templates' where i18nNormalizeLineEndingsInICUs is true", "inputFiles": [ - "inline_template_non_legacy.ts" + "inline_template_non_legacy_normalized.ts" ], "angularCompilerOptions": { "i18nNormalizeLineEndingsInICUs": true, @@ -14,8 +14,8 @@ { "files": [ { - "generated": "inline_template_non_legacy.js", - "expected": "non_legacy.js" + "generated": "inline_template_non_legacy_normalized.js", + "expected": "inline_template_non_legacy.js" } ], "extraChecks": [ @@ -26,9 +26,9 @@ ] }, { - "description": "should normalize non-legacy message line endings in inline templates where i18nNormalizeLineEndingsInICUs is false", + "description": "should normalize line breaks for non-legacy messages in 'inline templates' where i18nNormalizeLineEndingsInICUs is false", "inputFiles": [ - "inline_template_non_legacy.ts" + "inline_template_non_legacy_non_normalized.ts" ], "angularCompilerOptions": { "i18nNormalizeLineEndingsInICUs": false, @@ -38,8 +38,8 @@ { "files": [ { - "generated": "inline_template_non_legacy.js", - "expected": "non_legacy.js" + "generated": "inline_template_non_legacy_non_normalized.js", + "expected": "inline_template_non_legacy.js" } ], "extraChecks": [ @@ -50,9 +50,9 @@ ] }, { - "description": "should normalize non-legacy message line endings in external templates where i18nNormalizeLineEndingsInICUs is true", + "description": "should normalize line breaks for non-legacy messages in 'external templates' where i18nNormalizeLineEndingsInICUs is true", "inputFiles": [ - "external_template_non_legacy.ts" + "external_template_non_legacy_normalized.ts" ], "angularCompilerOptions": { "i18nNormalizeLineEndingsInICUs": true, @@ -62,8 +62,8 @@ { "files": [ { - "generated": "external_template_non_legacy.js", - "expected": "non_legacy.js" + "generated": "external_template_non_legacy_normalized.js", + "expected": "external_template_non_legacy.js" } ], "extraChecks": [ @@ -74,9 +74,9 @@ ] }, { - "description": "should normalize non-legacy line endings in external templates where i18nNormalizeLineEndingsInICUs is false", + "description": "should normalize line breaks for non-legacy messages in 'external templates' where i18nNormalizeLineEndingsInICUs is false", "inputFiles": [ - "external_template_non_legacy.ts" + "external_template_non_legacy_non_normalized.ts" ], "angularCompilerOptions": { "i18nNormalizeLineEndingsInICUs": false, @@ -86,8 +86,8 @@ { "files": [ { - "generated": "external_template_non_legacy.js", - "expected": "non_legacy.js" + "generated": "external_template_non_legacy_non_normalized.js", + "expected": "external_template_non_legacy.js" } ], "extraChecks": [ @@ -100,7 +100,7 @@ { "description": "should compute normalized legacy ids for messages in inline templates where i18nNormalizeLineEndingsInICUs is true", "inputFiles": [ - "inline_template_legacy.ts" + "inline_template_legacy_normalized.ts" ], "angularCompilerOptions": { "i18nNormalizeLineEndingsInICUs": true, @@ -110,8 +110,8 @@ { "files": [ { - "generated": "inline_template_legacy.js", - "expected": "legacy_normalized.js" + "generated": "inline_template_legacy_normalized.js", + "expected": "inline_template_legacy.js" } ], "extraChecks": [ @@ -124,7 +124,7 @@ { "description": "should compute normalized legacy ids for messages in inline templates where i18nNormalizeLineEndingsInICUs is false", "inputFiles": [ - "inline_template_legacy.ts" + "inline_template_legacy_non_normalized.ts" ], "angularCompilerOptions": { "i18nNormalizeLineEndingsInICUs": false, @@ -134,8 +134,8 @@ { "files": [ { - "generated": "inline_template_legacy.js", - "expected": "legacy_normalized.js" + "generated": "inline_template_legacy_non_normalized.js", + "expected": "inline_template_legacy.js" } ], "extraChecks": [ @@ -156,12 +156,6 @@ }, "expectations": [ { - "files": [ - { - "generated": "external_template_legacy_normalized.js", - "expected": "legacy_normalized.js" - } - ], "extraChecks": [ "verifyPlaceholdersIntegrity", "verifyUniqueConsts" @@ -172,7 +166,7 @@ { "description": "should compute non-normalized legacy ids for messages in external templates where i18nNormalizeLineEndingsInICUs is false", "inputFiles": [ - "external_template_legacy.ts" + "external_template_legacy_non_normalized.ts" ], "angularCompilerOptions": { "i18nNormalizeLineEndingsInICUs": false, @@ -180,12 +174,6 @@ }, "expectations": [ { - "files": [ - { - "generated": "external_template_legacy.js", - "expected": "legacy_nonnormalized.js" - } - ], "extraChecks": [ "verifyPlaceholdersIntegrity", "verifyUniqueConsts" diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/external_template_legacy_non_normalized.js b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/external_template_legacy_non_normalized.js new file mode 100644 index 0000000000..3de7f7926b --- /dev/null +++ b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/external_template_legacy_non_normalized.js @@ -0,0 +1,8 @@ +// NOTE: The ids generated by the compiler are different if the template is external and we are not explicitly normalizing the line endings. +$I18N_1$ = $localize `:␟4f9ce2c66b187afd9898b25f6336d1eb2be8b5dc␟7326958852138509669:abc +def`; +… +$I18N_2$ = $localize `:␟ed275132ef4cf80cbcf817e66b74c384e68340b1␟2056861121373082280:{VAR_SELECT, select, =0 {zero + }}` +… +$I18N_3$ = $localize `:␟55d63b098ee4cce61944f086cdd9b60c6bcef20b␟6752545234037626269: Some Message ${$I18N_2$}:ICU:`; diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/external_template_legacy.ts b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/external_template_legacy_non_normalized.ts similarity index 100% rename from packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/external_template_legacy.ts rename to packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/external_template_legacy_non_normalized.ts diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/external_template_legacy_normalized.js b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/external_template_legacy_normalized.js new file mode 100644 index 0000000000..b52187f4b2 --- /dev/null +++ b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/external_template_legacy_normalized.js @@ -0,0 +1,8 @@ +// NOTE: The ids generated by the compiler are different if the template is external and we are not explicitly normalizing the line endings. +$I18N_1$ = $localize `:␟4f9ce2c66b187afd9898b25f6336d1eb2be8b5dc␟7326958852138509669:abc +def`; +… +$I18N_2$ = $localize `:␟47e6af99f2e9137a977cf8c7bf39d091d339ae3a␟2056861121373082280:{VAR_SELECT, select, =0 {zero + }}` +… +$I18N_3$ = $localize `:␟23ea0658f9e9f6c61c9e2798fff0f4b11c509fae␟6752545234037626269: Some Message ${$I18N_2$}:ICU:`; diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/external_template_non_legacy.js b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/external_template_non_legacy.js new file mode 100644 index 0000000000..5f848cbfe4 --- /dev/null +++ b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/external_template_non_legacy.js @@ -0,0 +1,7 @@ +$I18N_0$ = $localize `abc +def`; +… +$I18N_4$ = $localize `{VAR_SELECT, select, =0 {zero + }}` +… +$I18N_3$ = $localize ` Some Message ${$I18N_4$}:ICU:`; diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/external_template_non_legacy.ts b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/external_template_non_legacy_non_normalized.ts similarity index 100% rename from packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/external_template_non_legacy.ts rename to packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/external_template_non_legacy_non_normalized.ts diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/external_template_non_legacy_normalized.ts b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/external_template_non_legacy_normalized.ts new file mode 100644 index 0000000000..26ea41f171 --- /dev/null +++ b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/external_template_non_legacy_normalized.ts @@ -0,0 +1,15 @@ +import {Component, NgModule} from '@angular/core'; + +@Component({ + selector: 'my-component', + // NOTE: The template has escaped `\r\n` line-endings markers that will be converted to real + // `\r\n` line-ending chars when loaded from the test file-system. + templateUrl: 'template.html' +}) +export class MyComponent { + value!: any; +} + +@NgModule({declarations: [MyComponent]}) +export class MyModule { +} diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/legacy_normalized.js b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/inline_template_legacy.js similarity index 100% rename from packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/legacy_normalized.js rename to packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/inline_template_legacy.js diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/inline_template_legacy.ts b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/inline_template_legacy_non_normalized.ts similarity index 100% rename from packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/inline_template_legacy.ts rename to packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/inline_template_legacy_non_normalized.ts diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/inline_template_non_legacy.ts b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/inline_template_legacy_normalized.ts similarity index 100% rename from packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/inline_template_non_legacy.ts rename to packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/inline_template_legacy_normalized.ts diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/non_legacy.js b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/inline_template_non_legacy.js similarity index 100% rename from packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/non_legacy.js rename to packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/inline_template_non_legacy.js diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/inline_template_non_legacy_non_normalized.ts b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/inline_template_non_legacy_non_normalized.ts new file mode 100644 index 0000000000..e488573f5a --- /dev/null +++ b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/inline_template_non_legacy_non_normalized.ts @@ -0,0 +1,25 @@ +import {Component, NgModule} from '@angular/core'; + +@Component({ + selector: 'my-component', + // NOTE: This template has escaped `\r\n` line-endings markers that will be converted to real + // `\r\n` line-ending chars when loaded from the test file-system. + template: ` +
\r\n +Some Message\r\n +{\r\n + value,\r\n + select,\r\n + =0 {\r\n + zero\r\n + }\r\n +}
` +}) +export class MyComponent { + value!: any; +} + +@NgModule({declarations: [MyComponent]}) +export class MyModule { +} diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/inline_template_non_legacy_normalized.ts b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/inline_template_non_legacy_normalized.ts new file mode 100644 index 0000000000..e488573f5a --- /dev/null +++ b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/inline_template_non_legacy_normalized.ts @@ -0,0 +1,25 @@ +import {Component, NgModule} from '@angular/core'; + +@Component({ + selector: 'my-component', + // NOTE: This template has escaped `\r\n` line-endings markers that will be converted to real + // `\r\n` line-ending chars when loaded from the test file-system. + template: ` +
\r\n +Some Message\r\n +{\r\n + value,\r\n + select,\r\n + =0 {\r\n + zero\r\n + }\r\n +}
` +}) +export class MyComponent { + value!: any; +} + +@NgModule({declarations: [MyComponent]}) +export class MyModule { +} diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/legacy_nonnormalized.js b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/legacy_nonnormalized.js deleted file mode 100644 index 6706670177..0000000000 --- a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/legacy_nonnormalized.js +++ /dev/null @@ -1,10 +0,0 @@ -// NOTE: The ids generated by the compiler are different if the template is external and we are not explicitly normalizing the line endings. -$I18N_0$ = $localize `:␟4f9ce2c66b187afd9898b25f6336d1eb2be8b5dc␟7326958852138509669:abc -def`; -… -$I18N_4$ = $localize `:␟70a685282be2d956e4db234fa3d985970672faa0␟4863953183043480207:{VAR_SELECT, select, =0 {zero - }}` -… -$I18N_3$ = $localize `:␟6a55b51b9bcf8f84b1b868c585ae09949668a72b␟2773178924738647105: -Some Message -${$I18N_4$}:ICU:`; diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/template.html b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/template.html index 81f2da3e5c..db08b6bb46 100644 --- a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/template.html +++ b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/line_ending_normalization/template.html @@ -1,11 +1,14 @@ - +
\r\n -Some Message\r\n -{\r\n - value,\r\n - select,\r\n - =0 {\r\n - zero\r\n - }\r\n -}
\ No newline at end of file + Some Message\r\n + {\r\n + value,\r\n + select,\r\n + =0 {\r\n + zero\r\n + }\r\n + } \ No newline at end of file diff --git a/packages/compiler-cli/test/compliance/test_helpers/compile_test.ts b/packages/compiler-cli/test/compliance/test_helpers/compile_test.ts index 41019853da..ab1ace64f7 100644 --- a/packages/compiler-cli/test/compliance/test_helpers/compile_test.ts +++ b/packages/compiler-cli/test/compliance/test_helpers/compile_test.ts @@ -127,13 +127,19 @@ function getOptions( * Replace escaped line-ending markers (\r\n) with real line-ending characters. * * This allows us to simulate, more reliably, files that have `\r\n` line-endings. - * (See `line_ending_normalization` test cases.) + * (See `test_cases/r3_view_compiler_i18n/line_ending_normalization/template.html`.) */ function monkeyPatchReadFile(fs: FileSystem): void { const originalReadFile = fs.readFile; fs.readFile = (path: AbsoluteFsPath): string => { const file = originalReadFile.call(fs, path); - return file.replace(/\\r\\n\r?\n/g, '\r\n'); + return file + // First convert actual `\r\n` sequences to `\n` + .replace(/\r\n/g, '\n') + // unescape `\r\n` at the end of a line + .replace(/\\r\\n\n/g, '\r\n') + // unescape `\\r\\n`, at the end of a line, to `\r\n` + .replace(/\\\\r\\\\n(\r?\n)/g, '\\r\\n$1'); }; } diff --git a/packages/compiler-cli/test/compliance/test_helpers/sourcemap_helpers.ts b/packages/compiler-cli/test/compliance/test_helpers/sourcemap_helpers.ts index 1ed43c393e..19ef8f16e9 100644 --- a/packages/compiler-cli/test/compliance/test_helpers/sourcemap_helpers.ts +++ b/packages/compiler-cli/test/compliance/test_helpers/sourcemap_helpers.ts @@ -97,8 +97,8 @@ function extractMappings( } function unescape(str: string): string { - const replacements: Record = {'\\n': '\n', '\\\\': '\\'}; - return str.replace(/\\[n\\]/g, match => replacements[match]); + const replacements: Record = {'\\n': '\n', '\\r': '\r', '\\\\': '\\'}; + return str.replace(/\\[rn\\]/g, match => replacements[match]); } /**