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
|
2014-06-13 22:41:45 +02:00
|
|
|
def raise()
|
|
|
|
putstring()
|
|
|
|
exit()
|
|
|
|
end
|
|
|
|
def method_missing(name,args)
|
|
|
|
name.raise()
|
|
|
|
end
|
|
|
|
def class()
|
|
|
|
l = @layout
|
|
|
|
return l.class()
|
|
|
|
end
|
|
|
|
def resolve_method(name)
|
|
|
|
clazz = class()
|
|
|
|
function = clazz._get_instance_variable(name)
|
|
|
|
index = clazz.index_of(name)
|
|
|
|
if( function == 0 )
|
|
|
|
name.raise()
|
|
|
|
else
|
|
|
|
return function
|
|
|
|
end
|
|
|
|
end
|
2014-06-01 20:03:08 +02:00
|
|
|
def index_of( name )
|
2014-06-05 17:17:00 +02:00
|
|
|
l = @layout
|
2015-05-13 15:17:10 +02:00
|
|
|
return l.index_of(name)
|
2014-06-01 20:03:08 +02:00
|
|
|
end
|
2015-05-17 13:41:18 +02:00
|
|
|
def old_layout()
|
2014-06-01 13:24:54 +02:00
|
|
|
return @layout
|
|
|
|
end
|
|
|
|
end
|
2014-06-03 13:49:02 +02:00
|
|
|
class Class
|
|
|
|
def Class.new_object( length )
|
|
|
|
return 4
|
|
|
|
end
|
|
|
|
end
|
2014-05-31 15:43:03 +02:00
|
|
|
class String
|
2014-06-03 13:49:02 +02:00
|
|
|
def String.new_string( len )
|
|
|
|
return Class.new_object( len << 2 )
|
|
|
|
end
|
2014-06-01 13:24:54 +02:00
|
|
|
def length()
|
|
|
|
return @length
|
|
|
|
end
|
|
|
|
def plus(str)
|
2015-05-13 15:17:10 +02:00
|
|
|
my_length = @length
|
2014-05-31 15:43:03 +02:00
|
|
|
str_len = str.length()
|
2014-06-02 12:45:08 +02:00
|
|
|
new_string = String.new_string(my_length + str_len)
|
2014-05-31 15:43:03 +02:00
|
|
|
i = 0
|
2014-06-01 13:24:54 +02:00
|
|
|
while( i < my_length) do
|
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
|
2014-06-01 13:24:54 +02:00
|
|
|
while( i < str_len) do
|
2014-05-31 15:43:03 +02:00
|
|
|
char = str.get(i)
|
|
|
|
new_string.set( i + my_length , char)
|
|
|
|
i = i + 1
|
|
|
|
end
|
2014-06-01 13:24:54 +02:00
|
|
|
return new_string
|
2014-05-31 15:43:03 +02:00
|
|
|
end
|
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
|