Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from topaz.error import RubyError
from topaz.objects.arrayobject import W_ArrayObject
from topaz.objects.bignumobject import W_BignumObject
from topaz.objects.boolobject import W_TrueObject, W_FalseObject
from topaz.objects.boolobject import W_BoolObject
from topaz.objects.floatobject import W_FloatObject
from topaz.objects.intobject import W_FixnumObject
from topaz.objects.moduleobject import W_ModuleObject
Expand All @@ -32,10 +32,8 @@ def unwrap(self, space, w_obj):
return space.bigint_w(w_obj)
elif isinstance(w_obj, W_FloatObject):
return space.float_w(w_obj)
elif isinstance(w_obj, W_TrueObject):
return True
elif isinstance(w_obj, W_FalseObject):
return False
elif isinstance(w_obj, W_BoolObject):
return w_obj.boolvalue
elif isinstance(w_obj, W_StringObject):
return space.str_w(w_obj)
elif isinstance(w_obj, W_SymbolObject):
Expand All @@ -44,10 +42,6 @@ def unwrap(self, space, w_obj):
return [self.unwrap(space, w_x) for w_x in space.listview(w_obj)]
elif isinstance(w_obj, W_ModuleObject):
return w_obj
elif w_obj is space.w_true:
return True
elif w_obj is space.w_false:
return False
elif w_obj is space.w_nil:
return None
raise NotImplementedError(type(w_obj))
31 changes: 31 additions & 0 deletions tests/jit/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,34 @@ def test_method_missing(self, topaz, tmpdir):
setfield_gc(p1, p73, descr=<FieldP topaz.frame.Frame.vable_token 32>)
jump(p0, p1, p3, p4, p5, p7, p10, i75, p19, p22, p24, p30, descr=TargetToken(4310782288))
""")

def test_unroll(self, topaz, tmpdir):
traces = self.run(topaz, tmpdir, """
i = 0
while i < 10000
i += [0, 1].reduce(:+)
end
""")
self.assert_matches(traces[0].loop, """
label(p0, p1, p3, p4, p5, p6, p7, p10, i35, p20, p22, p28, descr=TargetToken(4310781936))
debug_merge_point(0, 0, '<main> at LOAD_DEREF')
debug_merge_point(0, 0, '<main> at LOAD_CONST')
debug_merge_point(0, 0, '<main> at SEND')
setfield_gc(p22, 21, descr=<FieldS topaz.executioncontext.ExecutionContext.inst_last_instr 24>)
guard_not_invalidated(descr=<Guard0x100febda8>)
p37 = force_token()
i38 = int_lt(i35, 10000)
guard_true(i38, descr=<Guard0x100febcb8>)
debug_merge_point(0, 0, '<main> at JUMP_IF_FALSE')
debug_merge_point(0, 0, '<main> at LOAD_DEREF')
debug_merge_point(0, 0, '<main> at LOAD_CONST')
debug_merge_point(0, 0, '<main> at SEND')
p39 = force_token()
i40 = int_add(i35, 1)
debug_merge_point(0, 0, '<main> at STORE_DEREF')
debug_merge_point(0, 0, '<main> at DISCARD_TOP')
debug_merge_point(0, 0, '<main> at JUMP')
debug_merge_point(0, 0, '<main> at LOAD_DEREF')
setfield_gc(p22, 35, descr=<FieldS topaz.executioncontext.ExecutionContext.inst_last_instr 24>)
jump(p0, p1, p3, p4, p5, p6, p7, p10, i40, p20, p22, p28, descr=TargetToken(4310781936))
""")
31 changes: 17 additions & 14 deletions tests/modules/test_comparable.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,52 @@
class TestComparable(object):
from ..base import BaseTopazTest


class TestComparable(BaseTopazTest):
def test_name(self, space):
space.execute("Comparable")

def test_gt(self, space):
w_res = space.execute("return 'a' > 'b'")
assert w_res is space.w_false
assert self.unwrap(space, w_res) is False

def test_lt(self, space):
w_res = space.execute("return 'a' < 'b'")
assert w_res is space.w_true
assert self.unwrap(space, w_res) is True

def test_le(self, space):
w_res = space.execute("return 'b' <= 'b'")
assert w_res is space.w_true
assert self.unwrap(space, w_res) is True
w_res = space.execute("return 'a' <= 'b'")
assert w_res is space.w_true
assert self.unwrap(space, w_res) is True
w_res = space.execute("return 'c' <= 'b'")
assert w_res is space.w_false
assert self.unwrap(space, w_res) is False

def test_ge(self, space):
w_res = space.execute("return 'c' >= 'b'")
assert w_res is space.w_true
assert self.unwrap(space, w_res) is True

def test_eqeq(self, space):
w_res = space.execute("return 'a' == 'a'")
assert w_res is space.w_true
assert self.unwrap(space, w_res) is True

def test_not_eqeq(self, space):
w_res = space.execute("return 'a' == 'b'")
assert w_res is space.w_false
assert self.unwrap(space, w_res) is False

def test_between_true(self, space):
w_res = space.execute("return 'c'.between?('b', 'd')")
assert w_res is space.w_true
assert self.unwrap(space, w_res) is True

def test_between_false_low(self, space):
w_res = space.execute("return 'a'.between?('b', 'd')")
assert w_res is space.w_false
assert self.unwrap(space, w_res) is False

def test_between_false_high(self, space):
w_res = space.execute("return 'e'.between?('b', 'd')")
assert w_res is space.w_false
assert self.unwrap(space, w_res) is False

def test_between_equal(self, space):
w_res = space.execute("return 'e'.between?('e', 'z')")
assert w_res is space.w_true
assert self.unwrap(space, w_res) is True
w_res = space.execute("return 'e'.between?('a', 'e')")
assert w_res is space.w_true
assert self.unwrap(space, w_res) is True
16 changes: 8 additions & 8 deletions tests/modules/test_enumerable.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,41 +41,41 @@ def test_all(self, space):
word.length > 2
end
""")
assert w_res is space.w_true
assert self.unwrap(space, w_res) is True

def test_all_false(self, space):
w_res = space.execute("""
return ["ant", "bear", "cat"].all? do |word|
word.length > 3
end
""")
assert w_res is space.w_false
assert self.unwrap(space, w_res) is False

def test_all_empty(self, space):
w_res = space.execute("""
return [].all?
""")
assert w_res is space.w_true
assert self.unwrap(space, w_res) is True

def test_all_no_block(self, space):
w_res = space.execute("""
return [1, 2, 3].all?
""")
assert w_res is space.w_true
assert self.unwrap(space, w_res) is True

def test_any(self, space):
w_res = space.execute("""
return ["ant", "bear", "cat"].any? do |word|
word.length > 2
end
""")
assert w_res is space.w_true
assert self.unwrap(space, w_res) is True

def test_any_false(self, space):
w_res = space.execute("""
return [nil, nil, nil].any?
""")
assert w_res is space.w_false
assert self.unwrap(space, w_res) is False

def test_select(self, space):
w_res = space.execute("""
Expand All @@ -87,12 +87,12 @@ def test_include(self, space):
w_res = space.execute("""
return (2..5).include? 12
""")
assert w_res is space.w_false
assert self.unwrap(space, w_res) is False

w_res = space.execute("""
return (2..3).include? 2
""")
assert w_res is space.w_true
assert self.unwrap(space, w_res) is True

def test_drop(self, space):
w_res = space.execute("""return [0, 1, 2, 3, 4, 5, 6, 7].drop 3""")
Expand Down
25 changes: 15 additions & 10 deletions tests/modules/test_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_lambda(self, space):
""")
w_cls, w_lambda = space.listview(w_res)
assert w_cls is space.w_proc
assert w_lambda is space.w_true
assert self.unwrap(space, w_lambda) is True

def test_proc(self, space):
w_res = space.execute("""
Expand All @@ -38,7 +38,7 @@ def test_proc(self, space):
""")
w_cls, w_lambda = space.listview(w_res)
assert w_cls is space.w_proc
assert w_lambda is space.w_false
assert self.unwrap(space, w_lambda) is False

def test_singleton_methods(self, space):
w_res = space.execute("""
Expand Down Expand Up @@ -137,9 +137,14 @@ def test_exit(self, space):
space.execute("exit")

def test_block_given_p(self, space):
assert space.execute("return block_given?") is space.w_false
assert space.execute("return iterator?") is space.w_false
assert space.execute("return (proc { block_given? })[]") is space.w_false
w_res = space.execute("return block_given?")
assert self.unwrap(space, w_res) is False

w_res = space.execute("return iterator?")
assert self.unwrap(space, w_res) is False

w_res = space.execute("return (proc { block_given? })[]")
assert self.unwrap(space, w_res) is False
w_res = space.execute("""
def foo
block_given?
Expand Down Expand Up @@ -304,15 +309,15 @@ def t(a, b)
assert space.int_w(w_res) == -9

def test_load_path(self, space, tmpdir):
f = tmpdir.join("t.rb")
f = tmpdir.join("abc.rb")
f.write("""
def t(a, b)
a - b
end
""")
w_res = space.execute("""
$LOAD_PATH[0..-1] = ['%s']
require 't.rb'
require 'abc.rb'

return t(2, 5)
""" % tmpdir)
Expand All @@ -322,7 +327,7 @@ def test_stdlib_default_load_path(self, space):
w_res = space.execute("""
return require 'prettyprint'
""")
assert w_res is space.w_true
assert self.unwrap(space, w_res) is True

def test_nonexistance(self, space):
with self.raises(space, "LoadError"):
Expand Down Expand Up @@ -396,7 +401,7 @@ def to_path
require 't'
return $success
""" % tmpdir)
assert w_res is space.w_true
assert self.unwrap(space, w_res) is True

def test_path_ambigious_directory_file(self, space, tmpdir):
f = tmpdir.join("t.rb")
Expand All @@ -409,7 +414,7 @@ def test_path_ambigious_directory_file(self, space, tmpdir):
require '%s'
return $success
""" % (tmpdir, tmpdir.join("t")))
assert w_res is space.w_true
assert self.unwrap(space, w_res) is True


class TestExec(BaseTopazTest):
Expand Down
6 changes: 4 additions & 2 deletions tests/modules/test_objectspace.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from rpython.rlib import rgc

from ..base import BaseTopazTest

class TestObjectSpace(object):

class TestObjectSpace(BaseTopazTest):
def test_name(self, space):
space.execute("ObjectSpace")

Expand All @@ -18,4 +20,4 @@ class X
end
return names.include? "X"
""")
assert w_res is space.w_true
assert self.unwrap(space, w_res) is True
10 changes: 5 additions & 5 deletions tests/objects/test_arrayobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ def test_length(self, space):

def test_emptyp(self, space):
w_res = space.execute("return [].empty?")
assert w_res is space.w_true
assert self.unwrap(space, w_res) is True
w_res = space.execute("return [1].empty?")
assert w_res is space.w_false
assert self.unwrap(space, w_res) is False

def test_plus(self, space):
w_res = space.execute("return [1, 2] + [3]")
Expand Down Expand Up @@ -321,11 +321,11 @@ def test_eq(self, space):

def test_eqlp(self, space):
w_res = space.execute("return [].eql? 2")
assert w_res is space.w_false
assert self.unwrap(space, w_res) is False
w_res = space.execute("return [0].eql? [0.0]")
assert w_res is space.w_false
assert self.unwrap(space, w_res) is False
w_res = space.execute("return [0].eql? [0]")
assert w_res is space.w_true
assert self.unwrap(space, w_res) is True

def test_clear(self, space):
w_res = space.execute("""
Expand Down
8 changes: 4 additions & 4 deletions tests/objects/test_bignumobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ def test_xor(self, space):

def test_eq(self, space):
w_res = space.execute("return 18446744073709551628 == 18446744073709551628")
assert w_res is space.w_true
assert self.unwrap(space, w_res) is True
w_res = space.execute("return 18446744073709551628 == 18446744073709551629")
assert w_res is space.w_false
assert self.unwrap(space, w_res) is False

def test_comparator(self, space):
w_res = space.execute("return 18446744073709551628 <=> 2")
assert space.int_w(w_res) == 1

def test_hash(self, space):
w_res = space.execute("return 18446744073709551628.hash == 18446744073709551628.hash")
assert w_res is space.w_true
assert self.unwrap(space, w_res) is True
w_res = space.execute("return 18446744073709551628.hash == 18446744073709551658.hash")
assert w_res is space.w_false
assert self.unwrap(space, w_res) is False

def test_coerce(self, space):
w_res = space.execute("return 18446744073709551628.coerce 12")
Expand Down
Loading