rarg 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rarg.rb +112 -0
- data/license.txt +281 -0
- data/rakefile.rb +44 -0
- data/readme_en.txt +50 -0
- data/readme_ja.txt +54 -0
- data/setup.rb +1585 -0
- data/spec/main.rb +74 -0
- metadata +59 -0
data/spec/main.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'rarg'
|
2
|
+
|
3
|
+
describe RArg do
|
4
|
+
|
5
|
+
it 'raise ParseError without required argument' do
|
6
|
+
definition = proc do
|
7
|
+
require_arg :r1, :r2
|
8
|
+
end
|
9
|
+
|
10
|
+
proc{RArg.parse({}, &definition)}.should raise_error(RArg::Error)
|
11
|
+
proc{RArg.parse({:r1 => nil}, &definition)}.should raise_error(RArg::Error)
|
12
|
+
proc{RArg.parse({:r2 => nil}, &definition)}.should raise_error(RArg::Error)
|
13
|
+
proc{RArg.parse({:r1 => nil, :r2 => nil}, &definition)}.should_not raise_error
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'set default arguments' do
|
17
|
+
definition = proc do
|
18
|
+
default_arg :d1, 255
|
19
|
+
end
|
20
|
+
|
21
|
+
re = RArg.parse({}, &definition)
|
22
|
+
re[:d1].should == 255
|
23
|
+
re = RArg.parse({:d1 => nil}, &definition)
|
24
|
+
re[:d1].should be_nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'raise NameError if you try to get named argument that is not defined' do
|
28
|
+
re = RArg.parse({}) do
|
29
|
+
default_arg :d1
|
30
|
+
end
|
31
|
+
|
32
|
+
proc{re[:d1]}.should_not raise_error
|
33
|
+
proc{re[:unknown]}.should raise_error(RArg::Error)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'handle aliases' do
|
37
|
+
definition = proc do
|
38
|
+
default_arg :a0
|
39
|
+
alias_arg :a1, :a0
|
40
|
+
alias_arg :a2, :a0
|
41
|
+
end
|
42
|
+
|
43
|
+
re = RArg.parse({:a1 => 200}, &definition)
|
44
|
+
re[:a0].should == 200
|
45
|
+
proc{re[:a1]}.should raise_error(RArg::Error)
|
46
|
+
|
47
|
+
re = RArg.parse({:a2 => 200}, &definition)
|
48
|
+
re[:a0].should == 200
|
49
|
+
proc{re[:a2]}.should raise_error(RArg::Error)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'handle aliases and requirements in combination' do
|
53
|
+
definition = proc do
|
54
|
+
require_arg :r1
|
55
|
+
alias_arg :a1, :r1
|
56
|
+
end
|
57
|
+
|
58
|
+
proc{RArg.parse({:a1 => 200}, &definition)}.should_not raise_error
|
59
|
+
end
|
60
|
+
|
61
|
+
it "can't set alias from not existing name" do
|
62
|
+
definition = proc do
|
63
|
+
alias_arg :a1, :a0
|
64
|
+
default_arg :a0
|
65
|
+
end
|
66
|
+
|
67
|
+
proc{RArg.parse({}, &definition)}.should raise_error(RArg::Error)
|
68
|
+
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rarg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dice
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-01-31 00:00:00 +09:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: RArg is simple and small library for validating a Hash as named arguments (keyword arguments). It has three functions, requiring arguments, setting default arguments, and aliasing argument name.
|
17
|
+
email: tetradice.1011@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/rarg.rb
|
26
|
+
- spec/main.rb
|
27
|
+
- rakefile.rb
|
28
|
+
- setup.rb
|
29
|
+
- license.txt
|
30
|
+
- readme_en.txt
|
31
|
+
- readme_ja.txt
|
32
|
+
has_rdoc: false
|
33
|
+
homepage: http://rubyforge.org/projects/rarg/
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
requirements: []
|
52
|
+
|
53
|
+
rubyforge_project: rarg
|
54
|
+
rubygems_version: 1.2.0
|
55
|
+
signing_key:
|
56
|
+
specification_version: 2
|
57
|
+
summary: Small library for validating a Hash as named arguments
|
58
|
+
test_files: []
|
59
|
+
|