browser/devtools/sourceeditor/test/browser_detectindent.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:2d76c9d1d76b
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 "use strict";
5
6
7 const TWO_SPACES_CODE = [
8 "/*",
9 " * tricky comment block",
10 " */",
11 "div {",
12 " color: red;",
13 " background: blue;",
14 "}",
15 " ",
16 "span {",
17 " padding-left: 10px;",
18 "}"
19 ].join("\n");
20
21 const FOUR_SPACES_CODE = [
22 "var obj = {",
23 " addNumbers: function() {",
24 " var x = 5;",
25 " var y = 18;",
26 " return x + y;",
27 " },",
28 " ",
29 " /*",
30 " * Do some stuff to two numbers",
31 " * ",
32 " * @param x",
33 " * @param y",
34 " * ",
35 " * @return the result of doing stuff",
36 " */",
37 " subtractNumbers: function(x, y) {",
38 " var x += 7;",
39 " var y += 18;",
40 " var result = x - y;",
41 " result %= 2;",
42 " }",
43 "}"
44 ].join("\n");
45
46 const TABS_CODE = [
47 "/*",
48 " * tricky comment block",
49 " */",
50 "div {",
51 "\tcolor: red;",
52 "\tbackground: blue;",
53 "}",
54 "",
55 "span {",
56 "\tpadding-left: 10px;",
57 "}"
58 ].join("\n");
59
60 const NONE_CODE = [
61 "var x = 0;",
62 " // stray thing",
63 "var y = 9;",
64 " ",
65 ""
66 ].join("\n");
67
68 function test() {
69 waitForExplicitFinish();
70
71 setup((ed, win) => {
72 is(ed.getOption("indentUnit"), 2,
73 "2 spaces before code added");
74 is(ed.getOption("indentWithTabs"), false,
75 "spaces is default");
76
77 ed.setText(NONE_CODE);
78 is(ed.getOption("indentUnit"), 2,
79 "2 spaces after un-detectable code");
80 is(ed.getOption("indentWithTabs"), false,
81 "spaces still set after un-detectable code");
82
83 ed.setText(FOUR_SPACES_CODE);
84 is(ed.getOption("indentUnit"), 4,
85 "4 spaces detected in 4 space code");
86 is(ed.getOption("indentWithTabs"), false,
87 "spaces detected in 4 space code");
88
89 ed.setText(TWO_SPACES_CODE);
90 is(ed.getOption("indentUnit"), 2,
91 "2 spaces detected in 2 space code");
92 is(ed.getOption("indentWithTabs"), false,
93 "spaces detected in 2 space code");
94
95 ed.setText(TABS_CODE);
96 is(ed.getOption("indentUnit"), 2,
97 "2 space indentation unit");
98 is(ed.getOption("indentWithTabs"), true,
99 "tabs detected in majority tabs code");
100
101 teardown(ed, win);
102 });
103 }

mercurial