From b97c6d29b6a1c66c2596033cd255d6803939aba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sat, 4 Mar 2017 18:26:54 +0100 Subject: test/lua: convert tests to busted infrastructure --- lua/cursor.lua | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 lua/cursor.lua (limited to 'lua/cursor.lua') diff --git a/lua/cursor.lua b/lua/cursor.lua new file mode 100644 index 0000000..06d31a1 --- /dev/null +++ b/lua/cursor.lua @@ -0,0 +1,105 @@ +local busted = require 'busted.runner'() + +local win = vis.win + +-- check that cursor position remains unchanged after an invalid adjustment +local invalid_pos = function(place) + local pos = win.cursor.pos + local line = win.cursor.line + local col = win.cursor.col + win.cursor:to(line, col) + assert.has_error(place) + assert.are.equal(pos, win.cursor.pos) + assert.are.equal(line, win.cursor.line) + assert.are.equal(col, win.cursor.col) +end + +describe("win.cursor", function() + + it("initial position", function() + assert.are.equal(0, win.cursor.pos) + end) + + it("initial line", function() + assert.are.equal(1, win.cursor.line) + end) + + it("initial column", function() + assert.are.equal(1, win.cursor.col) + end) +end) + +describe("win.cursor.pos", function() + + it("= 0", function() + win.cursor.pos = 0 + assert.are.equal(0, win.cursor.pos) + assert.are.equal(1, win.cursor.line) + assert.are.equal(1, win.cursor.col) + end) + + it("= beyond end of file", function() + win.cursor.pos = win.file.size + local pos = win.cursor.pos + local line = win.cursor.line + local col = win.cursor.col + win.cursor.pos = 0 + -- cursor is placed on last valid position + win.cursor.pos = win.file.size+1 + assert.are.equal(pos, win.cursor.pos) + assert.are.equal(line, win.cursor.line) + assert.are.equal(col, win.cursor.col) + end) + +end) + +describe("win.cursor.to", function() + + it("(5, 3)", function() + win.cursor:to(5, 3) + assert.are.equal(30, win.cursor.pos) + assert.are.equal(5, win.cursor.line) + assert.are.equal(3, win.cursor.col) + end) + + it("(0, 0) invalid position", function() + -- is that what we want? + win.cursor:to(0, 0) + assert.are.equal(0, win.cursor.pos) + assert.are.equal(1, win.cursor.line) + assert.are.equal(1, win.cursor.col) + end) + + it("invalid position, negative line", function() + invalid_pos(function() win.cursor:to(-1, 0) end) + end) + + it("invalid position, negative column", function() + invalid_pos(function() win.cursor:to(0, -1) end) + end) + + it("invalid position, non-integer line", function() + invalid_pos(function() win.cursor:to(1.5, 1) end) + end) + + it("invalid position, non-integer column", function() + invalid_pos(function() win.cursor:to(1, 1.5) end) + end) + +--[[ + it("move beyond end of file", function() + win.cursor.pos = win.file.size + local pos = win.cursor.pos + local line = win.cursor.line + local col = win.cursor.col + win.cursor.pos = 0 + -- cursor is placed on last valid position + win.cursor:to(#win.file.lines+2, 1000) + assert.are.equal(pos, win.cursor.pos) + assert.are.equal(line, win.cursor.line) + assert.are.equal(col, win.cursor.col) + end) +--]] + +end) + -- cgit v1.2.3