2014-05-31 11:52:29 +02:00
|
|
|
require_relative 'helper'
|
|
|
|
|
2014-06-24 11:25:03 +02:00
|
|
|
class TestStringClass < MiniTest::Test
|
2014-05-31 11:52:29 +02:00
|
|
|
include Fragments
|
|
|
|
|
2014-06-24 11:25:03 +02:00
|
|
|
def test_string_class
|
2014-05-31 11:52:29 +02:00
|
|
|
@string_input = <<HERE
|
2014-06-01 13:24:54 +02:00
|
|
|
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
|
2015-05-13 15:17:10 +02:00
|
|
|
return l.index_of(name)
|
2014-06-01 20:03:08 +02:00
|
|
|
end
|
2015-09-20 16:33:05 +02:00
|
|
|
ref old_layout()
|
|
|
|
return self.layout
|
2014-06-01 13:24:54 +02:00
|
|
|
end
|
|
|
|
end
|
2014-06-03 13:49:02 +02:00
|
|
|
class Class
|
2015-09-20 16:33:05 +02:00
|
|
|
int Class.new_object( int length )
|
2014-06-03 13:49:02 +02:00
|
|
|
return 4
|
|
|
|
end
|
|
|
|
end
|
2014-05-31 15:43:03 +02:00
|
|
|
class String
|
2015-09-20 16:33:05 +02:00
|
|
|
|
|
|
|
ref self.new_string(int len )
|
|
|
|
len = len << 2
|
|
|
|
return super.new_object( len)
|
2014-06-03 13:49:02 +02:00
|
|
|
end
|
2015-09-20 16:33:05 +02:00
|
|
|
|
|
|
|
int length()
|
|
|
|
return self.length
|
2014-06-01 13:24:54 +02:00
|
|
|
end
|
2015-09-20 16:33:05 +02:00
|
|
|
|
|
|
|
int plus(ref str)
|
|
|
|
my_length = self.length
|
2014-05-31 15:43:03 +02:00
|
|
|
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 )
|
2014-05-31 15:43:03 +02:00
|
|
|
i = 0
|
2015-09-20 16:33:05 +02:00
|
|
|
while( i < my_length)
|
2014-06-03 13:49:02 +02:00
|
|
|
char = get(i)
|
2014-05-31 15:43:03 +02:00
|
|
|
new_string.set(i , char)
|
|
|
|
i = i + 1
|
|
|
|
end
|
|
|
|
i = 0
|
2015-09-20 16:33:05 +02:00
|
|
|
while( i < str_len)
|
2014-05-31 15:43:03 +02:00
|
|
|
char = str.get(i)
|
2015-09-20 16:33:05 +02:00
|
|
|
len = i + my_length
|
|
|
|
new_string.set( len , char)
|
2014-05-31 15:43:03 +02:00
|
|
|
i = i + 1
|
|
|
|
end
|
2014-06-01 13:24:54 +02:00
|
|
|
return new_string
|
2014-05-31 15:43:03 +02:00
|
|
|
end
|
2015-09-20 16:33:05 +02:00
|
|
|
|
2014-05-31 11:52:29 +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
|
|
|
|
|
2014-05-31 11:52:29 +02:00
|
|
|
end
|