michael@0: /* vim: set ts=2 et sw=2 tw=80: */ 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: function test() { michael@0: waitForExplicitFinish(); michael@0: setup((ed, win) => { michael@0: var simpleProg = "function foo() {\n let i = 1;\n let j = 2;\n return bar;\n}"; michael@0: ed.setText(simpleProg); michael@0: michael@0: // Move first line up michael@0: ed.setCursor({ line: 0, ch: 0 }); michael@0: ed.moveLineUp(); michael@0: is(ed.getText(0), "function foo() {", "getText(num)"); michael@0: ch(ed.getCursor(), { line: 0, ch: 0 }, "getCursor"); michael@0: michael@0: // Move last line down michael@0: ed.setCursor({ line: 4, ch: 0 }); michael@0: ed.moveLineDown(); michael@0: is(ed.getText(4), "}", "getText(num)"); michael@0: ch(ed.getCursor(), { line: 4, ch: 0 }, "getCursor"); michael@0: michael@0: // Move line 2 up michael@0: ed.setCursor({ line: 1, ch: 5}); michael@0: ed.moveLineUp(); michael@0: is(ed.getText(0), " let i = 1;", "getText(num)"); michael@0: is(ed.getText(1), "function foo() {", "getText(num)"); michael@0: ch(ed.getCursor(), { line: 0, ch: 5 }, "getCursor"); michael@0: michael@0: // Undo previous move by moving line 1 down michael@0: ed.moveLineDown(); michael@0: is(ed.getText(0), "function foo() {", "getText(num)"); michael@0: is(ed.getText(1), " let i = 1;", "getText(num)"); michael@0: ch(ed.getCursor(), { line: 1, ch: 5 }, "getCursor"); michael@0: michael@0: // Move line 2 and 3 up michael@0: ed.setSelection({ line: 1, ch: 0 }, { line: 2, ch: 0 }); michael@0: ed.moveLineUp(); michael@0: is(ed.getText(0), " let i = 1;", "getText(num)"); michael@0: is(ed.getText(1), " let j = 2;", "getText(num)"); michael@0: is(ed.getText(2), "function foo() {", "getText(num)"); michael@0: ch(ed.getCursor("start"), { line: 0, ch: 0 }, "getCursor(string)"); michael@0: ch(ed.getCursor("end"), { line: 1, ch: 0 }, "getCursor(string)"); michael@0: michael@0: // Move line 1 to 3 down twice michael@0: ed.dropSelection(); michael@0: ed.setSelection({ line: 0, ch: 7 }, { line: 2, ch: 5 }); michael@0: ed.moveLineDown(); michael@0: ed.moveLineDown(); michael@0: is(ed.getText(0), " return bar;", "getText(num)"); michael@0: is(ed.getText(1), "}", "getText(num)"); michael@0: is(ed.getText(2), " let i = 1;", "getText(num)"); michael@0: is(ed.getText(3), " let j = 2;", "getText(num)"); michael@0: is(ed.getText(4), "function foo() {", "getText(num)"); michael@0: ch(ed.getCursor("start"), { line: 2, ch: 7 }, "getCursor(string)"); michael@0: ch(ed.getCursor("end"), { line: 4, ch: 5 }, "getCursor(string)"); michael@0: michael@0: teardown(ed, win); michael@0: }); michael@0: }