more word tests
This commit is contained in:
parent
0731a6061a
commit
a46dd9f6bf
@ -59,4 +59,15 @@ module Parfait
|
||||
end
|
||||
word
|
||||
end
|
||||
Word.class_eval do
|
||||
def to_s
|
||||
string = ""
|
||||
index = 0
|
||||
while( index < self.length)
|
||||
string[index] = get_char(index).chr
|
||||
index = index + 1
|
||||
end
|
||||
string
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -61,7 +61,7 @@ module Parfait
|
||||
return false if other.class != self.class
|
||||
return false if other.length != self.length
|
||||
len = self.length
|
||||
while len
|
||||
while(len >= 0)
|
||||
return false if self.get_char(len) != other.get_char(len)
|
||||
len = len - 1
|
||||
end
|
||||
|
@ -3,84 +3,90 @@ require_relative "../helper"
|
||||
class TestEmptyWord < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@list = ::Parfait::Word.new_object(0)
|
||||
@word = ::Parfait::Word.new_object(0)
|
||||
end
|
||||
def def_same
|
||||
assert_equal @word , ::Parfait::Word.new_object(0)
|
||||
end
|
||||
def test_list_create
|
||||
assert @list.empty?
|
||||
assert @word.empty?
|
||||
end
|
||||
def test_empty_is_zero
|
||||
assert_equal 0 , @list.length
|
||||
assert_equal 0 , @word.length
|
||||
end
|
||||
def test_index_check_get
|
||||
assert_raises RuntimeError do
|
||||
@list.get_char(1)
|
||||
@word.get_char(1)
|
||||
end
|
||||
end
|
||||
def test_index_check_set
|
||||
assert_raises RuntimeError do
|
||||
@list.set_char(1 , 32)
|
||||
@word.set_char(1 , 32)
|
||||
end
|
||||
end
|
||||
end
|
||||
class TestWord < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@list = ::Parfait::Word.new_object(5)
|
||||
@word = ::Parfait::Word.new_object(5)
|
||||
end
|
||||
def test_len
|
||||
assert_equal 5 , @list.length
|
||||
assert_equal 5 , @word.length
|
||||
end
|
||||
def def_same
|
||||
assert_equal @word , ::Parfait::Word.new_object(5)
|
||||
end
|
||||
def test_index_check_get
|
||||
assert_raises RuntimeError do
|
||||
@list.get_char(-6)
|
||||
@word.get_char(-6)
|
||||
end
|
||||
end
|
||||
def test_index_check_set
|
||||
assert_raises RuntimeError do
|
||||
@list.set_char(6 , 32)
|
||||
@word.set_char(6 , 32)
|
||||
end
|
||||
end
|
||||
def test_index_check_get
|
||||
assert_raises RuntimeError do
|
||||
@list.get_char(6)
|
||||
@word.get_char(6)
|
||||
end
|
||||
end
|
||||
def test_index_check_set
|
||||
assert_raises RuntimeError do
|
||||
@list.set_char(-6 , 32)
|
||||
@word.set_char(-6 , 32)
|
||||
end
|
||||
end
|
||||
def pest_one_char
|
||||
assert 32 , @list.set_char(1 , 32)
|
||||
assert 32 , @word.set_char(1 , 32)
|
||||
end
|
||||
def pest_empty_list_doesnt_return
|
||||
assert_equal nil , @list.get(3)
|
||||
assert_equal nil , @word.get(3)
|
||||
end
|
||||
def pest_one_set0
|
||||
assert_equal 1 , @list.set(0,1)
|
||||
assert_equal 1 , @word.set(0,1)
|
||||
end
|
||||
def pest_one_set1
|
||||
assert_equal :some , @list.set(1,:some)
|
||||
assert_equal :some , @word.set(1,:some)
|
||||
end
|
||||
def pest_two_sets
|
||||
assert_equal 1 , @list.set(0,1)
|
||||
assert_equal :some , @list.set(1,:some)
|
||||
assert_equal 1 , @word.set(0,1)
|
||||
assert_equal :some , @word.set(1,:some)
|
||||
end
|
||||
def pest_one_get1
|
||||
pest_one_set0
|
||||
assert_equal 1 , @list.get(0)
|
||||
assert_equal 1 , @word.get(0)
|
||||
end
|
||||
def pest_one_get2
|
||||
pest_one_set1
|
||||
assert_equal :some , @list.get(1)
|
||||
assert_equal :some , @word.get(1)
|
||||
end
|
||||
def pest_many_get
|
||||
shouldda = { 1 => :one , 2 => :two , 3 => :three}
|
||||
shouldda.each do |k,v|
|
||||
@list.set(k,v)
|
||||
@word.set(k,v)
|
||||
end
|
||||
shouldda.each do |k,v|
|
||||
assert_equal v , @list.get(k)
|
||||
assert_equal v , @word.get(k)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
58
test/virtual/test_conversion.rb
Normal file
58
test/virtual/test_conversion.rb
Normal file
@ -0,0 +1,58 @@
|
||||
require_relative "../helper"
|
||||
|
||||
class TestConversion < MiniTest::Test
|
||||
|
||||
def pest_number
|
||||
@string_input = '42 '
|
||||
@output = "-Virtual::Return(:index => 5, :type => Virtual::Integer)*^* :value Virtual::IntegerConstant(:integer => 42)"
|
||||
check
|
||||
end
|
||||
|
||||
def pest_true
|
||||
@string_input = 'true '
|
||||
@output = "-Virtual::Return(:index => 5, :type => Virtual::Reference)*^* :value Virtual::TrueConstant(:length => -1)"
|
||||
check
|
||||
end
|
||||
def pest_false
|
||||
@string_input = 'false '
|
||||
@output = "-Virtual::Return(:index => 5, :type => Virtual::Reference)*^* :value Virtual::FalseConstant(:length => -1)"
|
||||
check
|
||||
end
|
||||
def pest_nil
|
||||
@string_input = 'nil '
|
||||
@output = "-Virtual::Return(:index => 5, :type => Virtual::Reference)*^* :value Virtual::NilConstant(:length => -1)"
|
||||
check
|
||||
end
|
||||
|
||||
def pest_name
|
||||
@string_input = 'foo '
|
||||
@output = "-Virtual::Return(:index => 5, :type => Virtual::Mystery)"
|
||||
check
|
||||
end
|
||||
|
||||
def pest_self
|
||||
@string_input = 'self '
|
||||
@output = "-Virtual::Self(:index => 3, :type => Virtual::Mystery)"
|
||||
check
|
||||
end
|
||||
|
||||
def pest_instance_variable
|
||||
@string_input = '@foo_bar '
|
||||
@output = "-Virtual::Return(:index => 5, :type => Virtual::Mystery)"
|
||||
check
|
||||
end
|
||||
|
||||
def pest_module_name
|
||||
@string_input = 'FooBar '
|
||||
@output = "---RETURN_MARKER- &1 !ruby/object:Boot::BootClassRETURN_MARKER instance_methods: []RETURN_MARKER name: :FooBarRETURN_MARKER super_class_name: :ObjectRETURN_MARKER meta_class: !ruby/object:Boot::MetaClassRETURN_MARKER functions: []RETURN_MARKER me_self: *1RETURN_MARKER"
|
||||
check
|
||||
end
|
||||
|
||||
def test_string
|
||||
string = "hello"
|
||||
word = Parfait.new_word string
|
||||
assert_equal word , Parfait.new_word(string)
|
||||
assert_equal string , word.to_s
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue
Block a user