aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/test/stub_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'spec/outputs/test/stub_spec.lua')
-rw-r--r--spec/outputs/test/stub_spec.lua148
1 files changed, 148 insertions, 0 deletions
diff --git a/spec/outputs/test/stub_spec.lua b/spec/outputs/test/stub_spec.lua
new file mode 100644
index 0000000..0daf5b6
--- /dev/null
+++ b/spec/outputs/test/stub_spec.lua
@@ -0,0 +1,148 @@
1local stub_fn
2stub_fn = function()
3 return function() end
4end
5local _anon_func_0 = function(stub_fn)
6 stub_fn()
7 return true
8end
9return describe("function stub", function()
10 it("should create empty function", function()
11 stub_fn()
12 return assert.is_true(true)
13 end)
14 it("should support stub in table", function()
15 local obj = {
16 stub = stub_fn()
17 }
18 return assert.is_true(true)
19 end)
20 it("should work with method stub", function()
21 local obj = {
22 method = stub_fn()
23 }
24 return assert.is_true(true)
25 end)
26 it("should handle stub in assignment", function()
27 local my_func = stub_fn()
28 return assert.is_true(true)
29 end)
30 it("should support stub in return", function()
31 local get_stub
32 get_stub = function()
33 return stub_fn()
34 end
35 local fn = get_stub()
36 return assert.is_true(true)
37 end)
38 it("should work in conditional", function()
39 if stub_fn() then
40 return assert.is_true(true)
41 end
42 end)
43 it("should support stub as callback", function()
44 local call_fn
45 call_fn = function(fn)
46 return fn()
47 end
48 local result = call_fn(stub_fn())
49 return assert.is_true(true)
50 end)
51 it("should handle stub in table literal", function()
52 local tb = {
53 on_click = stub_fn(),
54 on_hover = stub_fn()
55 }
56 return assert.is_true(true)
57 end)
58 it("should work with fat arrow stub", function()
59 local obj = {
60 value = 10,
61 method = stub_fn()
62 }
63 local result = obj:method()
64 return assert.is_true(true)
65 end)
66 it("should support stub in array", function()
67 local callbacks = {
68 stub_fn(),
69 stub_fn(),
70 stub_fn()
71 }
72 return assert.same(#callbacks, 3)
73 end)
74 it("should handle stub in expression", function()
75 local result = stub_fn() and true or false
76 return assert.is_true(result)
77 end)
78 it("should work with chained stub calls", function()
79 stub_fn()
80 stub_fn()
81 stub_fn()
82 return assert.is_true(true)
83 end)
84 it("should support stub in comprehension", function()
85 local result
86 do
87 local _accum_0 = { }
88 local _len_0 = 1
89 for i = 1, 3 do
90 _accum_0[_len_0] = stub_fn()
91 _len_0 = _len_0 + 1
92 end
93 result = _accum_0
94 end
95 return assert.same(#result, 3)
96 end)
97 it("should handle stub in switch", function()
98 local value = "test"
99 local result
100 if "test" == value then
101 stub_fn()
102 result = "matched"
103 else
104 result = "not matched"
105 end
106 return assert.same(result, "matched")
107 end)
108 it("should work in with statement", function()
109 local obj = {
110 stub = stub_fn()
111 }
112 obj.stub()
113 return assert.is_true(true)
114 end)
115 it("should support stub as argument default", function()
116 local fn
117 fn = function(callback)
118 if callback == nil then
119 callback = stub_fn()
120 end
121 return callback()
122 end
123 local result = fn()
124 return assert.is_true(true)
125 end)
126 it("should handle stub in varargs", function()
127 local collect
128 collect = function(...)
129 return {
130 ...
131 }
132 end
133 local result = collect(stub_fn(), stub_fn())
134 return assert.same(#result, 2)
135 end)
136 it("should work in do block", function()
137 do
138 stub_fn()
139 end
140 return assert.is_true(true)
141 end)
142 return it("should support stub in try block", function()
143 local success = xpcall(_anon_func_0, function(err)
144 return false
145 end, stub_fn)
146 return assert.is_true(success)
147 end)
148end)