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 pathstate_spec.rb
106 lines (71 loc) · 2.06 KB
/
state_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
#
# Specifying rufus-lua
#
# Mon Mar 16 23:38:00 JST 2009
#
require 'spec_base'
describe Rufus::Lua::State do
describe '#new' do
it 'loads all libs by default' do
@s = Rufus::Lua::State.new
expect(@s.eval('return os;')).not_to be nil
@s.close
end
it 'loads no libs when told so' do
@s = Rufus::Lua::State.new(false)
expect(@s.eval('return os;')).to be nil
@s.close
end
it 'loads only specific libs when told so' do
@s = Rufus::Lua::State.new([ :os, :math ])
expect(@s.eval('return io;')).to be nil
expect(@s.eval('return os;')).not_to be nil
@s.close
end
end
describe '#close' do
it 'does not crash when closing an already closed State' do
@s = Rufus::Lua::State.new
@s.close
expect(lambda { @s.close }).to raise_error(RuntimeError)
end
end
describe '#[]' do
before do
@s = Rufus::Lua::State.new
end
after do
@s.close
end
it 'return nils for unbound variables' do
expect(@s['a']).to be nil
end
it 'accepts setting values directly' do
@s['a'] = 1
@s['a'] == 1
end
it 'accepts setting array values directly' do
@s['a'] = [ true, false, %w[ alpha bravo charly ] ]
expect(@s['a'].to_a[0]).to be true
expect(@s['a'].to_a[2].to_a).to eq %w[ alpha bravo charly ]
end
it 'accepts setting hash values directly' do
@s['a'] = { 'a' => 'alpha', 'b' => 'bravo' }
expect(@s['a'].to_h).to eq({ 'a' => 'alpha', 'b' => 'bravo' })
end
end
context 'gh-6 panic: unprotected error' do
it 'does not happen when loading io alone' do
state = Rufus::Lua::State.new(%w[ io ])
expect(state.eval('return io;')).not_to be nil
expect(state.eval('return math;')).to be nil
state.close
end
it 'does not happen' do
state = Rufus::Lua::State.new(%w[ base table string math package ])
expect(state.eval('return table;')).not_to be nil
expect(state.eval('return math;')).not_to be nil
state.close
end
end
end