summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
authorSatya Rohith <me@satyarohith.com>2021-01-19 23:09:35 +0530
committerGitHub <noreply@github.com>2021-01-19 18:39:35 +0100
commit16036a8a5170030a95a56b28b29b1b355d0d0f80 (patch)
tree87d6e5dfe13662270df61a5221efe814b4b1f40f /cli/tests
parent4c223d0521bf9711ccd4813a04ba7b1f7899485b (diff)
feat: add markdown support to deno fmt (#8887)
This commit adds support for formatting markdown files with "deno fmt". Additionally "--ext={js|jsx|ts|tsx|md}" flag was added to "deno fmt" that allows to specify file type when providing contents over stdio.
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/badly_formatted.md28
-rw-r--r--cli/tests/badly_formatted_fixed.md23
-rw-r--r--cli/tests/fmt/expected_fmt_check_formatted_files.out2
-rw-r--r--cli/tests/fmt/expected_fmt_check_ignore.out2
-rw-r--r--cli/tests/fmt/expected_fmt_check_tests_dir.out2
-rw-r--r--cli/tests/fmt/formatted3.md17
-rw-r--r--cli/tests/integration_tests.rs48
7 files changed, 106 insertions, 16 deletions
diff --git a/cli/tests/badly_formatted.md b/cli/tests/badly_formatted.md
new file mode 100644
index 000000000..adffe3e46
--- /dev/null
+++ b/cli/tests/badly_formatted.md
@@ -0,0 +1,28 @@
+# Hello Markdown
+
+```js
+console.log("Hello World"
+
+)
+```
+
+```javascript
+console.log("Hello World2"
+
+)
+```
+
+```ts
+
+function hello(name: string ) {
+ console.log(name);
+};
+
+hello( "alice");
+```
+
+```typescript
+function foo(): number {
+ return 2;
+}
+``` \ No newline at end of file
diff --git a/cli/tests/badly_formatted_fixed.md b/cli/tests/badly_formatted_fixed.md
new file mode 100644
index 000000000..359a8aead
--- /dev/null
+++ b/cli/tests/badly_formatted_fixed.md
@@ -0,0 +1,23 @@
+# Hello Markdown
+
+```js
+console.log("Hello World");
+```
+
+```javascript
+console.log("Hello World2");
+```
+
+```ts
+function hello(name: string) {
+ console.log(name);
+}
+
+hello("alice");
+```
+
+```typescript
+function foo(): number {
+ return 2;
+}
+```
diff --git a/cli/tests/fmt/expected_fmt_check_formatted_files.out b/cli/tests/fmt/expected_fmt_check_formatted_files.out
index 158c556c2..7c1e471b9 100644
--- a/cli/tests/fmt/expected_fmt_check_formatted_files.out
+++ b/cli/tests/fmt/expected_fmt_check_formatted_files.out
@@ -1 +1 @@
-Checked 2 files
+Checked 3 files
diff --git a/cli/tests/fmt/expected_fmt_check_ignore.out b/cli/tests/fmt/expected_fmt_check_ignore.out
index c05ac45a1..158c556c2 100644
--- a/cli/tests/fmt/expected_fmt_check_ignore.out
+++ b/cli/tests/fmt/expected_fmt_check_ignore.out
@@ -1 +1 @@
-Checked 1 file
+Checked 2 files
diff --git a/cli/tests/fmt/expected_fmt_check_tests_dir.out b/cli/tests/fmt/expected_fmt_check_tests_dir.out
index 00d7cb3fa..e2dc2b4ae 100644
--- a/cli/tests/fmt/expected_fmt_check_tests_dir.out
+++ b/cli/tests/fmt/expected_fmt_check_tests_dir.out
@@ -1,2 +1,2 @@
[WILDCARD]
-error: Found 5 not formatted files in [WILDCARD] files
+error: Found 6 not formatted files in [WILDCARD] files
diff --git a/cli/tests/fmt/formatted3.md b/cli/tests/fmt/formatted3.md
new file mode 100644
index 000000000..e6e616584
--- /dev/null
+++ b/cli/tests/fmt/formatted3.md
@@ -0,0 +1,17 @@
+# Hello
+
+```js
+function foo() {
+ return 42;
+}
+
+foo();
+```
+
+```ts
+function bar(): number {
+ return 42;
+}
+
+bar();
+```
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index 0af4709fb..80a7222e5 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -511,20 +511,31 @@ fn cache_invalidation_test_no_check() {
#[test]
fn fmt_test() {
let t = TempDir::new().expect("tempdir fail");
- let fixed = util::root_path().join("cli/tests/badly_formatted_fixed.js");
- let badly_formatted_original =
+ let fixed_js = util::root_path().join("cli/tests/badly_formatted_fixed.js");
+ let fixed_md = util::root_path().join("cli/tests/badly_formatted_fixed.md");
+ let badly_formatted_original_js =
util::root_path().join("cli/tests/badly_formatted.mjs");
- let badly_formatted = t.path().join("badly_formatted.js");
- let badly_formatted_str = badly_formatted.to_str().unwrap();
- std::fs::copy(&badly_formatted_original, &badly_formatted)
+ let badly_formatted_original_md =
+ util::root_path().join("cli/tests/badly_formatted.md");
+ let badly_formatted_js = t.path().join("badly_formatted.js");
+ let badly_formatted_md = t.path().join("badly_formatted.md");
+ let badly_formatted_js_str = badly_formatted_js.to_str().unwrap();
+ let badly_formatted_md_str = badly_formatted_md.to_str().unwrap();
+ std::fs::copy(&badly_formatted_original_js, &badly_formatted_js)
+ .expect("Failed to copy file");
+ std::fs::copy(&badly_formatted_original_md, &badly_formatted_md)
.expect("Failed to copy file");
// First, check formatting by ignoring the badly formatted file.
let status = util::deno_cmd()
.current_dir(util::root_path())
.arg("fmt")
- .arg(format!("--ignore={}", badly_formatted_str))
+ .arg(format!(
+ "--ignore={},{}",
+ badly_formatted_js_str, badly_formatted_md_str
+ ))
.arg("--check")
- .arg(badly_formatted_str)
+ .arg(badly_formatted_js_str)
+ .arg(badly_formatted_md_str)
.spawn()
.expect("Failed to spawn script")
.wait()
@@ -535,7 +546,8 @@ fn fmt_test() {
.current_dir(util::root_path())
.arg("fmt")
.arg("--check")
- .arg(badly_formatted_str)
+ .arg(badly_formatted_js_str)
+ .arg(badly_formatted_md_str)
.spawn()
.expect("Failed to spawn script")
.wait()
@@ -545,15 +557,19 @@ fn fmt_test() {
let status = util::deno_cmd()
.current_dir(util::root_path())
.arg("fmt")
- .arg(badly_formatted_str)
+ .arg(badly_formatted_js_str)
+ .arg(badly_formatted_md_str)
.spawn()
.expect("Failed to spawn script")
.wait()
.expect("Failed to wait for child process");
assert!(status.success());
- let expected = std::fs::read_to_string(fixed).unwrap();
- let actual = std::fs::read_to_string(badly_formatted).unwrap();
- assert_eq!(expected, actual);
+ let expected_js = std::fs::read_to_string(fixed_js).unwrap();
+ let expected_md = std::fs::read_to_string(fixed_md).unwrap();
+ let actual_js = std::fs::read_to_string(badly_formatted_js).unwrap();
+ let actual_md = std::fs::read_to_string(badly_formatted_md).unwrap();
+ assert_eq!(expected_js, actual_js);
+ assert_eq!(expected_md, actual_md);
}
// Helper function to skip watcher output that contains "Restarting"
@@ -2751,7 +2767,7 @@ itest!(fmt_quiet_check_fmt_dir {
});
itest!(fmt_check_formatted_files {
- args: "fmt --check fmt/formatted1.js fmt/formatted2.ts",
+ args: "fmt --check fmt/formatted1.js fmt/formatted2.ts fmt/formatted3.md",
output: "fmt/expected_fmt_check_formatted_files.out",
exit_code: 0,
});
@@ -2768,6 +2784,12 @@ itest!(fmt_stdin {
output_str: Some("const a = 1;\n"),
});
+itest!(fmt_stdin_markdown {
+ args: "fmt --ext=md -",
+ input: Some("# Hello Markdown\n```ts\nconsole.log( \"text\")\n```\n"),
+ output_str: Some("# Hello Markdown\n\n```ts\nconsole.log(\"text\");\n```\n"),
+});
+
itest!(fmt_stdin_check_formatted {
args: "fmt --check -",
input: Some("const a = 1;\n"),