erg/tests/should_ok/class.er
2024-02-08 02:42:49 +09:00

33 lines
554 B
Python

unittest = pyimport "unittest"
Test! = Inherit unittest.TestCase!
_ = Test!
# forward reference
C = Class { .x = D }
C|<: Eq|.
`==` self, other = self.x == other.x
C.
foo self, x = self.x.foo(x)
D = Class { .y = Int }
D.
new y = Self { .y; }
@staticmethod
foo x = x + 1
one = Self.new 1
D|<: Eq|.
`==` self, other = self.y == other.y
d = D.new 1
assert d.foo(1) == 2
c = C.new { .x = D.new(1) }
assert c.x.y == 1
Vec = Class [Int; _]
Vec.
sum self =
sum(self::base)
v = Vec.new [1, 2, 3]
assert v.sum() == 6