Modified ruby functors to remove ruby prefix.

Added new test for functors.



git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9776 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Gonzalo Garramuno 2007-05-06 04:08:55 +00:00
commit 0f15d298da
4 changed files with 113 additions and 28 deletions

View file

@ -21,6 +21,7 @@ CPP_TEST_CASES = \
li_factory \
li_std_map \
li_std_set \
li_std_functors \
naming \
primitive_types \
std_containers \

View file

@ -0,0 +1,17 @@
%module stl_new
%include <std_vector.i>
%include <std_deque.i>
%include <std_list.i>
%include <std_set.i>
%include <std_map.i>
%template(Vector ) std::vector <swig::LANGUAGE_OBJ>;
%template(Deque ) std::deque <swig::LANGUAGE_OBJ>;
%template(List ) std::list <swig::LANGUAGE_OBJ>;
%template(Set ) std::set <swig::LANGUAGE_OBJ,
swig::BinaryPredicate<> >;
%template(Map ) std::map <swig::LANGUAGE_OBJ,swig::LANGUAGE_OBJ,
swig::BinaryPredicate<> >;

View file

@ -0,0 +1,65 @@
#!/usr/bin/env ruby
#
# This is a test of STL containers using proc
# objects to change the sorting function used in them. Same as a
# std::binary_predicate in C++.
#
# Author::
# Copyright::
# License:: Ruby
#
require 'swig_assert'
require 'stl_new'
def _set(container)
swig_assert_each_line(<<EOF, binding)
cont = #{container}.new
[9,1,8,2,7,3,6,4,5].each { |x| cont.insert(x) }
i0 = cont.begin()
cont.to_a == [1,2,3,4,5,6,7,8,9]
cont = #{container}.new( proc { |a,b| b < a } )
[9,1,8,2,7,3,6,4,5].each { |x| cont.insert(x) }
cont.to_a == [9, 8, 7, 6, 5, 4, 3, 2, 1]
cont = #{container}.new( proc { |a,b| b > a } )
[9,1,8,2,7,3,6,4,5].each { |x| cont.insert(x) }
cont.to_a == [1, 2, 3, 4, 5, 6, 7, 8, 9]
cont = #{container}.new(proc { |a,b| b < a } )
cont.insert(1)
cont.to_a == [1]
i0 = cont.begin()
cont.erase(i0) # don't use i0 anymore, it is invalid now
cont.to_a == []
EOF
end
def _map(container)
swig_assert_each_line(<<EOF, binding)
cont = #{container}.new
cont['z'] = 9
cont['y'] = 1
cont['x'] = 8
cont['w'] = 2
cont.to_a == [['w',2],['x',8],['y',1],['z',9]]
cont = #{container}.new(proc { |a,b| b < a } )
cont['z'] = 9
cont['y'] = 1
cont['x'] = 8
cont['w'] = 2
cont.to_a == [['z',9],['y',1],['x',8],['w',2]]
EOF
end
def test
yield method(:_set), Stl_new::Set
yield method(:_map), Stl_new::Map
end
test do |proc, container|
proc.call(container)
end