summaryrefslogtreecommitdiffstats
path: root/spec/ecore_getopt_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ecore_getopt_spec.rb')
-rw-r--r--spec/ecore_getopt_spec.rb106
1 files changed, 32 insertions, 74 deletions
diff --git a/spec/ecore_getopt_spec.rb b/spec/ecore_getopt_spec.rb
index 3d0a7c0..10c0894 100644
--- a/spec/ecore_getopt_spec.rb
+++ b/spec/ecore_getopt_spec.rb
@@ -6,12 +6,14 @@ require 'efl/ecore_getopt'
#
describe Efl::EcoreGetopt do
#
- before(:each) do
+ before(:all) do
Efl::Ecore.init
#
@p = Efl::EcoreGetopt::Parser.new :prog =>"Prog", :usage => "Usage", :version => "0.0.0", :copyright => "less", :license => "MIT", :description => "description", :strict => 1
- def @p.cb parser, desc, string, data, value
- puts parser, desc, string, data, value
+ @callback = Proc.new do |parser, desc, string, data, value|
+ string.should eql "my_data"
+ data.read_string.should eql "cb_data"
+ value.read_pointer.read_int.should eql 99
true
end
#
@@ -30,20 +32,8 @@ describe Efl::EcoreGetopt do
:count => FFI::MemoryPointer.new(:int),
:callback => FFI::MemoryPointer.new(:int),
}
- [ :license, :copyright, :version, :help ].each do |sym|
- @values[sym].write_char 0
- end
- @values[:int].write_int 0
- @values[:double].write_double 3.1415926
- @values[:short].write_short 9
- @values[:long].write_long 666
- @values[:true].write_uchar 1
- @values[:false].write_uchar 0
- @values[:choice].write_pointer FFI::Pointer::NULL
- @values[:count].write_int 664
- @values[:callback].write_int 9
@meta = FFI::MemoryPointer.from_string "My pretty metadata"
- @cb_data = FFI::MemoryPointer.from_string "cb data"
+ @cb_data = FFI::MemoryPointer.from_string "cb_data"
#
@p.license 'L', 'license'
@p.value :boolp, @values[:license]
@@ -73,17 +63,32 @@ describe Efl::EcoreGetopt do
# @p.append 'a', 'append', 'store append', :ecore_getopt_type_int
@p.count 'k', 'count', 'store count'
@p.value :intp, @values[:count]
- # FIXME breaks --long ??
-# @p.callback_args 'b', 'callback', 'callback full', @meta, @p.method(:cb), @cb_data
-# @p.value :intp, @values[:callback]
+ @p.callback_args 'b', 'callback', 'callback full', @meta, @callback, @cb_data
+ @p.value :intp, @values[:callback]
@p.create
-# puts @p.debug
+ puts @p.debug
#
end
+ before(:each) do
+ [ :license, :copyright, :version, :help ].each do |sym|
+ @values[sym].write_char 0
+ end
+ @values[:int].write_int 0
+ @values[:double].write_double 3.1415926
+ @values[:short].write_short 9
+ @values[:long].write_long 666
+ @values[:true].write_uchar 1
+ @values[:false].write_uchar 0
+ @values[:choice].write_pointer FFI::Pointer::NULL
+ @values[:count].write_int 664
+ @values[:callback].write_int 99
+ end
+ after(:all) do
+ Efl::Ecore.shutdown
+ end
#
describe "license copyright version help" do
it "should handle -L" do
- #
[ :license, :copyright, :version, :help ].each do |sym|
@values[sym].read_char.should eql 0
end
@@ -92,10 +97,8 @@ describe Efl::EcoreGetopt do
[ :copyright, :version, :help ].each do |sym|
@values[sym].read_char.should eql 0
end
- Efl::Ecore.shutdown
end
it "should handle --license" do
- #
[ :license, :copyright, :version, :help ].each do |sym|
@values[sym].read_char.should eql 0
end
@@ -104,10 +107,8 @@ describe Efl::EcoreGetopt do
[ :copyright, :version, :help ].each do |sym|
@values[sym].read_char.should eql 0
end
- Efl::Ecore.shutdown
end
it "should handle -C" do
- #
[ :license, :copyright, :version, :help ].each do |sym|
@values[sym].read_char.should eql 0
end
@@ -116,10 +117,8 @@ describe Efl::EcoreGetopt do
[ :license, :version, :help ].each do |sym|
@values[sym].read_char.should eql 0
end
- Efl::Ecore.shutdown
end
it "should handle --copyright" do
- #
[ :license, :copyright, :version, :help ].each do |sym|
@values[sym].read_char.should eql 0
end
@@ -128,10 +127,8 @@ describe Efl::EcoreGetopt do
[ :license, :version, :help ].each do |sym|
@values[sym].read_char.should eql 0
end
- Efl::Ecore.shutdown
end
it "should handle -V" do
- #
[ :license, :copyright, :version, :help ].each do |sym|
@values[sym].read_char.should eql 0
end
@@ -140,10 +137,8 @@ describe Efl::EcoreGetopt do
[ :license, :copyright, :help ].each do |sym|
@values[sym].read_char.should eql 0
end
- Efl::Ecore.shutdown
end
it "should handle --version" do
- #
[ :license, :copyright, :version, :help ].each do |sym|
@values[sym].read_char.should eql 0
end
@@ -152,10 +147,8 @@ describe Efl::EcoreGetopt do
[ :license, :copyright, :help ].each do |sym|
@values[sym].read_char.should eql 0
end
- Efl::Ecore.shutdown
end
it "should handle -H" do
- #
[ :license, :copyright, :version, :help ].each do |sym|
@values[sym].read_char.should eql 0
end
@@ -164,10 +157,8 @@ describe Efl::EcoreGetopt do
[ :license, :copyright, :version ].each do |sym|
@values[sym].read_char.should eql 0
end
- Efl::Ecore.shutdown
end
it "should handle --help" do
- #
[ :license, :copyright, :version, :help ].each do |sym|
@values[sym].read_char.should eql 0
end
@@ -176,143 +167,110 @@ describe Efl::EcoreGetopt do
[ :license, :copyright, :version ].each do |sym|
@values[sym].read_char.should eql 0
end
- Efl::Ecore.shutdown
end
end
describe "simple options" do
it "should handle -i" do
- #
@values[:int].read_int.should eql 0
args = @p.parse ["progname","-i 666"]
@values[:int].read_int.should eql 666
- Efl::Ecore.shutdown
end
it "should handle --int" do
- #
@values[:int].read_int.should eql 0
args = @p.parse ["progname","--int=666"]
@values[:int].read_int.should eql 666
- Efl::Ecore.shutdown
end
it "should handle -d" do
- #
@values[:double].read_double.should eql 3.1415926
args = @p.parse ["progname","-d 6.66"]
@values[:double].read_double.should eql 6.66
- Efl::Ecore.shutdown
end
it "should handle --double" do
- #
@values[:double].read_double.should eql 3.1415926
args = @p.parse ["progname","--double=6.66"]
@values[:double].read_double.should eql 6.66
- Efl::Ecore.shutdown
end
# # FIXME : maybe fix ecore
# it "should handle -s default" do
-# #
# @values[:short].read_short.should eql 9
# args = @p.parse ["progname"]
# @values[:short].read_short.should eql 6
-# Efl::Ecore.shutdown
# end
it "should handle -s" do
- #
@values[:short].read_short.should eql 9
args = @p.parse ["progname","-s 125"]
@values[:short].read_short.should eql 125
- Efl::Ecore.shutdown
end
it "should handle --short" do
- #
@values[:short].read_short.should eql 9
args = @p.parse ["progname","--short=125"]
@values[:short].read_short.should eql 125
- Efl::Ecore.shutdown
end
it "should handle -l" do
- #
@values[:long].read_long.should eql 666
args = @p.parse ["progname","-l 69"]
@values[:long].read_long.should eql 69
- Efl::Ecore.shutdown
end
it "should handle --long" do
- #
@values[:long].read_long.should eql 666
args = @p.parse ["progname","--long=69"]
@values[:long].read_long.should eql 69
- Efl::Ecore.shutdown
end
it "should handle -c" do
- #
@values[:long].read_long.should eql 666
args = @p.parse ["progname","-c"]
@values[:long].read_long.should eql 123456
- Efl::Ecore.shutdown
end
it "should handle --const" do
- #
@values[:long].read_long.should eql 666
args = @p.parse ["progname","--const"]
@values[:long].read_long.should eql 123456
- Efl::Ecore.shutdown
end
it "should handle -t" do
- #
@values[:false].read_uchar.should eql 0
args = @p.parse ["progname","-t"]
@values[:false].read_uchar.should eql 1
- Efl::Ecore.shutdown
end
it "should handle --true" do
- #
@values[:false].read_uchar.should eql 0
args = @p.parse ["progname","--true"]
@values[:false].read_uchar.should eql 1
- Efl::Ecore.shutdown
end
it "should handle -f" do
- #
@values[:true].read_uchar.should eql 1
args = @p.parse ["progname","-f"]
@values[:true].read_uchar.should eql 0
- Efl::Ecore.shutdown
end
it "should handle --false" do
- #
@values[:true].read_uchar.should eql 1
args = @p.parse ["progname","--false"]
@values[:true].read_uchar.should eql 0
- Efl::Ecore.shutdown
end
it "should handle -m" do
- #
@values[:choice].read_pointer.should eql FFI::Pointer::NULL
args = @p.parse ["progname","-mch2"]
@values[:choice].read_pointer.read_string.should eql "ch2"
- Efl::Ecore.shutdown
end
it "should handle --many" do
- #
@values[:choice].read_pointer.should eql FFI::Pointer::NULL
args = @p.parse ["progname","--many=ch3"]
@values[:choice].read_pointer.read_string.should eql "ch3"
- Efl::Ecore.shutdown
end
it "should handle -k" do
- #
@values[:count].read_int.should eql 664
args = @p.parse ["progname","-kk"]
@values[:count].read_int.should eql 666
- Efl::Ecore.shutdown
end
it "should handle --count" do
- #
@values[:count].read_int.should eql 664
args = @p.parse ["progname","--count","--count"]
@values[:count].read_int.should eql 666
- Efl::Ecore.shutdown
+ end
+ it "should handle -b" do
+ args = @p.parse ["progname","-bmy_data"]
+ end
+ it "should handle --callback" do
+ args = @p.parse ["progname","-callback=my_data"]
end
end
end