This repository has been archived by the owner on Mar 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathfunctions_spec.rb
119 lines (87 loc) · 1.91 KB
/
functions_spec.rb
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#
# Specifying rufus-lua
#
# Wed Mar 11 17:09:17 JST 2009
#
require 'spec_base'
describe Rufus::Lua::State do
describe 'Lua functions' do
before do
@s = Rufus::Lua::State.new
end
after do
@s.close
end
it 'are returned as Rufus::Lua::Function instances' do
expect(@s.eval('return function () end').class).to eq Rufus::Lua::Function
end
it 'are callable from Ruby' do
f = @s.eval(%{
f = function ()
return 77
end
return f
})
expect(f.call()).to eq 77.0
end
it 'are callable even when they return multiple values' do
f = @s.eval(%{
f = function ()
return 77, 44
end
return f
})
expect(f.call()).to eq [ 77.0, 44.0 ]
end
it 'are callable with arguments' do
f = @s.eval(%{
f = function (x)
return x * x
end
return f
})
expect(f.call(2)).to eq 4.0
end
it 'are callable with boolean arguments' do
f = @s.eval(%{
f = function (x)
return x
end
return f
})
expect(f.call(true)).to eq true
expect(f.call(false)).to eq false
end
it 'are callable with array arguments' do
f = @s.eval(%{
f = function (x)
return x
end
return f
})
expect(f.call(%w[ one two three ]).to_a).to eq %w[ one two three ]
end
it 'are callable with multiple arguments' do
f = @s.eval(%{
f = function (x, y)
return x + y
end
return f
})
expect(f.call(1, 2)).to eq 3.0
end
it 'are called with #to_lua\'ed Ruby arguments' do
f = @s.eval(%{
f = function (x)
return x
end
return f
})
t = Time.now
def t.to_lua
"lua:#{to_s}"
end
expect(f.call(t)).to eq t.to_lua
end
end
end