def test_ll_union(): PS1 = lltype.Ptr(lltype.GcStruct('s')) PS2 = lltype.Ptr(lltype.GcStruct('s')) PS3 = lltype.Ptr(lltype.GcStruct('s3')) PA1 = lltype.Ptr(lltype.GcArray()) PA2 = lltype.Ptr(lltype.GcArray()) assert union(SomePtr(PS1), SomePtr(PS1)) == SomePtr(PS1) assert union(SomePtr(PS1), SomePtr(PS2)) == SomePtr(PS2) assert union(SomePtr(PS1), SomePtr(PS2)) == SomePtr(PS1) assert union(SomePtr(PA1), SomePtr(PA1)) == SomePtr(PA1) assert union(SomePtr(PA1), SomePtr(PA2)) == SomePtr(PA2) assert union(SomePtr(PA1), SomePtr(PA2)) == SomePtr(PA1) assert union(SomePtr(PS1), SomeImpossibleValue()) == SomePtr(PS1) assert union(SomeImpossibleValue(), SomePtr(PS1)) == SomePtr(PS1) with py.test.raises(UnionError): union(SomePtr(PA1), SomePtr(PS1)) with py.test.raises(UnionError): union(SomePtr(PS1), SomePtr(PS3)) with py.test.raises(UnionError): union(SomePtr(PS1), SomeInteger()) with py.test.raises(UnionError): union(SomeInteger(), SomePtr(PS1))
def method_join(self, s_list): if s_None.contains(s_list): return SomeImpossibleValue() s_item = s_list.listdef.read_item() if s_None.contains(s_item): if isinstance(self, SomeUnicodeString): return immutablevalue(u"") return immutablevalue("") no_nul = self.no_nul and s_item.no_nul return self.basestringclass(no_nul=no_nul)
def len(self): # This None could later be generalized into a list, for example. # For now, we give the impossible answer (because len(None) would # really crash translated code). It can be generalized later. return SomeImpossibleValue()
def method_update(dct1, dct2): if s_None.contains(dct2): return SomeImpossibleValue() dct1.dictdef.union(dct2.dictdef)