benry-cmdapp 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +6 -0
- data/README.md +1693 -852
- data/benry-cmdapp.gemspec +3 -3
- data/doc/benry-cmdapp.html +1582 -906
- data/lib/benry/cmdapp.rb +1894 -1060
- data/test/app_test.rb +882 -1078
- data/test/config_test.rb +71 -0
- data/test/context_test.rb +382 -0
- data/test/func_test.rb +302 -82
- data/test/help_test.rb +1054 -553
- data/test/metadata_test.rb +191 -0
- data/test/misc_test.rb +175 -0
- data/test/registry_test.rb +402 -0
- data/test/run_all.rb +4 -3
- data/test/scope_test.rb +1210 -0
- data/test/shared.rb +112 -49
- data/test/util_test.rb +154 -99
- metadata +17 -9
- data/test/action_test.rb +0 -1038
- data/test/index_test.rb +0 -185
@@ -0,0 +1,402 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
|
5
|
+
require_relative 'shared'
|
6
|
+
|
7
|
+
|
8
|
+
Oktest.scope do
|
9
|
+
|
10
|
+
|
11
|
+
topic Benry::CmdApp::Registry do
|
12
|
+
|
13
|
+
def new_registry_with_filter(*categories)
|
14
|
+
idx = Benry::CmdApp::Registry.new()
|
15
|
+
Benry::CmdApp::REGISTRY.metadata_each do |md|
|
16
|
+
idx.metadata_add(md) if md.name.start_with?(*categories)
|
17
|
+
end
|
18
|
+
return idx
|
19
|
+
end
|
20
|
+
|
21
|
+
before do
|
22
|
+
@registry = Benry::CmdApp::Registry.new
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
topic '#metadata_add()' do
|
27
|
+
|
28
|
+
spec "[!8bhxu] registers metadata with it's name as key." do
|
29
|
+
metadata = Benry::CmdApp::REGISTRY.metadata_get("hello")
|
30
|
+
ok {@registry.metadata_get("hello")} == nil
|
31
|
+
@registry.metadata_add(metadata)
|
32
|
+
ok {@registry.metadata_get("hello")} == metadata
|
33
|
+
end
|
34
|
+
|
35
|
+
spec "[!k07kp] returns registered metadata objet." do
|
36
|
+
metadata = Benry::CmdApp::REGISTRY.metadata_get("hello")
|
37
|
+
ok {@registry.metadata_add(metadata)} == metadata
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
topic '#metadata_get()' do
|
44
|
+
|
45
|
+
spec "[!l5m49] returns metadata object corresponding to name." do
|
46
|
+
metadata = Benry::CmdApp::REGISTRY.metadata_get("hello")
|
47
|
+
@registry.metadata_add(metadata)
|
48
|
+
ok {@registry.metadata_get("hello")} == metadata
|
49
|
+
end
|
50
|
+
|
51
|
+
spec "[!rztk2] returns nil if metadata not found for the name." do
|
52
|
+
ok {@registry.metadata_get("hello")} == nil
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
topic '#metadata_del()' do
|
59
|
+
|
60
|
+
spec "[!69vo7] deletes metadata object corresponding to name." do
|
61
|
+
metadata = Benry::CmdApp::REGISTRY.metadata_get("hello")
|
62
|
+
@registry.metadata_add(metadata)
|
63
|
+
ok {@registry.metadata_get("hello")} == metadata
|
64
|
+
@registry.metadata_del("hello") # !!!
|
65
|
+
ok {@registry.metadata_get("hello")} == nil
|
66
|
+
end
|
67
|
+
|
68
|
+
spec "[!8vg6w] returns deleted metadata object." do
|
69
|
+
metadata = Benry::CmdApp::REGISTRY.metadata_get("hello")
|
70
|
+
@registry.metadata_add(metadata)
|
71
|
+
ok {@registry.metadata_del("hello")} == metadata
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
topic '#metadata_exist?()' do
|
78
|
+
|
79
|
+
spec "[!0ck5n] returns true if metadata object registered." do
|
80
|
+
metadata = Benry::CmdApp::REGISTRY.metadata_get("hello")
|
81
|
+
@registry.metadata_add(metadata)
|
82
|
+
ok {@registry.metadata_exist?("hello")} == true
|
83
|
+
end
|
84
|
+
|
85
|
+
spec "[!x7ziz] returns false if metadata object not registered." do
|
86
|
+
ok {@registry.metadata_exist?("hello")} == false
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
topic '#metadata_each()' do
|
93
|
+
|
94
|
+
spec "[!3l6r7] returns Enumerator object if block not given." do
|
95
|
+
x = Benry::CmdApp::REGISTRY.metadata_each()
|
96
|
+
ok {x}.is_a?(Enumerator)
|
97
|
+
end
|
98
|
+
|
99
|
+
spec "[!r8mb3] yields each metadata object if block given." do
|
100
|
+
n = 0
|
101
|
+
Benry::CmdApp::REGISTRY.metadata_each do |md|
|
102
|
+
n += 1
|
103
|
+
ok {md}.is_a?(Benry::CmdApp::BaseMetadata)
|
104
|
+
end
|
105
|
+
ok {n} > 0
|
106
|
+
end
|
107
|
+
|
108
|
+
spec "[!qvc77] ignores hidden metadata if `all: false` passed." do
|
109
|
+
found = false
|
110
|
+
Benry::CmdApp::REGISTRY.metadata_each(all: false) {|md| found = true if md.hidden? }
|
111
|
+
ok {found} == false
|
112
|
+
#
|
113
|
+
found = false
|
114
|
+
Benry::CmdApp::REGISTRY.metadata_each {|md| found = true if md.hidden? }
|
115
|
+
ok {found} == true
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
topic '#metadata_action2aliases()' do
|
122
|
+
|
123
|
+
before do
|
124
|
+
hello_action = Benry::CmdApp::REGISTRY.metadata_get("hello")
|
125
|
+
stage_action = Benry::CmdApp::REGISTRY.metadata_get("git:stage")
|
126
|
+
staged_action = Benry::CmdApp::REGISTRY.metadata_get("git:staged")
|
127
|
+
unstage_action = Benry::CmdApp::REGISTRY.metadata_get("git:unstage")
|
128
|
+
@aliases = [
|
129
|
+
Benry::CmdApp::AliasMetadata.new("hi", "hello", []),
|
130
|
+
Benry::CmdApp::AliasMetadata.new("chao", "hello", ["-l", "it"]),
|
131
|
+
Benry::CmdApp::AliasMetadata.new("clear", "git:unstage", []),
|
132
|
+
]
|
133
|
+
@registry = Benry::CmdApp::Registry.new
|
134
|
+
reg = @registry
|
135
|
+
reg.metadata_add(hello_action)
|
136
|
+
reg.metadata_add(stage_action)
|
137
|
+
reg.metadata_add(staged_action)
|
138
|
+
reg.metadata_add(unstage_action)
|
139
|
+
@aliases.each do |md|
|
140
|
+
reg.metadata_add(md)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
spec "[!krry6] returns a Hash object (key: action name, value: alias metadatas)." do
|
145
|
+
d = @registry.metadata_action2aliases()
|
146
|
+
ok {d}.is_a?(Hash)
|
147
|
+
ok {d.keys} == ["hello", "git:unstage"]
|
148
|
+
ok {Set.new(d["hello"])} == Set.new([@aliases[0], @aliases[1]])
|
149
|
+
ok {d["git:unstage"]} == [@aliases[2]]
|
150
|
+
end
|
151
|
+
|
152
|
+
spec "[!zhcm6] skips actions which has no aliases." do
|
153
|
+
d = @registry.metadata_action2aliases()
|
154
|
+
ok {d}.is_a?(Hash)
|
155
|
+
ok {d.keys} == ["hello", "git:unstage"]
|
156
|
+
ok {d.keys}.NOT.include?("git:stage")
|
157
|
+
ok {d.keys}.NOT.include?("git:staged")
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
|
163
|
+
topic '#metadata_lookup()' do
|
164
|
+
|
165
|
+
spec "[!dcs9v] looks up action metadata recursively if alias name specified." do
|
166
|
+
Benry::CmdApp.define_alias("ali61", "hello")
|
167
|
+
Benry::CmdApp.define_alias!("ali62", "ali61")
|
168
|
+
Benry::CmdApp.define_alias!("ali63", "ali62")
|
169
|
+
#
|
170
|
+
hello_md = Benry::CmdApp::REGISTRY.metadata_get("hello")
|
171
|
+
ok {hello_md}.is_a?(Benry::CmdApp::ActionMetadata)
|
172
|
+
ok {hello_md.name} == "hello"
|
173
|
+
#
|
174
|
+
ok {Benry::CmdApp::REGISTRY.metadata_lookup("hello")} == [hello_md, []]
|
175
|
+
ok {Benry::CmdApp::REGISTRY.metadata_lookup("ali61")} == [hello_md, []]
|
176
|
+
ok {Benry::CmdApp::REGISTRY.metadata_lookup("ali62")} == [hello_md, []]
|
177
|
+
ok {Benry::CmdApp::REGISTRY.metadata_lookup("ali63")} == [hello_md, []]
|
178
|
+
end
|
179
|
+
|
180
|
+
spec "[!f8fqx] returns action metadata and alias args." do
|
181
|
+
Benry::CmdApp.define_alias("ali71", ["hello", "a"])
|
182
|
+
Benry::CmdApp.define_alias!("ali72", "ali71")
|
183
|
+
Benry::CmdApp.define_alias!("ali73", ["ali72", "b", "c"])
|
184
|
+
#
|
185
|
+
hello_md = Benry::CmdApp::REGISTRY.metadata_get("hello")
|
186
|
+
ok {Benry::CmdApp::REGISTRY.metadata_lookup("hello")} == [hello_md, []]
|
187
|
+
ok {Benry::CmdApp::REGISTRY.metadata_lookup("ali71")} == [hello_md, ["a"]]
|
188
|
+
ok {Benry::CmdApp::REGISTRY.metadata_lookup("ali72")} == [hello_md, ["a"]]
|
189
|
+
ok {Benry::CmdApp::REGISTRY.metadata_lookup("ali73")} == [hello_md, ["a", "b", "c"]]
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
|
195
|
+
topic '#prefix_add()' do
|
196
|
+
|
197
|
+
spec "[!k27in] registers prefix if not registered yet." do
|
198
|
+
prefix = "p7885:"
|
199
|
+
ok {@registry.category_exist?(prefix)} == false
|
200
|
+
@registry.category_add(prefix, nil)
|
201
|
+
ok {@registry.category_exist?(prefix)} == true
|
202
|
+
ok {@registry.category_get_desc(prefix)} == nil
|
203
|
+
end
|
204
|
+
|
205
|
+
spec "[!xubc8] registers prefix whenever desc is not a nil." do
|
206
|
+
prefix = "p8796:"
|
207
|
+
@registry.category_add(prefix, "some description")
|
208
|
+
ok {@registry.category_exist?(prefix)} == true
|
209
|
+
ok {@registry.category_get_desc(prefix)} == "some description"
|
210
|
+
#
|
211
|
+
@registry.category_add(prefix, "other description")
|
212
|
+
ok {@registry.category_get_desc(prefix)} == "other description"
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
|
218
|
+
topic '#prefix_add_via_action()' do
|
219
|
+
|
220
|
+
spec "[!ztrfj] registers prefix of action." do
|
221
|
+
@registry.category_add_via_action("p5671:hello")
|
222
|
+
ok {@registry.category_exist?("p5671:")} == true
|
223
|
+
ok {@registry.category_get_desc("p5671:")} == nil
|
224
|
+
#
|
225
|
+
@registry.category_add_via_action("p5671:fo-o:ba_r:baz9:hello2")
|
226
|
+
ok {@registry.category_exist?("p5671:fo-o:ba_r:baz9:")} == true
|
227
|
+
ok {@registry.category_exist?("p5671:fo-o:ba_r:")} == false
|
228
|
+
ok {@registry.category_exist?("p5671:fo-o:")} == false
|
229
|
+
end
|
230
|
+
|
231
|
+
spec "[!31pik] do nothing if prefix already registered." do
|
232
|
+
prefix = "p0620:hello"
|
233
|
+
@registry.category_add(prefix, "some desc")
|
234
|
+
@registry.category_add_via_action(prefix)
|
235
|
+
ok {@registry.category_get_desc(prefix)} == "some desc"
|
236
|
+
end
|
237
|
+
|
238
|
+
spec "[!oqq7j] do nothing if action has no prefix." do
|
239
|
+
ok {@registry.category_each().count()} == 0
|
240
|
+
@registry.category_add_via_action("a4049")
|
241
|
+
ok {@registry.category_each().count()} == 0
|
242
|
+
end
|
243
|
+
|
244
|
+
end
|
245
|
+
|
246
|
+
|
247
|
+
topic '#prefix_each()' do
|
248
|
+
|
249
|
+
spec "[!67r3i] returns Enumerator object if block not given." do
|
250
|
+
ok {@registry.category_each()}.is_a?(Enumerator)
|
251
|
+
end
|
252
|
+
|
253
|
+
spec "[!g3d1z] yields block with each prefix and desc." do
|
254
|
+
@registry.category_add("p2358:", nil)
|
255
|
+
@registry.category_add("p3892:", "some desc")
|
256
|
+
d = {}
|
257
|
+
@registry.category_each() {|prefix, desc| d[prefix] = desc }
|
258
|
+
ok {d} == {"p2358:" => nil, "p3892:" => "some desc"}
|
259
|
+
end
|
260
|
+
|
261
|
+
end
|
262
|
+
|
263
|
+
|
264
|
+
topic '#prefix_exist?()' do
|
265
|
+
|
266
|
+
spec "[!79cyx] returns true if prefix is already registered." do
|
267
|
+
@registry.category_add("p0057:", nil)
|
268
|
+
ok {@registry.category_exist?("p0057:")} == true
|
269
|
+
end
|
270
|
+
|
271
|
+
spec "[!jx7fk] returns false if prefix is not registered yet." do
|
272
|
+
ok {@registry.category_exist?("p0760:")} == false
|
273
|
+
end
|
274
|
+
|
275
|
+
end
|
276
|
+
|
277
|
+
|
278
|
+
topic '#prefix_get_desc()' do
|
279
|
+
|
280
|
+
spec "[!d47kq] returns description if prefix is registered." do
|
281
|
+
Benry::CmdApp::REGISTRY.category_add("p5679", "bla bla")
|
282
|
+
ok {Benry::CmdApp::REGISTRY.category_get_desc("p5679")} == "bla bla"
|
283
|
+
end
|
284
|
+
|
285
|
+
spec "[!otp1b] returns nil if prefix is not registered." do
|
286
|
+
ok {Benry::CmdApp::REGISTRY.category_get_desc("p8233")} == nil
|
287
|
+
end
|
288
|
+
|
289
|
+
end
|
290
|
+
|
291
|
+
|
292
|
+
topic '#prefix_count_actions()' do
|
293
|
+
|
294
|
+
spec "[!8wipx] includes prefix of hidden actions if `all: true` passed." do
|
295
|
+
registry = new_registry_with_filter("giit:", "md:")
|
296
|
+
ok {registry.category_count_actions(1, all: true) }.key?("md:")
|
297
|
+
ok {registry.category_count_actions(1, all: false)}.NOT.key?("md:")
|
298
|
+
end
|
299
|
+
|
300
|
+
spec "[!5n3qj] counts prefix of specified depth." do
|
301
|
+
registry = new_registry_with_filter("giit:", "md:")
|
302
|
+
expected1 = {"giit:"=>13}
|
303
|
+
expected2 = {"giit:branch:"=>2, "giit:"=>0, "giit:commit:"=>1,
|
304
|
+
"giit:repo:"=>7,
|
305
|
+
"giit:staging:"=>3}
|
306
|
+
expected3 = {"giit:branch:"=>2, "giit:"=>0, "giit:commit:"=>1,
|
307
|
+
"giit:repo:config:"=>3, "giit:repo:"=>2, "giit:repo:remote:"=>2,
|
308
|
+
"giit:staging:"=>3}
|
309
|
+
ok {registry.category_count_actions(1)} == expected1
|
310
|
+
ok {registry.category_count_actions(2)} == expected2
|
311
|
+
ok {registry.category_count_actions(3)} == expected3
|
312
|
+
ok {registry.category_count_actions(4)} == expected3
|
313
|
+
ok {registry.category_count_actions(5)} == expected3
|
314
|
+
end
|
315
|
+
|
316
|
+
spec "[!r2frb] counts prefix of lesser depth." do
|
317
|
+
registry = new_registry_with_filter("giit:", "md:")
|
318
|
+
x = registry.category_count_actions(1)
|
319
|
+
ok {x}.key?("giit:")
|
320
|
+
ok {x}.NOT.key?("giit:branch:")
|
321
|
+
ok {x}.NOT.key?("giit:repo:config:")
|
322
|
+
x = registry.category_count_actions(2)
|
323
|
+
ok {x}.key?("giit:")
|
324
|
+
ok {x}.key?("giit:branch:")
|
325
|
+
ok {x}.NOT.key?("giit:repo:config:")
|
326
|
+
x = registry.category_count_actions(3)
|
327
|
+
ok {x}.key?("giit:")
|
328
|
+
ok {x}.key?("giit:branch:")
|
329
|
+
ok {x}.key?("giit:repo:config:")
|
330
|
+
end
|
331
|
+
|
332
|
+
end
|
333
|
+
|
334
|
+
|
335
|
+
topic '#abbrev_add()' do
|
336
|
+
|
337
|
+
spec "[!n475k] registers abbrev with prefix." do
|
338
|
+
@registry.abbrev_add("g:", "git:")
|
339
|
+
ok {@registry.abbrev_exist?("g:")} == true
|
340
|
+
ok {@registry.abbrev_get_prefix("g:")} == "git:"
|
341
|
+
end
|
342
|
+
|
343
|
+
end
|
344
|
+
|
345
|
+
|
346
|
+
topic '#abbrev_get_prefix()' do
|
347
|
+
|
348
|
+
spec "[!h1dvb] returns prefix bound to abbrev." do
|
349
|
+
@registry.abbrev_add("g:", "git:")
|
350
|
+
ok {@registry.abbrev_get_prefix("g:")} == "git:"
|
351
|
+
end
|
352
|
+
|
353
|
+
end
|
354
|
+
|
355
|
+
|
356
|
+
topic '#abbrev_exist?()' do
|
357
|
+
|
358
|
+
spec "[!tjbdy] returns true/false if abbrev registered or not." do
|
359
|
+
ok {@registry.abbrev_exist?("g:")} == false
|
360
|
+
@registry.abbrev_add("g:", "git:")
|
361
|
+
ok {@registry.abbrev_exist?("g:")} == true
|
362
|
+
end
|
363
|
+
|
364
|
+
end
|
365
|
+
|
366
|
+
|
367
|
+
topic '#abbrev_each()' do
|
368
|
+
|
369
|
+
spec "[!2oo4o] yields each abbrev name and prefix." do
|
370
|
+
@registry.abbrev_add("g1:", "git:")
|
371
|
+
@registry.abbrev_add("g2:", "git:")
|
372
|
+
arr = []
|
373
|
+
@registry.abbrev_each do |*args|
|
374
|
+
arr << args
|
375
|
+
end
|
376
|
+
ok {arr} == [["g1:", "git:"], ["g2:", "git:"]]
|
377
|
+
end
|
378
|
+
|
379
|
+
end
|
380
|
+
|
381
|
+
|
382
|
+
topic '#abbrev_resolve()' do
|
383
|
+
|
384
|
+
spec "[!n7zsy] replaces abbrev in action name with prefix." do
|
385
|
+
@registry.abbrev_add("g:", "git:")
|
386
|
+
ok {@registry.abbrev_resolve("g:stage")} == "git:stage"
|
387
|
+
end
|
388
|
+
|
389
|
+
spec "[!kdi3o] returns nil if abbrev not found in action name." do
|
390
|
+
@registry.abbrev_add("g:", "git:")
|
391
|
+
ok {@registry.abbrev_resolve("gi:stage")} == nil
|
392
|
+
ok {@registry.abbrev_resolve("h:stage")} == nil
|
393
|
+
ok {@registry.abbrev_resolve("gitstage")} == nil
|
394
|
+
end
|
395
|
+
|
396
|
+
end
|
397
|
+
|
398
|
+
|
399
|
+
end
|
400
|
+
|
401
|
+
|
402
|
+
end
|
data/test/run_all.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
|
4
|
-
Dir.glob(File.dirname(__FILE__) + '
|
5
|
-
|
6
|
-
|
4
|
+
Dir.glob(File.dirname(__FILE__) + '/**/*.rb').each do |filename|
|
5
|
+
if filename != __FILE__
|
6
|
+
require_relative File.basename(filename)
|
7
|
+
end
|
7
8
|
end
|