diff options
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/badly_formatted.json | 12 | ||||
-rw-r--r-- | cli/tests/badly_formatted.md | 18 | ||||
-rw-r--r-- | cli/tests/badly_formatted_fixed.json | 8 | ||||
-rw-r--r-- | cli/tests/badly_formatted_fixed.md | 14 | ||||
-rw-r--r-- | cli/tests/fmt/expected_fmt_check_formatted_files.out | 2 | ||||
-rw-r--r-- | cli/tests/fmt/expected_fmt_check_ignore.out | 2 | ||||
-rw-r--r-- | cli/tests/fmt/expected_fmt_check_tests_dir.out | 2 | ||||
-rw-r--r-- | cli/tests/fmt/formatted4.jsonc | 4 | ||||
-rw-r--r-- | cli/tests/integration_tests.rs | 42 |
9 files changed, 92 insertions, 12 deletions
diff --git a/cli/tests/badly_formatted.json b/cli/tests/badly_formatted.json new file mode 100644 index 000000000..f2bacf73d --- /dev/null +++ b/cli/tests/badly_formatted.json @@ -0,0 +1,12 @@ +{ + + + "key1": "value1", + "key2": true, + "key3": ["value2", "value3", false], + "keys": { + "more": "values" + } + + +}
\ No newline at end of file diff --git a/cli/tests/badly_formatted.md b/cli/tests/badly_formatted.md index adffe3e46..26afe483b 100644 --- a/cli/tests/badly_formatted.md +++ b/cli/tests/badly_formatted.md @@ -25,4 +25,22 @@ hello( "alice"); function foo(): number { return 2; } +``` + +```jsonc + +{ + // Comment in JSON + "key": "value", + "key2": + "value2", +} + +``` + +```json +{ + "numbers": + ["1", "2"] +} ```
\ No newline at end of file diff --git a/cli/tests/badly_formatted_fixed.json b/cli/tests/badly_formatted_fixed.json new file mode 100644 index 000000000..0d697a2c6 --- /dev/null +++ b/cli/tests/badly_formatted_fixed.json @@ -0,0 +1,8 @@ +{ + "key1": "value1", + "key2": true, + "key3": ["value2", "value3", false], + "keys": { + "more": "values" + } +} diff --git a/cli/tests/badly_formatted_fixed.md b/cli/tests/badly_formatted_fixed.md index 359a8aead..8ba74cac3 100644 --- a/cli/tests/badly_formatted_fixed.md +++ b/cli/tests/badly_formatted_fixed.md @@ -21,3 +21,17 @@ function foo(): number { return 2; } ``` + +```jsonc +{ + // Comment in JSON + "key": "value", + "key2": "value2" +} +``` + +```json +{ + "numbers": ["1", "2"] +} +``` diff --git a/cli/tests/fmt/expected_fmt_check_formatted_files.out b/cli/tests/fmt/expected_fmt_check_formatted_files.out index 7c1e471b9..5a4833dd4 100644 --- a/cli/tests/fmt/expected_fmt_check_formatted_files.out +++ b/cli/tests/fmt/expected_fmt_check_formatted_files.out @@ -1 +1 @@ -Checked 3 files +Checked 4 files diff --git a/cli/tests/fmt/expected_fmt_check_ignore.out b/cli/tests/fmt/expected_fmt_check_ignore.out index 158c556c2..7c1e471b9 100644 --- a/cli/tests/fmt/expected_fmt_check_ignore.out +++ b/cli/tests/fmt/expected_fmt_check_ignore.out @@ -1 +1 @@ -Checked 2 files +Checked 3 files diff --git a/cli/tests/fmt/expected_fmt_check_tests_dir.out b/cli/tests/fmt/expected_fmt_check_tests_dir.out index e2dc2b4ae..fe84cd485 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 6 not formatted files in [WILDCARD] files +error: Found 7 not formatted files in [WILDCARD] files diff --git a/cli/tests/fmt/formatted4.jsonc b/cli/tests/fmt/formatted4.jsonc new file mode 100644 index 000000000..f0f72a6ed --- /dev/null +++ b/cli/tests/fmt/formatted4.jsonc @@ -0,0 +1,4 @@ +{ + // Comment + "key": "value" +} diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 988372b17..b55111154 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -496,30 +496,43 @@ mod integration { fn fmt_test() { let t = TempDir::new().expect("tempdir fail"); 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_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"); + + let fixed_md = util::root_path().join("cli/tests/badly_formatted_fixed.md"); + let badly_formatted_original_md = + util::root_path().join("cli/tests/badly_formatted.md"); + let badly_formatted_md = t.path().join("badly_formatted.md"); + let badly_formatted_md_str = badly_formatted_md.to_str().unwrap(); std::fs::copy(&badly_formatted_original_md, &badly_formatted_md) .expect("Failed to copy file"); + + let fixed_json = + util::root_path().join("cli/tests/badly_formatted_fixed.json"); + let badly_formatted_original_json = + util::root_path().join("cli/tests/badly_formatted.json"); + let badly_formatted_json = t.path().join("badly_formatted.json"); + let badly_formatted_json_str = badly_formatted_json.to_str().unwrap(); + std::fs::copy(&badly_formatted_original_json, &badly_formatted_json) + .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_js_str, badly_formatted_md_str + "--ignore={},{},{}", + badly_formatted_js_str, + badly_formatted_md_str, + badly_formatted_json_str )) .arg("--check") .arg(badly_formatted_js_str) .arg(badly_formatted_md_str) + .arg(badly_formatted_json_str) .spawn() .expect("Failed to spawn script") .wait() @@ -532,6 +545,7 @@ mod integration { .arg("--check") .arg(badly_formatted_js_str) .arg(badly_formatted_md_str) + .arg(badly_formatted_json_str) .spawn() .expect("Failed to spawn script") .wait() @@ -543,6 +557,7 @@ mod integration { .arg("fmt") .arg(badly_formatted_js_str) .arg(badly_formatted_md_str) + .arg(badly_formatted_json_str) .spawn() .expect("Failed to spawn script") .wait() @@ -550,10 +565,13 @@ mod integration { assert!(status.success()); let expected_js = std::fs::read_to_string(fixed_js).unwrap(); let expected_md = std::fs::read_to_string(fixed_md).unwrap(); + let expected_json = std::fs::read_to_string(fixed_json).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(); + let actual_json = std::fs::read_to_string(badly_formatted_json).unwrap(); assert_eq!(expected_js, actual_js); assert_eq!(expected_md, actual_md); + assert_eq!(expected_json, actual_json); } mod file_watcher { @@ -2838,7 +2856,7 @@ console.log("finish"); }); itest!(fmt_check_tests_dir { - args: "fmt --check ./", + args: "fmt --check ./ --ignore=.test_coverage", output: "fmt/expected_fmt_check_tests_dir.out", exit_code: 1, }); @@ -2850,7 +2868,7 @@ console.log("finish"); }); itest!(fmt_check_formatted_files { - args: "fmt --check fmt/formatted1.js fmt/formatted2.ts fmt/formatted3.md", + args: "fmt --check fmt/formatted1.js fmt/formatted2.ts fmt/formatted3.md fmt/formatted4.jsonc", output: "fmt/expected_fmt_check_formatted_files.out", exit_code: 0, }); @@ -2875,6 +2893,12 @@ console.log("finish"); ), }); + itest!(fmt_stdin_json { + args: "fmt --ext=json -", + input: Some("{ \"key\": \"value\"}"), + output_str: Some("{ \"key\": \"value\" }\n"), + }); + itest!(fmt_stdin_check_formatted { args: "fmt --check -", input: Some("const a = 1;\n"), |