diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /devtools/client/shared/sourceeditor/test/browser_detectindent.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/shared/sourceeditor/test/browser_detectindent.js')
-rw-r--r-- | devtools/client/shared/sourceeditor/test/browser_detectindent.js | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/devtools/client/shared/sourceeditor/test/browser_detectindent.js b/devtools/client/shared/sourceeditor/test/browser_detectindent.js new file mode 100644 index 0000000000..80f2487417 --- /dev/null +++ b/devtools/client/shared/sourceeditor/test/browser_detectindent.js @@ -0,0 +1,99 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const TWO_SPACES_CODE = [ + "/*", + " * tricky comment block", + " */", + "div {", + " color: red;", + " background: blue;", + "}", + " ", + "span {", + " padding-left: 10px;", + "}", +].join("\n"); + +const FOUR_SPACES_CODE = [ + "var obj = {", + " addNumbers: function() {", + " var x = 5;", + " var y = 18;", + " return x + y;", + " },", + " ", + " /*", + " * Do some stuff to two numbers", + " * ", + " * @param x", + " * @param y", + " * ", + " * @return the result of doing stuff", + " */", + " subtractNumbers: function(x, y) {", + " var x += 7;", + " var y += 18;", + " var result = x - y;", + " result %= 2;", + " }", + "}", +].join("\n"); + +const TABS_CODE = [ + "/*", + " * tricky comment block", + " */", + "div {", + "\tcolor: red;", + "\tbackground: blue;", + "}", + "", + "span {", + "\tpadding-left: 10px;", + "}", +].join("\n"); + +const NONE_CODE = [ + "var x = 0;", + " // stray thing", + "var y = 9;", + " ", + "", +].join("\n"); + +async function test() { + waitForExplicitFinish(); + + const { ed, win } = await setup(); + is(ed.getOption("indentUnit"), 2, "2 spaces before code added"); + is(ed.getOption("indentWithTabs"), false, "spaces is default"); + + ed.setText(NONE_CODE); + is(ed.getOption("indentUnit"), 2, "2 spaces after un-detectable code"); + is( + ed.getOption("indentWithTabs"), + false, + "spaces still set after un-detectable code" + ); + + ed.setText(FOUR_SPACES_CODE); + is(ed.getOption("indentUnit"), 4, "4 spaces detected in 4 space code"); + is(ed.getOption("indentWithTabs"), false, "spaces detected in 4 space code"); + + ed.setText(TWO_SPACES_CODE); + is(ed.getOption("indentUnit"), 2, "2 spaces detected in 2 space code"); + is(ed.getOption("indentWithTabs"), false, "spaces detected in 2 space code"); + + ed.setText(TABS_CODE); + is(ed.getOption("indentUnit"), 2, "2 space indentation unit"); + is( + ed.getOption("indentWithTabs"), + true, + "tabs detected in majority tabs code" + ); + + teardown(ed, win); +} |