browser/devtools/sourceeditor/test/browser_detectindent.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/sourceeditor/test/browser_detectindent.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,103 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +"use strict";
     1.8 +
     1.9 +
    1.10 +const TWO_SPACES_CODE = [
    1.11 +"/*",
    1.12 +" * tricky comment block",
    1.13 +" */",
    1.14 +"div {",
    1.15 +"  color: red;",
    1.16 +"  background: blue;",
    1.17 +"}",
    1.18 +"     ",
    1.19 +"span {",
    1.20 +"  padding-left: 10px;",
    1.21 +"}"
    1.22 +].join("\n");
    1.23 +
    1.24 +const FOUR_SPACES_CODE = [
    1.25 +"var obj = {",
    1.26 +"    addNumbers: function() {",
    1.27 +"        var x = 5;",
    1.28 +"        var y = 18;",
    1.29 +"        return x + y;",
    1.30 +"    },",
    1.31 +"   ",
    1.32 +"    /*",
    1.33 +"     * Do some stuff to two numbers",
    1.34 +"     * ",
    1.35 +"     * @param x",
    1.36 +"     * @param y",
    1.37 +"     * ",
    1.38 +"     * @return the result of doing stuff",
    1.39 +"     */",
    1.40 +"    subtractNumbers: function(x, y) {",
    1.41 +"        var x += 7;",
    1.42 +"        var y += 18;",
    1.43 +"        var result = x - y;",
    1.44 +"        result %= 2;",
    1.45 +"    }",
    1.46 +"}"
    1.47 +].join("\n");
    1.48 +
    1.49 +const TABS_CODE = [
    1.50 +"/*",
    1.51 +" * tricky comment block",
    1.52 +" */",
    1.53 +"div {",
    1.54 +"\tcolor: red;",
    1.55 +"\tbackground: blue;",
    1.56 +"}",
    1.57 +"",
    1.58 +"span {",
    1.59 +"\tpadding-left: 10px;",
    1.60 +"}"
    1.61 +].join("\n");
    1.62 +
    1.63 +const NONE_CODE = [
    1.64 +"var x = 0;",
    1.65 +"           // stray thing",
    1.66 +"var y = 9;",
    1.67 +"    ",
    1.68 +""
    1.69 +].join("\n");
    1.70 +
    1.71 +function test() {
    1.72 +  waitForExplicitFinish();
    1.73 +
    1.74 +  setup((ed, win) => {
    1.75 +    is(ed.getOption("indentUnit"), 2,
    1.76 +       "2 spaces before code added");
    1.77 +    is(ed.getOption("indentWithTabs"), false,
    1.78 +       "spaces is default");
    1.79 +
    1.80 +    ed.setText(NONE_CODE);
    1.81 +    is(ed.getOption("indentUnit"), 2,
    1.82 +       "2 spaces after un-detectable code");
    1.83 +    is(ed.getOption("indentWithTabs"), false,
    1.84 +       "spaces still set after un-detectable code");
    1.85 +
    1.86 +    ed.setText(FOUR_SPACES_CODE);
    1.87 +    is(ed.getOption("indentUnit"), 4,
    1.88 +       "4 spaces detected in 4 space code");
    1.89 +    is(ed.getOption("indentWithTabs"), false,
    1.90 +       "spaces detected in 4 space code");
    1.91 +
    1.92 +    ed.setText(TWO_SPACES_CODE);
    1.93 +    is(ed.getOption("indentUnit"), 2,
    1.94 +       "2 spaces detected in 2 space code");
    1.95 +    is(ed.getOption("indentWithTabs"), false,
    1.96 +       "spaces detected in 2 space code");
    1.97 +
    1.98 +    ed.setText(TABS_CODE);
    1.99 +    is(ed.getOption("indentUnit"), 2,
   1.100 +       "2 space indentation unit");
   1.101 +    is(ed.getOption("indentWithTabs"), true,
   1.102 +       "tabs detected in majority tabs code");
   1.103 +
   1.104 +    teardown(ed, win);
   1.105 +  });
   1.106 +}

mercurial