summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/xpcshell/test_format_command.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /devtools/server/tests/xpcshell/test_format_command.js
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/server/tests/xpcshell/test_format_command.js')
-rw-r--r--devtools/server/tests/xpcshell/test_format_command.js111
1 files changed, 111 insertions, 0 deletions
diff --git a/devtools/server/tests/xpcshell/test_format_command.js b/devtools/server/tests/xpcshell/test_format_command.js
new file mode 100644
index 0000000000..529e560a0f
--- /dev/null
+++ b/devtools/server/tests/xpcshell/test_format_command.js
@@ -0,0 +1,111 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const {
+ formatCommand,
+} = require("resource://devtools/server/actors/webconsole/commands/parser.js");
+
+const testcases = [
+ { input: ":help", expectedOutput: "help()" },
+ {
+ input: ":screenshot --fullscreen",
+ expectedOutput: 'screenshot({"fullscreen":true})',
+ },
+ {
+ input: ":screenshot --fullscreen true",
+ expectedOutput: 'screenshot({"fullscreen":true})',
+ },
+ { input: ":screenshot ", expectedOutput: "screenshot()" },
+ {
+ input: ":screenshot --dpr 0.5 --fullpage --chrome",
+ expectedOutput: 'screenshot({"dpr":0.5,"fullpage":true,"chrome":true})',
+ },
+ {
+ input: ":screenshot 'filename'",
+ expectedOutput: 'screenshot({"filename":"filename"})',
+ },
+ {
+ input: ":screenshot filename",
+ expectedOutput: 'screenshot({"filename":"filename"})',
+ },
+ {
+ input:
+ ":screenshot --name 'filename' --name `filename` --name \"filename\"",
+ expectedOutput: 'screenshot({"name":["filename","filename","filename"]})',
+ },
+ {
+ input: ":screenshot 'filename1' 'filename2' 'filename3'",
+ expectedOutput: 'screenshot({"filename":"filename1"})',
+ },
+ {
+ input: ":screenshot --chrome --chrome",
+ expectedOutput: 'screenshot({"chrome":true})',
+ },
+ {
+ input: ':screenshot "file name with spaces"',
+ expectedOutput: 'screenshot({"filename":"file name with spaces"})',
+ },
+ {
+ input: ":screenshot 'filename1' --name 'filename2'",
+ expectedOutput: 'screenshot({"filename":"filename1","name":"filename2"})',
+ },
+ {
+ input: ":screenshot --name 'filename1' 'filename2'",
+ expectedOutput: 'screenshot({"name":"filename1","filename":"filename2"})',
+ },
+ {
+ input: ':screenshot "fo\\"o bar"',
+ expectedOutput: 'screenshot({"filename":"fo\\\\\\"o bar"})',
+ },
+ {
+ input: ':screenshot "foo b\\"ar"',
+ expectedOutput: 'screenshot({"filename":"foo b\\\\\\"ar"})',
+ },
+];
+
+const edgecases = [
+ { input: ":", expectedError: /'' is not a valid command/ },
+ { input: ":invalid", expectedError: /'invalid' is not a valid command/ },
+ { input: ":screenshot :help", expectedError: /Invalid command/ },
+ { input: ":screenshot --", expectedError: /invalid flag/ },
+ {
+ input: ':screenshot "fo"o bar',
+ expectedError:
+ /String has unescaped `"` in \["fo"o\.\.\.\], may miss a space between arguments/,
+ },
+ {
+ input: ':screenshot "foo b"ar',
+ expectedError:
+ // eslint-disable-next-line max-len
+ /String has unescaped `"` in \["foo b"ar\.\.\.\], may miss a space between arguments/,
+ },
+ { input: ": screenshot", expectedError: /'' is not a valid command/ },
+ {
+ input: ':screenshot "file name',
+ expectedError: /String does not terminate/,
+ },
+ {
+ input: ':screenshot "file name --clipboard',
+ expectedError: /String does not terminate before flag "clipboard"/,
+ },
+ {
+ input: "::screenshot",
+ expectedError: /':screenshot' is not a valid command/,
+ },
+];
+
+function run_test() {
+ testcases.forEach(testcase => {
+ Assert.equal(formatCommand(testcase.input), testcase.expectedOutput);
+ });
+
+ edgecases.forEach(testcase => {
+ Assert.throws(
+ () => formatCommand(testcase.input),
+ testcase.expectedError,
+ `"${testcase.input}" should throw expected error`
+ );
+ });
+}