Skip to content

Commit

Permalink
fix(test): support typechecking docs with CRLF line endings (denoland…
Browse files Browse the repository at this point in the history
  • Loading branch information
GJZwiers authored Nov 15, 2021
1 parent dd91ece commit 58e7b29
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 3 deletions.
1 change: 1 addition & 0 deletions .dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion cli/tests/integration/fmt_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
6 changes: 6 additions & 0 deletions cli/tests/integration/test_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
31 changes: 31 additions & 0 deletions cli/tests/testdata/test/markdown_windows.md
Original file line number Diff line number Diff line change
@@ -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;
```
7 changes: 7 additions & 0 deletions cli/tests/testdata/test/markdown_windows.out
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions cli/tools/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 58e7b29

Please sign in to comment.