added operator override test

This commit is contained in:
pca006132 2020-12-18 16:54:47 +08:00 committed by pca006132
parent 97fdef2488
commit 92c92f6a4c
1 changed files with 29 additions and 0 deletions

View File

@ -3,6 +3,7 @@ from type_def import *
from inference import *
from helper import *
from parse_expr import *
from top_level import *
types = {
'int32': PrimitiveType('int32'),
@ -71,3 +72,31 @@ test_expr('[[1], [2], [3]][a]', {'a': i32})
test_expr('a == a == a', {'a': I})
test_expr('a == a and 1 == 2', {'a': I})
test_classes = """
class Foo:
a: int32
def __init__(self, a: int32):
self.a = a
def __add__(self, other: Foo) -> Foo:
return Foo(self.a + other.a)
def __sub__(self, other: Foo) -> Foo:
return Foo(self.a - other.a)
def __lt__(self, other: Foo) -> bool:
pass
def __le__(self, other: Foo) -> bool:
pass
def __gt__(self, other: Foo) -> bool:
pass
def __ge__(self, other: Foo) -> bool:
pass
"""
ctx, _ = parse_top_level(ctx, ast.parse(test_classes))
test_expr('Foo(1) + Foo(1)', {})
test_expr('Foo(1) + Foo(1) < Foo(2) + Foo(3) < Foo(4)', {})