Skip to content

Commit

Permalink
Fixed toplevel Ruby constants
Browse files Browse the repository at this point in the history
  • Loading branch information
danlucraft committed Jun 10, 2008
1 parent a9ee07c commit 0e6cef2
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 44 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Expand Up @@ -34,4 +34,9 @@ test/simple/mkmf.log
test/simple/src/simple_rb.c
test/simple/src/simple_rb.o
test/simple/src/simple_rb.so
test/simple/src/semantic.cache
test/simple/src/semantic.cache
test/embed/embed.gidl
test/embed/embed.h
test/embed/embed.c
test/embed/embed.vapi
test/embed/embed
1 change: 1 addition & 0 deletions TODO
@@ -1,4 +1,5 @@

o complex type conversions
o iterators for array
o Make use of the faster type checks FIXNUM_P.
o Data members can be nullable
Expand Down
27 changes: 14 additions & 13 deletions lib/library.rb
Expand Up @@ -87,20 +87,22 @@ def self.new_from_vapi(filename)
end
end
when /public (\w+ )*([\w\.\?]+) (\w+) \((.*)\);/
params = $4
keywords = $1
new_meth = ValaMethod.new
new_meth.name = $3
new_meth.returns = ValaType.parse($2)
new_meth.static = (keywords and keywords.include?("static"))
if params
params.split(", ").each do |param_str|
type_def, arg_name = param_str.split(" ")
new_meth.params << [ValaType.parse(type_def), arg_name]
unless $1 and $1.include? "signal"
params = $4
keywords = $1
new_meth = ValaMethod.new
new_meth.name = $3
new_meth.returns = ValaType.parse($2)
new_meth.static = (keywords and keywords.include?("static"))
if params
params.split(", ").each do |param_str|
type_def, arg_name = param_str.split(" ")
new_meth.params << [ValaType.parse(type_def), arg_name]
end
end
new_meth.obj = current_obj
current_obj.functions << new_meth
end
new_meth.obj = current_obj
current_obj.functions << new_meth
when /public (\w+ )*([\w\.\?]+) (\w+) \{(.*)\}/
# property - automatically handled by ruby-glib
when /public (\w+ )*([\w\.\?]+) (\w+);/
Expand Down Expand Up @@ -163,7 +165,6 @@ def output

fout.puts <<END
void Init_#{@name}_rb() {
VALUE m_vala = rb_define_class("Vala", rb_cObject);
END
@objects.sort_by{|o| o.vala_typename.length}.each do |obj|
obj.output_definition(fout) if obj.convertible?
Expand Down
4 changes: 2 additions & 2 deletions lib/object.rb
Expand Up @@ -9,7 +9,7 @@ def initialize
end

def convertible?
descends_from? "GLib.Object"
descends_from? "GLib.Object" or abstract
end

def object(name)
Expand Down Expand Up @@ -174,7 +174,7 @@ def output_definition(fout)
END
else
fout.puts <<END
rbc_#{underscore_typename} = G_DEF_CLASS(#{underscore_typename}_get_type(), "#{name}", m_vala);
rbc_#{underscore_typename} = G_DEF_CLASS(#{underscore_typename}_get_type(), "#{name}", rb_cObject);
END
end
fout.puts <<END
Expand Down
6 changes: 3 additions & 3 deletions test/test_simple.rb
Expand Up @@ -6,9 +6,9 @@

class TestVala < Test::Unit::TestCase
def test_gobjects
assert Vala::Simple
assert Vala::Simple.new(3)
assert_equal 7, Vala::Simple.new(8).seven
assert Simple
assert Simple.new(3)
assert_equal 7, Simple.new(8).seven
end

# def test_objects
Expand Down
50 changes: 25 additions & 25 deletions test/test_vlib.rb
Expand Up @@ -5,88 +5,88 @@

class TestVala < Test::Unit::TestCase
def test_array_get_length
assert_equal 3, Vala::VLib.new.get_length([1, 2, 3, ])
assert_equal 3, VLib.new.get_length([1, 2, 3, ])
end

def test_string_get_length
assert_equal 3, Vala::VLib.new.get_str_length("asd")
assert_equal 3, VLib.new.get_str_length("asd")
end

# if --no-type-checks, these segfault:
def test_type_checks_work
assert_raises(ArgumentError) {
Vala::VLib.new.get_length(10)
VLib.new.get_length(10)
}
assert_raises(ArgumentError) {
Vala::VLib.new.get_str_length(10)
VLib.new.get_str_length(10)
}
Vala::VLib.new.sum_3(10, 4, 2.0)
VLib.new.sum_3(10, 4, 2.0)
assert_raises(ArgumentError) {
Vala::VLib.new.sum_3(10, 4, 2)
VLib.new.sum_3(10, 4, 2)
}
assert_raises(ArgumentError) {
Vala::VLib.new.sum_3(10.9, 4, 2.0)
VLib.new.sum_3(10.9, 4, 2.0)
}
end

def test_ary_new
a = Vala::VLib.new.get_ary
a = VLib.new.get_ary
assert_equal Array, a.class
assert_equal 0, a.length
end

def test_id
assert_equal false, Vala::VLib.new.responds_to_length(1)
assert_equal true, Vala::VLib.new.responds_to_length([1, 2, 3])
assert_equal false, VLib.new.responds_to_length(1)
assert_equal true, VLib.new.responds_to_length([1, 2, 3])
end

def test_hash
h = {}
Vala::VLib.new.set_foo(h)
VLib.new.set_foo(h)
assert_equal 123, h["foo"]
end

# these test conversions
def test_times_2
assert_equal 264, Vala::VLib.new.times_2(132)
assert_equal 74, Vala::VLib.new.times_2(37)
assert_equal 264, VLib.new.times_2(132)
assert_equal 74, VLib.new.times_2(37)
end

def test_vala_length
assert_equal 4, Vala::VLib.new.vala_length("asdf")
assert_equal 7, Vala::VLib.new.vala_length("asdf123")
assert_equal 4, VLib.new.vala_length("asdf")
assert_equal 7, VLib.new.vala_length("asdf123")
end

def test_static_methods
assert_equal 7, Vala::VLib.add1(3, 4)
assert_equal 7, VLib.add1(3, 4)
end

def test_nullable_return_values
assert_equal "adama", Vala::VLib.maybe_string(100)
assert_equal nil, Vala::VLib.maybe_string(1)
assert_equal "adama", VLib.maybe_string(100)
assert_equal nil, VLib.maybe_string(1)
end

def test_nullable_arguments
assert_equal 0, Vala::VLib.maybe_length(nil)
assert_equal 5, Vala::VLib.maybe_length("adama")
assert_equal 0, VLib.maybe_length(nil)
assert_equal 5, VLib.maybe_length("adama")
assert_raises(ArgumentError) {
Vala::VLib.maybe_length(19)
VLib.maybe_length(19)
}
end

def test_simple_property
vl = Vala::VLib.new
vl = VLib.new
vl.anint = 10
assert_equal 10, vl.anint
end

def test_boolean_conversion
assert_equal true, Vala::VLib.invert(false)
assert_equal false, Vala::VLib.invert(true)
assert_equal true, VLib.invert(false)
assert_equal false, VLib.invert(true)
end

def signals
v = Vala::VLib.new
v = VLib.new
foo = nil
v.signal_connect("sig_1") do |val|
foo = val
Expand Down

0 comments on commit 0e6cef2

Please sign in to comment.