1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/sourceeditor/test/browser_editor_movelines.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,62 @@ 1.4 +/* vim: set ts=2 et sw=2 tw=80: */ 1.5 +/* Any copyright is dedicated to the Public Domain. 1.6 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +function test() { 1.11 + waitForExplicitFinish(); 1.12 + setup((ed, win) => { 1.13 + var simpleProg = "function foo() {\n let i = 1;\n let j = 2;\n return bar;\n}"; 1.14 + ed.setText(simpleProg); 1.15 + 1.16 + // Move first line up 1.17 + ed.setCursor({ line: 0, ch: 0 }); 1.18 + ed.moveLineUp(); 1.19 + is(ed.getText(0), "function foo() {", "getText(num)"); 1.20 + ch(ed.getCursor(), { line: 0, ch: 0 }, "getCursor"); 1.21 + 1.22 + // Move last line down 1.23 + ed.setCursor({ line: 4, ch: 0 }); 1.24 + ed.moveLineDown(); 1.25 + is(ed.getText(4), "}", "getText(num)"); 1.26 + ch(ed.getCursor(), { line: 4, ch: 0 }, "getCursor"); 1.27 + 1.28 + // Move line 2 up 1.29 + ed.setCursor({ line: 1, ch: 5}); 1.30 + ed.moveLineUp(); 1.31 + is(ed.getText(0), " let i = 1;", "getText(num)"); 1.32 + is(ed.getText(1), "function foo() {", "getText(num)"); 1.33 + ch(ed.getCursor(), { line: 0, ch: 5 }, "getCursor"); 1.34 + 1.35 + // Undo previous move by moving line 1 down 1.36 + ed.moveLineDown(); 1.37 + is(ed.getText(0), "function foo() {", "getText(num)"); 1.38 + is(ed.getText(1), " let i = 1;", "getText(num)"); 1.39 + ch(ed.getCursor(), { line: 1, ch: 5 }, "getCursor"); 1.40 + 1.41 + // Move line 2 and 3 up 1.42 + ed.setSelection({ line: 1, ch: 0 }, { line: 2, ch: 0 }); 1.43 + ed.moveLineUp(); 1.44 + is(ed.getText(0), " let i = 1;", "getText(num)"); 1.45 + is(ed.getText(1), " let j = 2;", "getText(num)"); 1.46 + is(ed.getText(2), "function foo() {", "getText(num)"); 1.47 + ch(ed.getCursor("start"), { line: 0, ch: 0 }, "getCursor(string)"); 1.48 + ch(ed.getCursor("end"), { line: 1, ch: 0 }, "getCursor(string)"); 1.49 + 1.50 + // Move line 1 to 3 down twice 1.51 + ed.dropSelection(); 1.52 + ed.setSelection({ line: 0, ch: 7 }, { line: 2, ch: 5 }); 1.53 + ed.moveLineDown(); 1.54 + ed.moveLineDown(); 1.55 + is(ed.getText(0), " return bar;", "getText(num)"); 1.56 + is(ed.getText(1), "}", "getText(num)"); 1.57 + is(ed.getText(2), " let i = 1;", "getText(num)"); 1.58 + is(ed.getText(3), " let j = 2;", "getText(num)"); 1.59 + is(ed.getText(4), "function foo() {", "getText(num)"); 1.60 + ch(ed.getCursor("start"), { line: 2, ch: 7 }, "getCursor(string)"); 1.61 + ch(ed.getCursor("end"), { line: 4, ch: 5 }, "getCursor(string)"); 1.62 + 1.63 + teardown(ed, win); 1.64 + }); 1.65 +}