o 1.0.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +207 -46
- data/lib/o.rb +193 -107
- data/lib/o/hash_method_fix.rb +13 -0
- data/lib/o/parser.rb +88 -0
- data/lib/o/semantics.rb +12 -0
- data/{version.rb → lib/o/version.rb} +3 -3
- data/lib/o1.rb +189 -0
- data/o.gemspec +2 -2
- data/spec/data/rc.rb +0 -0
- data/spec/o/parser_spec.rb +120 -0
- data/spec/o_spec.rb +245 -67
- data/spec/spec_helper.rb +1 -0
- metadata +9 -3
data/spec/o_spec.rb
CHANGED
@@ -1,111 +1,289 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
class O
|
4
|
-
attr_reader :_data
|
5
|
-
end
|
6
|
-
|
7
|
-
o = O.relative_load "data/lib/test"
|
8
|
-
p o._data
|
9
|
-
|
10
3
|
describe O do
|
11
|
-
|
12
|
-
|
13
|
-
|
4
|
+
describe ".get" do
|
5
|
+
it "gets from Hash" do
|
6
|
+
O.get(a: 1).should == {a: 1}
|
7
|
+
end
|
8
|
+
it "gets from O" do
|
9
|
+
o = O.new
|
10
|
+
o._child = {a:1}
|
11
|
+
O.get(o).should == {a: 1}
|
12
|
+
end
|
14
13
|
end
|
14
|
+
describe ".[]" do
|
15
|
+
it "converts Hash to O" do
|
16
|
+
O[a:1].should be_an_instance_of O
|
17
|
+
end
|
18
|
+
end
|
19
|
+
describe ".require" do
|
20
|
+
it "raise LoadError when file doesn't exist" do
|
21
|
+
lambda{O.require "file/doesnt/exists"}.should raise_error(O::LoadError)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "loads an absolute path" do
|
25
|
+
O.require(File.join($spec_data_dir, 'rc.rb'))._child == {a: 1}
|
26
|
+
end
|
15
27
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
28
|
+
it "loads a relative path" do
|
29
|
+
$: << $spec_data_dir
|
30
|
+
O.require('rc')._child == {a: 1}
|
31
|
+
O.require('rc.rb')._child == {a: 1}
|
20
32
|
end
|
33
|
+
|
34
|
+
it "loads a home path" do
|
35
|
+
ENV["HOME"] = $spec_data_dir
|
36
|
+
O.require('rc.rb')._child == {a: 1}
|
37
|
+
end
|
38
|
+
|
21
39
|
end
|
22
40
|
|
23
|
-
|
24
|
-
|
25
|
-
@
|
41
|
+
context "access" do
|
42
|
+
before :all do
|
43
|
+
@rc = O.new
|
44
|
+
@rc._child = {a: 1}
|
45
|
+
end
|
46
|
+
|
47
|
+
it "#name" do
|
48
|
+
@rc.a.should == 1
|
49
|
+
end
|
50
|
+
|
51
|
+
it "#name?" do
|
52
|
+
@rc.a?.should be_true
|
53
|
+
end
|
54
|
+
|
55
|
+
it "#[]" do
|
56
|
+
@rc[:a].should == 1
|
26
57
|
end
|
58
|
+
|
27
59
|
end
|
60
|
+
context "assignment" do
|
61
|
+
before :each do
|
62
|
+
@rc = O.new
|
63
|
+
end
|
28
64
|
|
29
|
-
|
30
|
-
|
31
|
-
@
|
65
|
+
it "#name value" do
|
66
|
+
@rc.a 1
|
67
|
+
@rc[:a].should == 1
|
32
68
|
end
|
33
69
|
|
34
|
-
it "
|
35
|
-
@
|
70
|
+
it "#name= value" do
|
71
|
+
@rc.a = 1
|
72
|
+
@rc[:a].should == 1
|
36
73
|
end
|
37
74
|
|
38
|
-
it "
|
39
|
-
@
|
40
|
-
@
|
75
|
+
it "#[:key]= value" do
|
76
|
+
@rc[:a] = 1
|
77
|
+
@rc[:a].should == 1
|
41
78
|
end
|
42
79
|
|
43
|
-
it
|
44
|
-
@
|
80
|
+
it '#["key"]= value' do
|
81
|
+
@rc["a"] = 1
|
82
|
+
@rc[:a].should == 1
|
83
|
+
end
|
84
|
+
end
|
85
|
+
it "return <#O> if key doesn't exist" do
|
86
|
+
rc = O.new
|
87
|
+
rc.i.dont.exists.should be_an_instance_of O
|
88
|
+
end
|
89
|
+
|
90
|
+
context "basic syntax" do
|
91
|
+
it "works" do
|
92
|
+
rc = O.new do
|
93
|
+
a 1
|
94
|
+
end
|
95
|
+
|
96
|
+
rc._child.should == {a: 1}
|
45
97
|
end
|
46
98
|
|
99
|
+
it "has block-style syntax" do
|
100
|
+
rc = O.new do |c|
|
101
|
+
c.a = 1
|
102
|
+
end
|
103
|
+
rc._child.should == {a: 1}
|
104
|
+
end
|
105
|
+
|
106
|
+
it "more complex one" do
|
107
|
+
rc = O.new do
|
108
|
+
self.a = 1
|
109
|
+
self[:b] = 2
|
110
|
+
end
|
111
|
+
rc._child.should == {a: 1, b: 2}
|
112
|
+
end
|
47
113
|
|
48
114
|
end
|
115
|
+
context "namespace" do
|
49
116
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
117
|
+
it "supports basic namespace" do
|
118
|
+
rc = O.new do
|
119
|
+
a.b.c 1
|
120
|
+
end
|
121
|
+
rc._child.should == {a: O[b: O[c:1]]}
|
54
122
|
end
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
123
|
+
|
124
|
+
it "support block namespace" do
|
125
|
+
rc = O.new do
|
126
|
+
b.c do
|
127
|
+
d 1
|
128
|
+
end
|
60
129
|
end
|
61
|
-
|
62
|
-
o.b.should == 2
|
130
|
+
rc._child.should == {b: O[c: O[d:1]]}
|
63
131
|
end
|
132
|
+
|
133
|
+
it "supports redefine in basic namspace" do
|
134
|
+
rc = O.new do
|
135
|
+
a.b.c 1
|
136
|
+
a.b.c 2
|
137
|
+
end
|
138
|
+
rc._child.should == {a: O[b: O[c:2]]}
|
139
|
+
end
|
140
|
+
|
141
|
+
it "supports redefine in lock namespace" do
|
142
|
+
rc = O.new do
|
143
|
+
a.b.c 3
|
144
|
+
a.b do
|
145
|
+
c 4
|
146
|
+
end
|
147
|
+
end
|
148
|
+
rc._child.should == {a: O[b: O[c:4]]}
|
149
|
+
end
|
150
|
+
|
151
|
+
it "complex namespace" do
|
152
|
+
rc = O.new do
|
153
|
+
age 1
|
154
|
+
|
155
|
+
my do
|
156
|
+
age 2
|
157
|
+
|
158
|
+
friend do
|
159
|
+
age 3
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
rc.should == O[age: 1, my: O[age: 2, friend: O[age: 3]]]
|
165
|
+
end
|
64
166
|
end
|
65
167
|
|
66
|
-
|
67
|
-
it "support
|
68
|
-
|
69
|
-
|
70
|
-
|
168
|
+
context "variable & path" do
|
169
|
+
it "support basic varaible" do
|
170
|
+
rc = O.new do
|
171
|
+
age 1
|
172
|
+
myage age+1
|
173
|
+
end
|
174
|
+
|
175
|
+
rc.myage.should == 2
|
71
176
|
end
|
72
177
|
|
73
|
-
it "support
|
74
|
-
|
178
|
+
it "support path" do
|
179
|
+
rc = O.new do
|
180
|
+
age 1
|
181
|
+
_.age.should == 1
|
75
182
|
|
76
|
-
|
77
|
-
|
183
|
+
my do
|
184
|
+
age 2
|
78
185
|
|
79
|
-
|
80
|
-
|
186
|
+
friend do
|
187
|
+
age 3
|
81
188
|
|
189
|
+
age.should == 3
|
190
|
+
__.age.should == 2
|
191
|
+
___.age.should == 1
|
192
|
+
_.age.should == 1
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
82
196
|
end
|
83
197
|
end
|
84
198
|
|
85
|
-
|
86
|
-
|
87
|
-
|
199
|
+
context "computed attribute" do
|
200
|
+
it "works" do
|
201
|
+
base = 1
|
202
|
+
rc = O.new do
|
203
|
+
count proc{base+=1}
|
204
|
+
end
|
205
|
+
rc.count.should == 2
|
206
|
+
rc.count.should == 3
|
207
|
+
end
|
208
|
+
|
209
|
+
it "support argument" do
|
210
|
+
rc = O.new do
|
211
|
+
count proc{|n|n+1}
|
212
|
+
end
|
213
|
+
rc.count(1).should == 2
|
214
|
+
end
|
88
215
|
|
89
|
-
|
90
|
-
|
216
|
+
it "#[]" do
|
217
|
+
rc = O.new do
|
218
|
+
count proc{1}
|
219
|
+
end
|
220
|
+
rc[:count].should be_an_instance_of Proc
|
221
|
+
end
|
222
|
+
|
223
|
+
it "#name=" do
|
224
|
+
rc = O.new do
|
225
|
+
count proc{1}
|
226
|
+
end
|
227
|
+
rc.name = 1
|
228
|
+
rc.name.should == 1
|
229
|
+
end
|
91
230
|
end
|
92
231
|
|
93
|
-
|
232
|
+
it "is semantics" do
|
233
|
+
rc = O.new do
|
234
|
+
is_started no
|
235
|
+
end
|
94
236
|
|
95
|
-
|
96
|
-
|
97
|
-
o = O::O_Eval.new
|
98
|
-
o.instance_eval <<-EOF
|
99
|
-
@a = 1
|
100
|
-
EOF
|
237
|
+
rc.is_started?.should be_false
|
238
|
+
end
|
101
239
|
|
102
|
-
|
240
|
+
context "hash compatibility" do
|
241
|
+
it "works" do
|
242
|
+
rc = O.new do
|
243
|
+
a 1
|
244
|
+
end
|
245
|
+
|
246
|
+
rc._keys.should == [:a]
|
247
|
+
end
|
103
248
|
end
|
104
|
-
end
|
105
249
|
|
106
|
-
|
107
|
-
|
108
|
-
|
250
|
+
context "temporarily change" do
|
251
|
+
it "works" do
|
252
|
+
rc = O.new do
|
253
|
+
a 1
|
254
|
+
end
|
255
|
+
|
256
|
+
rc._temp do
|
257
|
+
rc.a 2
|
258
|
+
rc.a.should == 2
|
259
|
+
end
|
260
|
+
rc.a.should == 1
|
261
|
+
end
|
109
262
|
end
|
110
|
-
|
263
|
+
|
264
|
+
describe "#inspect" do
|
265
|
+
it "works" do
|
266
|
+
node1 = O.new
|
267
|
+
node2 = O.new
|
268
|
+
node3 = O.new
|
269
|
+
node3._child = {a: 1, b: 2}
|
270
|
+
node2._child = {a: node3, b: 3}
|
271
|
+
node1._child = { a: 1, b: 2, "a" => 112, c: node2}
|
272
|
+
|
273
|
+
right = <<-EOF.rstrip
|
274
|
+
<#O
|
275
|
+
:a => 1
|
276
|
+
:b => 2
|
277
|
+
"a" => 112
|
278
|
+
:c => <#O
|
279
|
+
:a => <#O
|
280
|
+
:a => 1
|
281
|
+
:b => 2>
|
282
|
+
:b => 3>>
|
283
|
+
EOF
|
284
|
+
|
285
|
+
node1.inspect.should == right
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
111
289
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: o
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version:
|
5
|
+
version: 2.0.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Guten
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-07-
|
13
|
+
date: 2011-07-12 00:00:00 Z
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description: |
|
@@ -31,15 +31,21 @@ files:
|
|
31
31
|
- README.md
|
32
32
|
- Ragfile
|
33
33
|
- lib/o.rb
|
34
|
+
- lib/o/hash_method_fix.rb
|
35
|
+
- lib/o/parser.rb
|
36
|
+
- lib/o/semantics.rb
|
37
|
+
- lib/o/version.rb
|
38
|
+
- lib/o1.rb
|
34
39
|
- o.gemspec
|
35
40
|
- o.watchr
|
36
41
|
- spec/data/home/gutenrc
|
37
42
|
- spec/data/lib/guten
|
38
43
|
- spec/data/lib/tag.rb
|
39
44
|
- spec/data/lib/test
|
45
|
+
- spec/data/rc.rb
|
46
|
+
- spec/o/parser_spec.rb
|
40
47
|
- spec/o_spec.rb
|
41
48
|
- spec/spec_helper.rb
|
42
|
-
- version.rb
|
43
49
|
homepage: http://github.com/GutenYe/o
|
44
50
|
licenses: []
|
45
51
|
|