1
0
Fork 0
mirror of https://github.com/Oreolek/ink-instead.git synced 2024-07-04 23:54:44 +03:00
ink-instead/test/test.lua

99 lines
2.9 KiB
Lua
Raw Normal View History

2017-01-25 23:09:32 +02:00
local luaunit = require('test.luaunit')
local parser = require('pink.parser')
2017-01-22 01:02:26 +02:00
local runtime = require('pink.runtime')
2016-12-31 01:27:11 +02:00
local pink = require('pink.pink')
2016-11-30 17:11:57 +02:00
2017-01-22 01:02:26 +02:00
--- parser ---
2016-11-30 17:11:57 +02:00
function testEmpt() doTestS(
"",
{}
) end
2016-12-03 01:08:14 +02:00
function testText() doTestS(
"Hello world",
{{"para", "Hello world"}}
) end
2016-12-04 02:38:27 +02:00
2016-12-03 01:08:14 +02:00
function testBasic() doTest('basic') end
2017-08-09 12:36:14 +03:00
function testComments() doTest('comments') end
2016-12-03 01:08:14 +02:00
function testChoices() doTest('choices') end
2016-12-04 02:38:27 +02:00
function testNest() doTest('nested') end
function testNest2() doTest('nested2') end
function testKnot() doTest('knot') end
2016-12-04 02:54:34 +02:00
function testBranching() doTest('branching') end
2016-12-04 03:47:33 +02:00
function testGlue() doTest('glue') end
2017-01-22 01:02:26 +02:00
function testInclude() doTest('include') end
2017-08-09 12:36:14 +03:00
function testTagsP() doTest('tags') end
2016-11-30 17:11:57 +02:00
2017-01-22 01:02:26 +02:00
--- runtime ---
2017-08-09 15:07:49 +03:00
function testBasicR()
local story = pink.getStory('test/runtime/hello.ink')
luaunit.assertEquals(story.continue(), 'hello world')
luaunit.assertFalse(story.canContinue)
end
2016-12-31 01:27:11 +02:00
function testVisitCount()
2017-01-22 01:02:26 +02:00
local story = pink.getStory('test/runtime/branching.ink')
2016-12-31 01:27:11 +02:00
story.choosePathString('hurry_outside');
luaunit.assertEquals(story.state.visitCountAtPathString('as_fast_as_we_could'), 0)
while story.canContinue do story.continue() end
luaunit.assertEquals(story.state.visitCountAtPathString('as_fast_as_we_could'), 1)
story.choosePathString('hurry_outside');
while story.canContinue do story.continue() end
luaunit.assertEquals(story.state.visitCountAtPathString('as_fast_as_we_could'), 2)
luaunit.assertEquals(story.state.visitCountAtPathString('as_fast_as_we_could'), 2)
end
2017-01-22 01:02:26 +02:00
function testIncludeR()
local story = pink.getStory('test/runtime/include.ink')
luaunit.assertEquals(story.continue(), 'hello world')
luaunit.assertEquals(story.continue(), 'hello again')
luaunit.assertFalse(story.canContinue)
end
2017-02-28 17:48:56 +02:00
function testTags()
local story = pink.getStory('test/runtime/tags.ink')
luaunit.assertEquals(story.continue(), '')
luaunit.assertEquals(story.continue(), '')
luaunit.assertEquals(story.globalTags, {""})
luaunit.assertFalse(story.canContinue)
end
function testInvisibleDiverts()
local story = pink.getStory('test/runtime/branching.ink')
story.choosePathString('hurry_outside')
luaunit.assertEquals(story.continue(), "We hurried home to Savile Row as fast as we could.")
end
2016-12-31 01:27:11 +02:00
-- TODO test runtime more, test public pink API
2016-11-30 17:11:57 +02:00
2017-01-22 01:21:12 +02:00
function testCLI()
-- note the different suffixes
os.execute("lua pink/pink.lua parse test/runtime/include.ink > tmp_test.lua")
local story = pink.getStory('tmp_test.ink')
luaunit.assertEquals(story.continue(), 'hello world')
luaunit.assertEquals(story.continue(), 'hello again')
luaunit.assertFalse(story.canContinue)
os.remove('tmp_test.lua')
end
2016-11-30 17:11:57 +02:00
-----------------------------
function doTestS(ink, expected)
luaunit.assertEquals(parser:match(ink), expected)
end
function doTest(name)
2017-01-22 01:02:26 +02:00
local test = require ('test.parser.'..name)
2016-11-30 17:11:57 +02:00
local parsed = parser:match(test.ink)
luaunit.assertEquals(parsed, test.expected)
end
os.exit( luaunit.LuaUnit.run() )