Add busted tests
This commit is contained in:
parent
b88cc3a85e
commit
ce6b85a5e7
|
@ -2,3 +2,4 @@
|
|||
*.nix
|
||||
*.lua
|
||||
!*tlconfig.lua
|
||||
!*tests.lua
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
local istream = require("InputStream")
|
||||
local ds = require("DataStructures")
|
||||
local Stack, Dictionary, WordInfo, Environment = ds.Stack, ds.Dictionary, ds.WordInfo, ds.Environment
|
||||
|
||||
|
||||
function pushThree(s)
|
||||
s:push(1)
|
||||
s:push(2)
|
||||
s:push(3)
|
||||
end
|
||||
|
||||
|
||||
describe("Stack Tests", function()
|
||||
local stack = Stack:new()
|
||||
it("fails on stack underflow", function()
|
||||
stack = Stack:new()
|
||||
assert.has.errors(function()
|
||||
stack:pop()
|
||||
end)
|
||||
end)
|
||||
it("pushes three items properly", function()
|
||||
stack = Stack:new()
|
||||
pushThree(stack)
|
||||
assert.are.same(stack.contents, {1,2,3})
|
||||
end)
|
||||
it("pops three items properly", function()
|
||||
stack = Stack:new()
|
||||
pushThree(stack)
|
||||
assert.are.same(stack.contents, {1,2,3})
|
||||
assert(3 == stack:pop())
|
||||
assert.are.same(stack.contents, {1,2})
|
||||
assert(2 == stack:pop())
|
||||
assert.are.same(stack.contents, {1})
|
||||
assert(1 == stack:pop())
|
||||
assert.are.same(stack.contents, {})
|
||||
assert.has.errors(function()
|
||||
stack:pop()
|
||||
end)
|
||||
end)
|
||||
it("PUSH 1, 2, 3, POP = 3, PUSH 4 = {1,2,4}", function()
|
||||
stack = Stack:new()
|
||||
pushThree(stack)
|
||||
assert(3 == stack:pop())
|
||||
assert.are.same(stack.contents, {1, 2})
|
||||
stack:push(4)
|
||||
assert.are.same(stack.contents, {1, 2, 4})
|
||||
end)
|
||||
end)
|
||||
|
||||
local function dummyInput()
|
||||
return "1234567890"
|
||||
end
|
||||
describe("InputStream tests", function()
|
||||
local input = istream:new(dummyInput)
|
||||
it("gets a new refill accurately", function()
|
||||
input = istream:new()
|
||||
input:setRefill(dummyInput)
|
||||
assert.are.equal(input.refill, dummyInput)
|
||||
end)
|
||||
it("reads text properly", function()
|
||||
input = istream:new(dummyInput)
|
||||
input:setRefill(dummyInput)
|
||||
local inputString = dummyInput()
|
||||
for i = 0, 100 do
|
||||
local j = i % #inputString + 1
|
||||
assert.are.same(inputString:sub(j, j), input:advanceOffset())
|
||||
end
|
||||
end)
|
||||
end)
|
||||
describe("WordInfo tests", function()
|
||||
local Environment = ds.Environment
|
||||
local WordInfo = ds.WordInfo
|
||||
it("creates and doesn't crash", function()
|
||||
local env = Environment:new()
|
||||
wi = WordInfo:new(function(env) end, false)
|
||||
end)
|
||||
end)
|
||||
|
||||
|
||||
describe("Dictionary tests", function()
|
||||
local Dictionary = ds.Dictionary
|
||||
local WordInfo = ds.WordInfo
|
||||
local Environment = ds.Environment
|
||||
it("defines without breaking",function()
|
||||
local env = Environment:new()
|
||||
local dict = Dictionary:new()
|
||||
local wi = WordInfo:new(function(env) end, false)
|
||||
|
||||
dict:define("TEST",wi)
|
||||
end)
|
||||
end)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue