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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
#! /usr/bin/env ruby
# -*- coding: UTF-8 -*-
#
require 'efl/ecore'
require 'efl/ecore_evas'
require 'efl/eina_list'
require 'efl/eina_rectangle'
require 'efl/ecore_getopt'
#
describe Efl::EcoreGetopt do
#
after(:all) do
Efl::Ecore.shutdown
end
before(:all) do
Efl::Ecore.init
end
#
before(:each) do
#
@p = Efl::EcoreGetopt::REcoreGetopt.new :prog =>"Prog", :usage => "Usage", :version => "0.0.0", :copyright => "less", :license => "MIT", :description => "description", :strict => 1
#
@callback = Proc.new do |parser, desc, string, data, storage|
parser.address.should == @p.to_ptr.address
Efl::Native::EcoreGetoptDesc.new(desc)[:shortname].chr.should == 'b'
string.should == "user_arg"
data.read_string.should == "cb_data"
storage.read_pointer.read_int.should == 69
storage.read_pointer.write_int 666
true
end
@g = Efl::Native::EinaRectangleStruct.new
@g[:x] = 100; @g[:y] = 200; @g[:w] = 300; @g[:h] = 400
#
# license and copyright share the same flag named quit
@p.license 'L', 'license', 'quit'
@p.copyright 'C', 'copyright', 'quit'
@p.version 'V', 'version'
@p.help 'H', 'help'
@p.store 'i', 'int', 'store an integer', :int, 2
@p.store_meta 'd', 'double', 'store an double+meta', "My pretty meta", :double, 3.1415926
@p.store_def 's', 'string', 'store an string+default', :string, "default"
@p.store_full 'l', 'long', 'store a long+full', "My precious meta", :ecore_getopt_desc_arg_requirement_yes, :long, 666
@p.store_const 'c', 'const', 'store a constant', -666, 123456
@p.store_true 't', 'true', 'store true'
@p.store_false 'f', 'false', 'store false'
@p.count 'k', 'count', 'store count', 664
@p.append 'a', 'append', 'store append', :int, [1,2,3]
@p.choice 'm', 'many', 'store choice', ['ch1','ch2','ch3']
@p.callback_args 'b', 'callback', 'callback full', "Another meta", @callback, "cb_data", :int, 69
@p.callback_noargs 'E', 'list-engines', 'list ecore-evas available engines',
Efl::Native.method(:ecore_getopt_callback_ecore_evas_list_engines)
@p.callback_args 'g', 'geometry', 'x:y:w:h', "X:Y:W:H",
Efl::Native.method(:ecore_getopt_callback_geometry_parse), nil, :pointer, @g
@p.create
#
end
#
describe "license copyright version help" do
if ENV['DEBUG']
it "DEBUG" do
puts @p.debug
end
end
it "should handle -L" do
args = @p.parse ["My lovely prog name","-L"]
@p['quit'].should == 1
end
it "should handle --license" do
args = @p.parse ["My lovely prog name","--license"]
@p['quit'].should == 1
end
it "should handle -C" do
args = @p.parse ["progname","-C"]
@p['quit'].should == 1
end
it "should handle --copyright" do
args = @p.parse ["My lovely prog name","--copyright"]
@p['quit'].should == 1
end
it "should handle -V" do
args = @p.parse ["My lovely prog name","-V"]
@p['V'].should == 1
end
it "should handle --version" do
args = @p.parse ["progname","--version"]
@p['V'].should == 1
end
it "should handle -H" do
args = @p.parse ["My lovely prog name","-H"]
@p['H'].should == 1
end
it "should handle --help" do
args = @p.parse ["progname","--help"]
@p['H'].should == 1
end
end
describe "simple short options" do
it "should handle -i" do
@p['i'].should == 2
args = @p.parse ["progname","-i 666"]
@p['i'].should == 666
end
it "should handle -d" do
@p['d'].should == 3.1415926
args = @p.parse ["progname","-d 6.66"]
@p['d'].should == 6.66
end
it "should handle -s" do
@p['s'].should == 'default'
args = @p.parse ["progname","-sset"]
@p['s'].should == 'set'
end
it "should handle -l" do
@p['l'].should == 666
args = @p.parse ["progname","-l 69"]
@p['l'].should == 69
end
it "should handle -c" do
@p['c'].should == -666
args = @p.parse ["progname","-c"]
@p['c'].should == 123456
end
it "should handle -t" do
@p['t'].should == 0
args = @p.parse ["progname","-t"]
@p['t'].should == 1
end
it "should handle -f" do
@p['f'].should == 1
args = @p.parse ["progname","-f"]
@p['f'].should == 0
end
it "should handle -k" do
@p['k'].should == 664
args = @p.parse ["progname","-kk"]
@p['k'].should == 666
end
it "should handle -a" do
@p['a'].should == [1,2,3]
args = @p.parse ["progname","-a10", "-a20"]
@p['a'].should == [1,2,3,10,20]
end
it "should handle -m" do
@p['m'].should == nil
args = @p.parse ["progname","-mch2"]
@p['m'].should == "ch2"
end
it "should handle -b" do
@p['b'].should == 69
args = @p.parse ["progname","-buser_arg"]
@p['b'].should == 666
end
it "should handle -E" do
args = @p.parse ["My lovely prog name","-E"]
@p['E'].should == 1
end
it "should handle -g" do
g = Efl::Native::EinaRectangleStruct.new @p['g']
g[:x].should == 100
g[:y].should == 200
g[:w].should == 300
g[:h].should == 400
args = @p.parse ["progname","-g=10:20:30:40"]
g = Efl::Native::EinaRectangleStruct.new @p['g']
g[:x].should == 10
g[:y].should == 20
g[:w].should == 30
g[:h].should == 40
end
end
describe "simple long options" do
it "should handle --int" do
@p['i'].should == 2
args = @p.parse ["progname","--int=666"]
@p['i'].should == 666
end
it "should handle --double" do
@p['d'].should == 3.1415926
args = @p.parse ["progname","--double=6.66"]
@p['d'].should == 6.66
end
it "should handle --string" do
@p['s'].should == 'default'
args = @p.parse ["progname","--string=set"]
@p['s'].should == 'set'
end
it "should handle --long" do
@p['l'].should == 666
args = @p.parse ["progname","--long=69"]
@p['l'].should == 69
end
it "should handle --const" do
@p['c'].should == -666
args = @p.parse ["progname","--const"]
@p['c'].should == 123456
end
it "should handle --true" do
@p['t'].should == 0
args = @p.parse ["progname","--true"]
@p['t'].should == 1
end
it "should handle --false" do
@p['f'].should == 1
args = @p.parse ["progname","--false"]
@p['f'].should == 0
end
it "should handle --count" do
@p['k'].should == 664
args = @p.parse ["progname","--count","--count"]
@p['k'].should == 666
end
it "should handle --append" do
@p['a'].should == [1,2,3]
args = @p.parse ["progname","--append=10", "--append=20"]
@p['a'].should == [1,2,3,10,20]
end
it "should handle --many" do
@p['m'].should == nil
args = @p.parse ["progname","--many=ch3"]
@p['m'].should == "ch3"
end
it "should handle --callback" do
@p['b'].should == 69
args = @p.parse ["progname","--callback=user_arg"]
@p['b'].should == 666
end
it "should handle --list-engines" do
args = @p.parse ["My lovely prog name","--list-engines"]
@p['E'].should == 1
end
it "should handle --geometry" do
g = Efl::Native::EinaRectangleStruct.new @p['g']
g[:x].should == 100
g[:y].should == 200
g[:w].should == 300
g[:h].should == 400
args = @p.parse ["progname","--geometry=10:20:30:40"]
g = Efl::Native::EinaRectangleStruct.new @p['g']
g[:x].should == 10
g[:y].should == 20
g[:w].should == 30
g[:h].should == 40
end
end
end
|