def test_retrieve_symbol(): """asSymbol "This is the only place that new Symbols are created. A Symbol is created if and only if there is not already a Symbol with its contents in existance." Symbol allInstancesDo: [ :sym | self = sym ifTrue: [ ^ sym ] ]. ^ (Symbol basicNew: self size) initFrom: self""" w_result = perform(w("someString"), "asSymbol") assert w_result.as_string() == "someString" w_anotherSymbol = perform(w("someString"), "asSymbol") assert w_result is w_anotherSymbol
def test_ensure_save_original_nlr(): #ensure # [^'b1'] ensure: ['b2'] import operator bytes = reduce(operator.add, map(chr, [0x8F, 0, 0, 2, 0x21, 0x7c, 0x8F, 0, 0, 2, 0x22, 0x7d, 0xe0, 0x87, 0x78])) s_class = space.w_BlockClosure.as_class_get_shadow(space) ensure_ = find_symbol_in_methoddict_of('ensure:', s_class) assert ensure_ is not None, 'Using image without #ensure:-method.' s_method = create_method_shadow(bytes, [ensure_, w('b1'), w('b2'), w('ensure'), space.w_BlockClosure]) # create a frame for our newly crafted method with a valid sender (to avoid raising returnFromTop to early) s_initial_frame = create_method_shadow(chr(0x7c)).create_frame(space, w(0), []) w_frame = s_method.create_frame(space, w(0), [], sender=s_initial_frame).w_self() try: interp.loop(w_frame) except interpreter.ReturnFromTopLevel, e: assert e.object.as_string() == 'b1'
def do_primitive(selector, operation, i=None, j=None, trace=False): candidates = i if i is not None else [0x1FFFFFFF, 0x3FFFFFFF, 0x7FFFFFFF] try: w_selector = space.get_special_selector(selector) except Exception: w_selector = find_symbol_in_methoddict_of(selector, w(intmask(candidates[0])).getclass(space)._shadow) interp.trace=trace for i, v in enumerate(candidates): x = w_l(v) if j is None: y = x else: if isinstance(j, list): y = w_l(j[i]) else: y = w_l(j) z = perform_primitive(x, w_selector, y) assert r_uint(z.value) == r_uint(operation(v, y.value)) interp.trace=False
def do_primitive(selector, operation, i=None, j=None, trace=False): candidates = i if i is not None else [0x1FFFFFFF, 0x3FFFFFFF, 0x7FFFFFFF] try: w_selector = space.get_special_selector(selector) except Exception: w_selector = find_symbol_in_methoddict_of( selector, w(intmask(candidates[0])).getclass(space)._shadow) interp.trace = trace for i, v in enumerate(candidates): x = w_l(v) if j is None: y = x else: if isinstance(j, list): y = w_l(j[i]) else: y = w_l(j) z = perform_primitive(x, w_selector, y) assert r_uint(z.value) == r_uint(operation(v, y.value)) interp.trace = False
def test_initialize_string_class(): interp.trace = False #initialize String class, because equality testing requires a class var set. initialize_class(w("string").getclass(tools.space))
def test_create_new_symbol(): py.test.skip("This test takes quite long and is actually included in test_retrieve_symbol.") w_result = perform(w("someString"), "asSymbol") assert w_result is not None assert w_result.as_string() == "someString"
def test_initialize_string_class(): #initialize String class, because equality testing requires a class var set. initialize_class(w("string").getclass(tools.space))