1
0
Fork 0
mirror of https://github.com/Oreolek/ink-instead.git synced 2024-06-16 15:10:48 +03:00

glue test

This commit is contained in:
premek 2016-12-04 02:47:33 +01:00
parent f978875905
commit 29b40f7a96
6 changed files with 70 additions and 17 deletions

View file

@ -6,18 +6,21 @@ We arrived into London at 9.45pm exactly.
-> hurry_outside
* "Monsieur, let us savour this moment!"[] I declared.
My master clouted me firmly around the head and dragged me out of the door.
My master clouted me firmly around the head
** A
**B
and dragged me out of the door. <>
-> dragged_outside
* [We hurried home] -> hurry_outside
=== hurry_outside ===
We hurried home to Savile Row -> as_fast_as_we_could
We hurried home to Savile Row -> as_fast_as_we_could
=== dragged_outside ===
He insisted that we hurried home to Savile Row
He insisted that we hurried <> home to Savile Row
-> as_fast_as_we_could

View file

@ -22,7 +22,7 @@ local commOL = sp * '//' * sp * (1-nl)^0 * wh
local commML = sp * '/*' * wh * (P(1)-'*/')^0 * '*/' * wh
local comm = commOL + commML + todo
local glue = P'<>'/'glue' *wh
local glue = P'<>'/'glue' *wh -- FIXME do not consume spaces after glue
local divertSym = '->' *wh
local divertEndSym = C('END') *wh

View file

@ -1,25 +1,26 @@
require('util') -- XXX
local is = function (what, node)
return node ~= nil and type(node) == "table" and node[1] == what
return node ~= nil
and (type(node) == "table" and node[1] == what)
or (type(node) == "string" and node == what)
end
local getPara = function (node)
if is('para', node) then return node[2] end
end
return function (tree)
print(to_string(tree))
--print(to_string(tree))
local s = {}
local pointer = 1
local tab = tree
local pointer = nil
local tab = {}
local knots = {}
local process = function ()
for i, v in ipairs(tree) do
for _, v in ipairs(tree) do
if is('knot', v) then
knots[v[2]] = v
end
@ -55,12 +56,31 @@ return function (tree)
end
end
local step = function ()
pointer = pointer + 1
update()
return tab[pointer]
end
local stepTo = function (table, pos)
tab = table
pointer = pos
update()
return tab[pointer]
end
s.canContinue = nil
s.continue = function()
local res = getPara(tab[pointer])
pointer = pointer + 1
update()
local next = step()
if is('glue', next) then
step()
res = res .. s.continue()
end
return res;
end
@ -70,16 +90,14 @@ return function (tree)
s.currentChoices = {}
local choice = tab[pointer]
local option = choice[1 + index]
tab = option
pointer = 5
update()
stepTo(option, 5)
end
s.choosePathString = function(knotName) end
s.variablesState = {}
-- s.state.ToJson();s.state.LoadJson(savedJson);
update()
stepTo(tree, 1)
process()
return s
end

View file

@ -24,6 +24,7 @@ function testNest() doTest('nested') end
function testNest2() doTest('nested2') end
function testKnot() doTest('knot') end
function testBranching() doTest('branching') end
function testGlue() doTest('glue') end

View file

@ -8,7 +8,7 @@ We arrived into London at 9.45pm exactly.
-> hurry_outside
* "Monsieur, let us savour this moment!"[] I declared.
My master clouted me firmly around the head and dragged me out of the door.
My master clouted me firmly around the head and dragged me out of the door.<>
-> dragged_outside
* [We hurried home] -> hurry_outside
@ -49,6 +49,7 @@ expected= {
"para",
"My master clouted me firmly around the head and dragged me out of the door."
},
'glue',
{"divert", "dragged_outside"}
},
{"option", "", "We hurried home", " ", {"divert", "hurry_outside"}}

30
test/glue.lua Normal file
View file

@ -0,0 +1,30 @@
return {
ink=[[
* "Monsieur, let us savour this moment!"[] I declared.
My master clouted me firmly around the head and dragged me out of the door. <>
-> dragged_outside
* [We hurried home] -> hurry_outside
=== as_fast_as_we_could ===
<> as fast as we could.
]],
expected={
{
"choice",
{
"option",
'"Monsieur, let us savour this moment!"',
"",
" I declared.",
{
"para",
"My master clouted me firmly around the head and dragged me out of the door. "
},
"glue",
{"divert", "dragged_outside"}
},
{"option", "", "We hurried home", " ", {"divert", "hurry_outside"}}
},
{"knot", "as_fast_as_we_could", "glue", {"para", "as fast as we could."}} -- TODO should be space before 'as'
}
}