/
context_spec.lua
executable file
·55 lines (43 loc) · 1.61 KB
/
context_spec.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package.path = "../src/?.lua"
local lustache = require "lustache" -- only needed to set string.split
local topic = function()
local view = { name = 'parent', message = 'hi', a = { b = 'b' } }
local context = require("lustache.context"):new(view)
return context, view
end
local push = function(context)
local child_view = { name = 'child', c = { d = 'd' } }
return context:push(child_view), child_view
end
describe("context specs", function()
local context, view = topic()
before_each(function()
context, view = topic()
end)
it("looks up contexts", function()
assert.equal(context:lookup("name"), view.name)
end)
it("looks up nested contexts", function()
assert.equal(context:lookup("a.b"), view.a.b)
end)
it("looks up child contexts", function()
local child_context, child_view = push(context)
assert.equal(child_context.view.name, child_view.name)
end)
it("looks up child context view properties", function()
local child_context, child_view = push(context)
assert.equal(child_context:lookup("name"), child_view.name)
end)
it("looks up child context parent view properties", function()
local child_context, child_view = push(context)
assert.equal(child_context:lookup("message"), view.message)
end)
it("looks up child context nested view properties", function()
local child_context, child_view = push(context)
assert.equal(child_context:lookup("c.d"), "d")
end)
it("looks up child context parent nested view properties", function()
local child_context, child_view = push(context)
assert.equal(child_context:lookup("a.b"), "b")
end)
end)