summaryrefslogtreecommitdiff
path: root/prettier/main_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'prettier/main_test.ts')
-rw-r--r--prettier/main_test.ts94
1 files changed, 94 insertions, 0 deletions
diff --git a/prettier/main_test.ts b/prettier/main_test.ts
index 718b716af..0d6015080 100644
--- a/prettier/main_test.ts
+++ b/prettier/main_test.ts
@@ -37,6 +37,10 @@ function normalizeOutput(output: string): string {
.join("\n");
}
+function normalizeSourceCode(source: string): string {
+ return source.replace(/\r/g, "");
+}
+
async function clearTestdataChanges(): Promise<void> {
await xrun({ args: ["git", "checkout", testdata] }).status();
}
@@ -90,3 +94,93 @@ Formatting ./prettier/testdata/foo/1.js`
await clearTestdataChanges();
});
+
+test(async function testPrettierOptions() {
+ await clearTestdataChanges();
+
+ const file0 = join(testdata, "opts", "0.ts");
+ const file1 = join(testdata, "opts", "1.ts");
+ const file2 = join(testdata, "opts", "2.ts");
+ const file3 = join(testdata, "opts", "3.md");
+
+ const getSourceCode = async f => decoder.decode(await Deno.readFile(f));
+
+ await run([...cmd, "--no-semi", file0]);
+ assertEquals(
+ normalizeSourceCode(await getSourceCode(file0)),
+ `console.log(0)
+console.log([function foo() {}, function baz() {}, a => {}])
+`
+ );
+
+ await run([...cmd, "--print-width", "30", "--tab-width", "4", file0]);
+ assertEquals(
+ normalizeSourceCode(await getSourceCode(file0)),
+ `console.log(0);
+console.log([
+ function foo() {},
+ function baz() {},
+ a => {}
+]);
+`
+ );
+
+ await run([...cmd, "--print-width", "30", "--use-tabs", file0]);
+ assertEquals(
+ normalizeSourceCode(await getSourceCode(file0)),
+ `console.log(0);
+console.log([
+ function foo() {},
+ function baz() {},
+ a => {}
+]);
+`
+ );
+
+ await run([...cmd, "--single-quote", file1]);
+ assertEquals(
+ normalizeSourceCode(await getSourceCode(file1)),
+ `console.log('1');
+`
+ );
+
+ await run([...cmd, "--print-width", "30", "--trailing-comma", "all", file0]);
+ assertEquals(
+ normalizeSourceCode(await getSourceCode(file0)),
+ `console.log(0);
+console.log([
+ function foo() {},
+ function baz() {},
+ a => {},
+]);
+`
+ );
+
+ await run([...cmd, "--no-bracket-spacing", file2]);
+ assertEquals(
+ normalizeSourceCode(await getSourceCode(file2)),
+ `console.log({a: 1});
+`
+ );
+
+ await run([...cmd, "--arrow-parens", "always", file0]);
+ assertEquals(
+ normalizeSourceCode(await getSourceCode(file0)),
+ `console.log(0);
+console.log([function foo() {}, function baz() {}, (a) => {}]);
+`
+ );
+
+ await run([...cmd, "--prose-wrap", "always", file3]);
+ assertEquals(
+ normalizeSourceCode(await getSourceCode(file3)),
+ `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
+incididunt ut labore et dolore magna aliqua.
+`
+ );
+
+ await run([...cmd, "--end-of-line", "crlf", file2]);
+ assertEquals(await getSourceCode(file2), "console.log({ a: 1 });\r\n");
+
+ await clearTestdataChanges();
+});