fix(test): support typechecking docs with CRLF line endings (#12748)

This commit is contained in:
Geert-Jan Zwiers 2021-11-15 15:58:04 +01:00 committed by GitHub
parent dd91ecef50
commit 58e7b290dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 51 additions and 3 deletions

View File

@ -25,6 +25,7 @@
"cli/tests/testdata/badly_formatted.json",
"cli/tests/testdata/byte_order_mark.ts",
"cli/tests/testdata/fmt/*",
"cli/tests/testdata/test/markdown_windows.md",
"cli/tsc/*typescript.js",
"test_util/std",
"test_util/wpt",

3
.gitattributes vendored
View File

@ -12,3 +12,6 @@
# Doesn't include them in the language statistics.
/cli/tsc/00_typescript.js linguist-vendored
/cli/dts/* linguist-vendored
# Keep Windows line endings in cross-platform doc check test file
/cli/tests/testdata/test/markdown_windows.md eol=crlf

View File

@ -129,7 +129,7 @@ fn fmt_ignore_unexplicit_files() {
}
itest!(fmt_check_tests_dir {
args: "fmt --check ./ --ignore=.test_coverage,fmt/fmt_with_config/",
args: "fmt --check ./ --ignore=.test_coverage,fmt/fmt_with_config/,test/markdown_windows.md",
output: "fmt/expected_fmt_check_tests_dir.out",
exit_code: 1,
});

View File

@ -85,6 +85,12 @@ itest!(markdown {
output: "test/markdown.out",
});
itest!(markdown_windows {
args: "test --doc --allow-all test/markdown_windows.md",
exit_code: 1,
output: "test/markdown_windows.out",
});
itest!(text {
args: "test --doc --allow-all test/text.md",
exit_code: 0,

View File

@ -0,0 +1,31 @@
# Documentation
The following block does not have a language attribute and should be ignored:
```
This is a fenced block without attributes, it's invalid and it should be ignored.
```
The following block should be given a js extension on extraction:
```js
console.log("js");
```
The following block should be given a ts extension on extraction:
```ts
console.log("ts");
```
The following example contains the ignore attribute and will be ignored:
```ts ignore
const value: Invalid = "ignored";
```
The following example will trigger the type-checker to fail:
```ts
const a: string = 42;
```

View File

@ -0,0 +1,7 @@
Check [WILDCARD]/test/markdown_windows.md$11-14.js
Check [WILDCARD]/test/markdown_windows.md$17-20.ts
Check [WILDCARD]/test/markdown_windows.md$29-32.ts
error: TS2322 [ERROR]: Type 'number' is not assignable to type 'string'.
const a: string = 42;
^
at [WILDCARD]/test/markdown_windows.md$29-32.ts:1:7

View File

@ -590,7 +590,7 @@ fn extract_files_from_source_comments(
scope_analysis: false,
})?;
let comments = parsed_source.comments().get_vec();
let blocks_regex = Regex::new(r"```([^\n]*)\n([\S\s]*?)```")?;
let blocks_regex = Regex::new(r"```([^\r\n]*)\r?\n([\S\s]*?)```")?;
let lines_regex = Regex::new(r"(?:\* ?)(?:\# ?)?(.*)")?;
let files = comments
@ -630,7 +630,7 @@ fn extract_files_from_fenced_blocks(
col: 0,
};
let blocks_regex = Regex::new(r"```([^\n]*)\n([\S\s]*?)```")?;
let blocks_regex = Regex::new(r"```([^\r\n]*)\r?\n([\S\s]*?)```")?;
let lines_regex = Regex::new(r"(?:\# ?)?(.*)")?;
extract_files_from_regex_blocks(