Skip to content
Browse files

parameter setting interface

  • Loading branch information...
1 parent ac45a0a commit 7faf1d94128b7e1d5ce496d5be7802f73f8c06f5 @ahoward committed Nov 5, 2012
Showing with 43 additions and 1 deletion.
  1. +1 −1 lib/main.rb
  2. +12 −0 lib/main/parameter.rb
  3. +30 −0 test/main_test.rb
View
2 lib/main.rb
@@ -1,7 +1,7 @@
module Main
# top level constants
#
- Main::VERSION = '5.1.0' unless
+ Main::VERSION = '5.1.1' unless
defined? Main::VERSION
def self.version() Main::VERSION end
View
12 lib/main/parameter.rb
@@ -128,10 +128,22 @@ def add_value value
values << value
end
+ def set(*values)
+ self.values.replace(values)
+ end
+
+ def get
+ self.values.first
+ end
+
def value
values.first
end
+ def value=(value)
+ set(value)
+ end
+
def argument_none?
argument.nil?
end
View
30 test/main_test.rb
@@ -456,6 +456,36 @@ def test_0271
}
}
end
+
+# manual parmeter setting
+#
+ def test_0272
+ assert_nothing_raised{
+ h = {}
+
+ main(){
+ argument(:foo){ optional }
+ run do
+ o = param['foo']
+ h[nil] = o.value
+
+ o.set 'bar'
+ h['bar'] = o.value
+
+ o.set ['bar']
+ h[['bar']] = o.value
+
+ o.set 'foo', 'bar'
+ h['foo'] = o.value
+ h[['foo', 'bar']] = o.values
+ end
+ }
+
+ h.each do |expected, actual|
+ assert_equal expected, actual
+ end
+ }
+ end
# usage
#

0 comments on commit 7faf1d9

Please sign in to comment.
Something went wrong with that request. Please try again.