~ubuntu-branches/ubuntu/oneiric/swig1.3/oneiric

« back to all changes in this revision

Viewing changes to Examples/test-suite/ruby/li_std_functors_runme.rb

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-12-06 10:27:08 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20071206102708-t37t62i45n595w0e
Tags: 1.3.33-2ubuntu1
* Merge with Debian; remaining changes:
  - Drop support for pike.
  - Use python2.5 instead of python2.4.
  - Clean Runtime/ as well.
  - Force a few environment variables.
* debian/Rules (clean): Remove Lib/ocaml/swigp4.ml.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env ruby
 
2
#
 
3
# This is a test of STL containers using proc
 
4
# objects to change the sorting function used in them.  Same as a
 
5
# std::binary_predicate in C++.
 
6
#
 
7
 
8
 
9
 
10
#
 
11
 
 
12
require 'swig_assert'
 
13
require 'li_std_functors'
 
14
 
 
15
 
 
16
def _set(container)
 
17
  swig_assert_each_line(<<EOF, binding)
 
18
    cont = #{container}.new
 
19
    [9,1,8,2,7,3,6,4,5].each { |x| cont.insert(x) }
 
20
    i0 = cont.begin()
 
21
    cont.to_a == [1,2,3,4,5,6,7,8,9]
 
22
    cont = #{container}.new( proc { |a,b| b < a } )
 
23
    [9,1,8,2,7,3,6,4,5].each { |x| cont.insert(x) }
 
24
    cont.to_a == [9, 8, 7, 6, 5, 4, 3, 2, 1]
 
25
    cont = #{container}.new( proc { |a,b| b > a } )
 
26
    [9,1,8,2,7,3,6,4,5].each { |x| cont.insert(x) }
 
27
    cont.to_a == [1, 2, 3, 4, 5, 6, 7, 8, 9]
 
28
    cont = #{container}.new(proc { |a,b| b < a } )
 
29
    cont.insert(1)
 
30
    cont.to_a == [1]
 
31
    i0 = cont.begin()
 
32
    cont.erase(i0) # don't use i0 anymore, it is invalid now
 
33
    cont.to_a == []
 
34
EOF
 
35
end
 
36
    
 
37
def _map(container)
 
38
  swig_assert_each_line(<<EOF, binding)
 
39
    cont = #{container}.new
 
40
    cont['z'] = 9
 
41
    cont['y'] = 1
 
42
    cont['x'] = 8
 
43
    cont['w'] = 2
 
44
    cont.to_a == [['w',2],['x',8],['y',1],['z',9]]
 
45
 
 
46
    cont = #{container}.new(proc { |a,b| b < a } )
 
47
    cont['z'] = 9
 
48
    cont['y'] = 1
 
49
    cont['x'] = 8
 
50
    cont['w'] = 2
 
51
    cont.to_a == [['z',9],['y',1],['x',8],['w',2]]
 
52
EOF
 
53
end
 
54
 
 
55
def test
 
56
  yield method(:_set), Li_std_functors::Set
 
57
  yield method(:_map), Li_std_functors::Map
 
58
end
 
59
 
 
60
# these should fail and not segfault
 
61
begin
 
62
  Li_std_functors::Set.new('sd')
 
63
rescue
 
64
end
 
65
 
 
66
test do |proc, container|
 
67
  proc.call(container)
 
68
end
 
69
 
 
70