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
This commit is contained in:
Pete Bacon Darwin 2020-12-18 09:41:05 +00:00 committed by atscott
parent 2224ab712d
commit 9f662e1313
18 changed files with 151 additions and 76 deletions

View File

@ -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: "<!-- 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. -->\n<div title=\"abc\r\ndef\" i18n-title i18n>\r\nSome Message\r\n{\r\n value,\r\n select,\r\n =0 {\r\n zero\r\n }\r\n}</div>", isInline: false } });
MyComponent.ɵcmp = i0.ɵɵngDeclareComponent({ version: "0.0.0-PLACEHOLDER", type: MyComponent, selector: "my-component", ngImport: i0, template: { source: "<!--\n 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.\n This conversion happens in the monkeyPatchReadFile() function, which changes `fs.readFile()`.\n-->\n<div title=\"abc\r\ndef\" i18n-title i18n>\r\n Some Message\r\n {\r\n value,\r\n select,\r\n =0 {\r\n zero\r\n }\r\n }</div>", 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: "<!-- 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. -->\n<div title=\"abc\r\ndef\" i18n-title i18n>\r\nSome Message\r\n{\r\n value,\r\n select,\r\n =0 {\r\n zero\r\n }\r\n}</div>", isInline: false } });
MyComponent.ɵcmp = i0.ɵɵngDeclareComponent({ version: "0.0.0-PLACEHOLDER", type: MyComponent, selector: "my-component", ngImport: i0, template: { source: "<!--\n 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.\n This conversion happens in the monkeyPatchReadFile() function, which changes `fs.readFile()`.\n-->\n<div title=\"abc\r\ndef\" i18n-title i18n>\r\n Some Message\r\n {\r\n value,\r\n select,\r\n =0 {\r\n zero\r\n }\r\n }</div>", 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: "<!-- 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. -->\n<div title=\"abc\r\ndef\" i18n-title i18n>\r\nSome Message\r\n{\r\n value,\r\n select,\r\n =0 {\r\n zero\r\n }\r\n}</div>", isInline: false } });
MyComponent.ɵcmp = i0.ɵɵngDeclareComponent({ version: "0.0.0-PLACEHOLDER", type: MyComponent, selector: "my-component", ngImport: i0, template: { source: "<!--\n 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.\n This conversion happens in the monkeyPatchReadFile() function, which changes `fs.readFile()`.\n-->\n<div title=\"abc\r\ndef\" i18n-title i18n>\r\n Some Message\r\n {\r\n value,\r\n select,\r\n =0 {\r\n zero\r\n }\r\n }</div>", 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: "<!-- 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. -->\n<div title=\"abc\r\ndef\" i18n-title i18n>\r\nSome Message\r\n{\r\n value,\r\n select,\r\n =0 {\r\n zero\r\n }\r\n}</div>", isInline: false } });
MyComponent.ɵcmp = i0.ɵɵngDeclareComponent({ version: "0.0.0-PLACEHOLDER", type: MyComponent, selector: "my-component", ngImport: i0, template: { source: "<!--\n 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.\n This conversion happens in the monkeyPatchReadFile() function, which changes `fs.readFile()`.\n-->\n<div title=\"abc\r\ndef\" i18n-title i18n>\r\n Some Message\r\n {\r\n value,\r\n select,\r\n =0 {\r\n zero\r\n }\r\n }</div>", 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 {

View File

@ -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"

View File

@ -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:`;

View File

@ -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:`;

View File

@ -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:`;

View File

@ -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 {
}

View File

@ -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: `
<div title="abc\r\n
def" i18n-title i18n>\r\n
Some Message\r\n
{\r\n
value,\r\n
select,\r\n
=0 {\r\n
zero\r\n
}\r\n
}</div>`
})
export class MyComponent {
value!: any;
}
@NgModule({declarations: [MyComponent]})
export class MyModule {
}

View File

@ -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: `
<div title="abc\r\n
def" i18n-title i18n>\r\n
Some Message\r\n
{\r\n
value,\r\n
select,\r\n
=0 {\r\n
zero\r\n
}\r\n
}</div>`
})
export class MyComponent {
value!: any;
}
@NgModule({declarations: [MyComponent]})
export class MyModule {
}

View File

@ -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:`;

View File

@ -1,11 +1,14 @@
<!-- 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. -->
<!--
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.
This conversion happens in the monkeyPatchReadFile() function, which changes `fs.readFile()`.
-->
<div title="abc\r\n
def" i18n-title i18n>\r\n
Some Message\r\n
{\r\n
value,\r\n
select,\r\n
=0 {\r\n
zero\r\n
}\r\n
}</div>
Some Message\r\n
{\r\n
value,\r\n
select,\r\n
=0 {\r\n
zero\r\n
}\r\n
}</div>

View File

@ -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');
};
}

View File

@ -97,8 +97,8 @@ function extractMappings(
}
function unescape(str: string): string {
const replacements: Record<any, string> = {'\\n': '\n', '\\\\': '\\'};
return str.replace(/\\[n\\]/g, match => replacements[match]);
const replacements: Record<any, string> = {'\\n': '\n', '\\r': '\r', '\\\\': '\\'};
return str.replace(/\\[rn\\]/g, match => replacements[match]);
}
/**