From 208eaad44eefb4585160e6597d11048a9d64a8fd Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Mon, 4 May 2020 18:27:15 +0800 Subject: [PATCH] Test empty files with `snippets` (#8116) * Test empty files with `snippets` * Assert output --- tests/empty/__snapshots__/jsfmt.spec.js.snap | 52 -------------------- tests/empty/empty | 0 tests/empty/jsfmt.spec.js | 45 ++++++++++++++--- tests/empty/newline | 1 - tests/empty/space | 1 - tests/empty/space-newline | 1 - 6 files changed, 38 insertions(+), 62 deletions(-) delete mode 100644 tests/empty/__snapshots__/jsfmt.spec.js.snap delete mode 100644 tests/empty/empty delete mode 100644 tests/empty/newline delete mode 100644 tests/empty/space delete mode 100644 tests/empty/space-newline diff --git a/tests/empty/__snapshots__/jsfmt.spec.js.snap b/tests/empty/__snapshots__/jsfmt.spec.js.snap deleted file mode 100644 index 6f0724cdf..000000000 --- a/tests/empty/__snapshots__/jsfmt.spec.js.snap +++ /dev/null @@ -1,52 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`empty format 1`] = ` -====================================options===================================== -parsers: ["flow", "babel", "babel-flow", "babel-ts", "typescript", "css", "less", "scss", "json", "json5", "json-stringify", "graphql", "markdown", "mdx", "vue", "yaml", "html", "angular", "lwc"] -printWidth: 80 - | printWidth -=====================================input====================================== - -=====================================output===================================== - -================================================================================ -`; - -exports[`newline format 1`] = ` -====================================options===================================== -parsers: ["flow", "babel", "babel-flow", "babel-ts", "typescript", "css", "less", "scss", "json", "json5", "json-stringify", "graphql", "markdown", "mdx", "vue", "yaml", "html", "angular", "lwc"] -printWidth: 80 - | printWidth -=====================================input====================================== - - -=====================================output===================================== - -================================================================================ -`; - -exports[`space format 1`] = ` -====================================options===================================== -parsers: ["flow", "babel", "babel-flow", "babel-ts", "typescript", "css", "less", "scss", "json", "json5", "json-stringify", "graphql", "markdown", "mdx", "vue", "yaml", "html", "angular", "lwc"] -printWidth: 80 - | printWidth -=====================================input====================================== - - -=====================================output===================================== - -================================================================================ -`; - -exports[`space-newline format 1`] = ` -====================================options===================================== -parsers: ["flow", "babel", "babel-flow", "babel-ts", "typescript", "css", "less", "scss", "json", "json5", "json-stringify", "graphql", "markdown", "mdx", "vue", "yaml", "html", "angular", "lwc"] -printWidth: 80 - | printWidth -=====================================input====================================== - - -=====================================output===================================== - -================================================================================ -`; diff --git a/tests/empty/empty b/tests/empty/empty deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/empty/jsfmt.spec.js b/tests/empty/jsfmt.spec.js index 58c7c013f..4412971c2 100644 --- a/tests/empty/jsfmt.spec.js +++ b/tests/empty/jsfmt.spec.js @@ -1,11 +1,42 @@ -const prettier = require("prettier/local"); -const parsers = prettier +const parsers = require("prettier/local") .getSupportInfo() - .options.find((option) => option.name === "parser"); + .options.find((option) => option.name === "parser") + .choices.filter((choice) => !choice.deprecated) + .map((choice) => choice.value); run_spec( - __dirname, - parsers.choices - .filter((choice) => !choice.deprecated) - .map((choice) => choice.value) + { + dirname: __dirname, + snippets: [ + // empty + "", + // space + " ", + " ", + // `\n` + "\n", + " \n", + " \n ", + "\n\n\n\n", + " \n \n \n\n", + " \n \n \n\n ", + // `\r` + "\r", + " \r", + " \r ", + "\r\r\r\r", + " \r \r \r\r", + " \r \r \r\r ", + // `\r\n` + "\r\n", + " \r\n", + " \r\n ", + "\r\n\r\n\r\n\r\n", + " \r\n \r\n \r\n\r\n", + " \r\n \r\n \r\n\r\n ", + // mixed `\r` `\r\n` '\n' + " \r \r\n \n ", + ].map((code) => ({ code, output: "" })), + }, + parsers ); diff --git a/tests/empty/newline b/tests/empty/newline deleted file mode 100644 index 8b1378917..000000000 --- a/tests/empty/newline +++ /dev/null @@ -1 +0,0 @@ - diff --git a/tests/empty/space b/tests/empty/space deleted file mode 100644 index 8d1c8b69c..000000000 --- a/tests/empty/space +++ /dev/null @@ -1 +0,0 @@ - diff --git a/tests/empty/space-newline b/tests/empty/space-newline deleted file mode 100644 index 8d1c8b69c..000000000 --- a/tests/empty/space-newline +++ /dev/null @@ -1 +0,0 @@ -