diff options
| author | Yoshiya Hinosawa <stibium121@gmail.com> | 2019-03-18 07:23:21 +0900 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2019-03-17 18:23:21 -0400 |
| commit | d1b0a1ef6c9cf0726687402bd12ce9ad4ead8424 (patch) | |
| tree | 2dc34916085c9febcafc44bca028db6b257b6d95 /prettier/main_test.ts | |
| parent | 942df0be0d8bb37862195c438017df7746b0f3f0 (diff) | |
Add prettier styling options (denoland/deno_std#281)
Original: https://github.com/denoland/deno_std/commit/fae48d5dfbbe6267c71a0dc48647548b190dd875
Diffstat (limited to 'prettier/main_test.ts')
| -rw-r--r-- | prettier/main_test.ts | 94 |
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(); +}); |
