Skip to content

Commit

Permalink
test/lua: adapt tests to changes in Lua API
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed Jul 13, 2017
1 parent e61362b commit 59be906
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 51 deletions.
100 changes: 50 additions & 50 deletions lua/cursor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,102 +2,102 @@ require 'busted.runner'()

local win = vis.win

-- check that cursor position remains unchanged after an invalid adjustment
-- check that selection 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)
local pos = win.selection.pos
local line = win.selection.line
local col = win.selection.col
win.selection: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)
assert.are.equal(pos, win.selection.pos)
assert.are.equal(line, win.selection.line)
assert.are.equal(col, win.selection.col)
end

describe("win.cursor", function()
describe("win.selection", function()

it("initial position", function()
assert.are.equal(0, win.cursor.pos)
assert.are.equal(0, win.selection.pos)
end)

it("initial line", function()
assert.are.equal(1, win.cursor.line)
assert.are.equal(1, win.selection.line)
end)

it("initial column", function()
assert.are.equal(1, win.cursor.col)
assert.are.equal(1, win.selection.col)
end)
end)

describe("win.cursor.pos", function()
describe("win.selection.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)
win.selection.pos = 0
assert.are.equal(0, win.selection.pos)
assert.are.equal(1, win.selection.line)
assert.are.equal(1, win.selection.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)
win.selection.pos = win.file.size
local pos = win.selection.pos
local line = win.selection.line
local col = win.selection.col
win.selection.pos = 0
-- selection is placed on last valid position
win.selection.pos = win.file.size+1
assert.are.equal(pos, win.selection.pos)
assert.are.equal(line, win.selection.line)
assert.are.equal(col, win.selection.col)
end)

end)

describe("win.cursor.to", function()
describe("win.selection.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)
win.selection:to(5, 3)
assert.are.equal(30, win.selection.pos)
assert.are.equal(5, win.selection.line)
assert.are.equal(3, win.selection.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)
win.selection:to(0, 0)
assert.are.equal(0, win.selection.pos)
assert.are.equal(1, win.selection.line)
assert.are.equal(1, win.selection.col)
end)

it("invalid position, negative line", function()
invalid_pos(function() win.cursor:to(-1, 0) end)
invalid_pos(function() win.selection:to(-1, 0) end)
end)

it("invalid position, negative column", function()
invalid_pos(function() win.cursor:to(0, -1) end)
invalid_pos(function() win.selection:to(0, -1) end)
end)

it("invalid position, non-integer line", function()
invalid_pos(function() win.cursor:to(1.5, 1) end)
invalid_pos(function() win.selection:to(1.5, 1) end)
end)

it("invalid position, non-integer column", function()
invalid_pos(function() win.cursor:to(1, 1.5) end)
invalid_pos(function() win.selection: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)
win.selection.pos = win.file.size
local pos = win.selection.pos
local line = win.selection.line
local col = win.selection.col
win.selection.pos = 0
-- selection is placed on last valid position
win.selection:to(#win.file.lines+2, 1000)
assert.are.equal(pos, win.selection.pos)
assert.are.equal(line, win.selection.line)
assert.are.equal(col, win.selection.col)
end)
--]]

Expand Down
2 changes: 1 addition & 1 deletion lua/map-basic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ local file = win.file
describe("map", function()

before_each(function()
win.cursor.pos = 0
win.selection.pos = 0
end)

after_each(function()
Expand Down

0 comments on commit 59be906

Please sign in to comment.