rubyx/test/fragments/test_string_class.rb

83 lines
1.4 KiB
Ruby
Raw Normal View History

require_relative 'helper'
2014-06-24 11:25:03 +02:00
class TestStringClass < MiniTest::Test
include Fragments
2014-06-24 11:25:03 +02:00
def test_string_class
@string_input = <<HERE
class Object
2015-09-20 16:33:05 +02:00
int raise()
self.putstring()
self.exit()
2014-06-13 22:41:45 +02:00
end
2015-09-20 16:33:05 +02:00
int method_missing(ref name,ref args)
2014-06-13 22:41:45 +02:00
name.raise()
end
2015-09-20 16:33:05 +02:00
ref class()
ref l = self.layout
l = l.object_class()
return l
2014-06-13 22:41:45 +02:00
end
2015-09-20 16:33:05 +02:00
ref resolve_method(ref name)
ref clazz = self.class()
ref function = clazz._get_instance_variable(name)
int index = clazz.index_of(name)
if( function == nil )
2014-06-13 22:41:45 +02:00
name.raise()
else
return function
end
end
2015-09-20 16:33:05 +02:00
int index_of( ref name )
ref l = self.layout
return l.index_of(name)
end
2015-09-20 16:33:05 +02:00
ref old_layout()
return self.layout
end
end
class Class
2015-09-20 16:33:05 +02:00
int Class.new_object( int length )
return 4
end
end
class String
2015-09-20 16:33:05 +02:00
ref self.new_string(int len )
len = len << 2
return super.new_object( len)
end
2015-09-20 16:33:05 +02:00
int length()
return self.length
end
2015-09-20 16:33:05 +02:00
int plus(ref str)
my_length = self.length
str_len = str.length()
2015-09-20 16:33:05 +02:00
my_length = str_len + my_length
new_string = self.new_string(my_length )
i = 0
2015-09-20 16:33:05 +02:00
while( i < my_length)
char = get(i)
new_string.set(i , char)
i = i + 1
end
i = 0
2015-09-20 16:33:05 +02:00
while( i < str_len)
char = str.get(i)
2015-09-20 16:33:05 +02:00
len = i + my_length
new_string.set( len , char)
i = i + 1
end
return new_string
end
2015-09-20 16:33:05 +02:00
end
HERE
2015-07-19 12:31:13 +02:00
@expect = [Virtual::Return ]
check
2014-06-02 12:45:08 +02:00
end
end