michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: michael@0: const TWO_SPACES_CODE = [ michael@0: "/*", michael@0: " * tricky comment block", michael@0: " */", michael@0: "div {", michael@0: " color: red;", michael@0: " background: blue;", michael@0: "}", michael@0: " ", michael@0: "span {", michael@0: " padding-left: 10px;", michael@0: "}" michael@0: ].join("\n"); michael@0: michael@0: const FOUR_SPACES_CODE = [ michael@0: "var obj = {", michael@0: " addNumbers: function() {", michael@0: " var x = 5;", michael@0: " var y = 18;", michael@0: " return x + y;", michael@0: " },", michael@0: " ", michael@0: " /*", michael@0: " * Do some stuff to two numbers", michael@0: " * ", michael@0: " * @param x", michael@0: " * @param y", michael@0: " * ", michael@0: " * @return the result of doing stuff", michael@0: " */", michael@0: " subtractNumbers: function(x, y) {", michael@0: " var x += 7;", michael@0: " var y += 18;", michael@0: " var result = x - y;", michael@0: " result %= 2;", michael@0: " }", michael@0: "}" michael@0: ].join("\n"); michael@0: michael@0: const TABS_CODE = [ michael@0: "/*", michael@0: " * tricky comment block", michael@0: " */", michael@0: "div {", michael@0: "\tcolor: red;", michael@0: "\tbackground: blue;", michael@0: "}", michael@0: "", michael@0: "span {", michael@0: "\tpadding-left: 10px;", michael@0: "}" michael@0: ].join("\n"); michael@0: michael@0: const NONE_CODE = [ michael@0: "var x = 0;", michael@0: " // stray thing", michael@0: "var y = 9;", michael@0: " ", michael@0: "" michael@0: ].join("\n"); michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: setup((ed, win) => { michael@0: is(ed.getOption("indentUnit"), 2, michael@0: "2 spaces before code added"); michael@0: is(ed.getOption("indentWithTabs"), false, michael@0: "spaces is default"); michael@0: michael@0: ed.setText(NONE_CODE); michael@0: is(ed.getOption("indentUnit"), 2, michael@0: "2 spaces after un-detectable code"); michael@0: is(ed.getOption("indentWithTabs"), false, michael@0: "spaces still set after un-detectable code"); michael@0: michael@0: ed.setText(FOUR_SPACES_CODE); michael@0: is(ed.getOption("indentUnit"), 4, michael@0: "4 spaces detected in 4 space code"); michael@0: is(ed.getOption("indentWithTabs"), false, michael@0: "spaces detected in 4 space code"); michael@0: michael@0: ed.setText(TWO_SPACES_CODE); michael@0: is(ed.getOption("indentUnit"), 2, michael@0: "2 spaces detected in 2 space code"); michael@0: is(ed.getOption("indentWithTabs"), false, michael@0: "spaces detected in 2 space code"); michael@0: michael@0: ed.setText(TABS_CODE); michael@0: is(ed.getOption("indentUnit"), 2, michael@0: "2 space indentation unit"); michael@0: is(ed.getOption("indentWithTabs"), true, michael@0: "tabs detected in majority tabs code"); michael@0: michael@0: teardown(ed, win); michael@0: }); michael@0: }