Type initialiser accepts sequences, stores internally as tuples. Add tests which try to break things.

This commit is contained in:
John J. Camilleri
2021-09-28 11:58:22 +02:00
parent 388829d63d
commit 16eb5f1a89
7 changed files with 162 additions and 112 deletions

View File

@@ -219,9 +219,11 @@ def test_Type_getters():
h0 = mkDepHypo("x", Type([], "N", []))
e0 = ExprVar(0)
type = Type([h0], "N", [e0])
assert type.hypos == [h0]
assert len(type.hypos) == 1
assert type.hypos[0] == h0
assert type.cat == "N"
assert type.exprs == [e0]
assert len(type.exprs) == 1
assert type.exprs[0] == e0
with pytest.raises(AttributeError):
type.fake

View File

@@ -0,0 +1,35 @@
import os
import pytest
from pgf import *
@pytest.fixture(scope="module")
def PGF():
return readPGF("../haskell/tests/basic.pgf")
def test_init_Type_tuples():
hypos = [mkDepHypo("x", Type([], "N", []))]
exprs = [ExprVar(0)]
ty = Type(tuple(hypos), "P", tuple(exprs))
assert str(ty) == "(x : N) -> P x"
def test_init_Type_lists():
hypos = [mkDepHypo("x", Type([], "N", []))]
exprs = [ExprVar(0)]
ty = Type(hypos, "P", exprs)
assert str(ty) == "(x : N) -> P x"
def test_Type_modify_shallow():
hypos = [(BIND_TYPE_EXPLICIT, "x", Type([], "N", []))]
exprs = [ExprVar(0)]
ty = Type(hypos, "P", exprs)
hypos.append(None)
assert str(ty) == "(x : N) -> P x"
def test_Type_modify_deep():
hypos = [(BIND_TYPE_EXPLICIT, "x", Type([], "N", []))]
exprs = [ExprVar(0)]
ty = Type(hypos, "P", exprs)
with pytest.raises(AttributeError):
hypos[0][2].exprs.append(None)
assert str(ty) == "(x : N) -> P x"