mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-12 14:29:31 -06:00
Add ExprMeta type, with two basic tests
This commit is contained in:
@@ -161,53 +161,92 @@ def test_readExpr_invalid():
|
||||
with pytest.raises(pgf.PGFError):
|
||||
pgf.readExpr("->")
|
||||
|
||||
def test_readExpr_equality_int():
|
||||
# expressions: literals
|
||||
|
||||
def test_readExpr_lint_equality():
|
||||
assert pgf.readExpr("123") == pgf.ExprLit(123)
|
||||
|
||||
def test_readExpr_equality_int_neg():
|
||||
def test_readExpr_lint_equality_neg():
|
||||
assert pgf.readExpr("-123") == pgf.ExprLit(-123)
|
||||
|
||||
def test_readExpr_equality_int_big():
|
||||
def test_readExpr_lint_equality_big2():
|
||||
assert pgf.readExpr("774763251095801167872") == pgf.ExprLit(774763251095801167872)
|
||||
|
||||
def test_readExpr_equality_int_big_neg():
|
||||
def test_readExpr_lint_equality_big2_neg():
|
||||
assert pgf.readExpr("-774763251095801167872") == pgf.ExprLit(-774763251095801167872)
|
||||
|
||||
def test_readExpr_inequality_int():
|
||||
def test_readExpr_lint_inequality():
|
||||
assert pgf.readExpr("123") != pgf.ExprLit(456)
|
||||
|
||||
def test_readExpr_equality_float():
|
||||
def test_readExpr_lflt_equality():
|
||||
assert pgf.readExpr("3.142") == pgf.ExprLit(3.142)
|
||||
|
||||
def test_readExpr_inequality_float():
|
||||
def test_readExpr_lflt_inequality():
|
||||
assert pgf.readExpr("3.142") != pgf.ExprLit(3)
|
||||
|
||||
def test_readExpr_equality_string():
|
||||
def test_readExpr_lstr_equality():
|
||||
assert pgf.readExpr("\"abc\"") == pgf.ExprLit("abc")
|
||||
|
||||
def test_readExpr_inequality_string():
|
||||
def test_readExpr_lstr_inequality():
|
||||
assert pgf.readExpr("\"abc\"") != pgf.ExprLit("def")
|
||||
|
||||
def test_readExpr_str_int():
|
||||
def test_readExpr_lint_str():
|
||||
assert str(pgf.readExpr("123")) == "123"
|
||||
|
||||
def test_readExpr_str_int_neg():
|
||||
def test_readExpr_lint_str_neg():
|
||||
assert str(pgf.readExpr("-123")) == "-123"
|
||||
|
||||
def test_readExpr_str_int_big_2():
|
||||
def test_readExpr_lint_str_big2():
|
||||
assert str(pgf.readExpr("774763251095801167872")) == "774763251095801167872"
|
||||
|
||||
def test_readExpr_str_int_big_3():
|
||||
def test_readExpr_lint_str_big3():
|
||||
assert str(pgf.readExpr("7747632510958011678729003251095801167999")) == "7747632510958011678729003251095801167999"
|
||||
|
||||
def test_readExpr_str_int_big_2_neg():
|
||||
def test_readExpr_lint_str_big2_neg():
|
||||
assert str(pgf.readExpr("-774763251095801167872")) == "-774763251095801167872"
|
||||
|
||||
def test_readExpr_str_int_big_3_neg():
|
||||
def test_readExpr_lint_str_big3_neg():
|
||||
assert str(pgf.readExpr("-7747632510958011678729003251095801167999")) == "-7747632510958011678729003251095801167999"
|
||||
|
||||
def test_readExpr_str_float():
|
||||
def test_readExpr_lflt_str():
|
||||
assert str(pgf.readExpr("3.142")) == "3.142"
|
||||
|
||||
def test_readExpr_str_string():
|
||||
def test_readExpr_lstr_str():
|
||||
assert str(pgf.readExpr("\"açġħ\"")) == "\"açġħ\""
|
||||
|
||||
# expressions: functions
|
||||
|
||||
# ,TestCase (assertEqual "show expression 1" "f x y" (showExpr [] (EApp (EApp (EFun "f") (EFun "x")) (EFun "y"))))
|
||||
# ,TestCase (assertEqual "show expression 2" "f (g x)" (showExpr [] (EApp (EFun "f") (EApp (EFun "g") (EFun "x")))))
|
||||
# ,TestCase (assertEqual "show expression 3" "f {g x}" (showExpr [] (EApp (EFun "f") (EImplArg (EApp (EFun "g") (EFun "x"))))))
|
||||
|
||||
# expressions: variables
|
||||
|
||||
# ,TestCase (assertEqual "show expression 4" "x" (showExpr ["x"] (EVar 0)))
|
||||
# ,TestCase (assertEqual "show expression 5" "#1" (showExpr ["x"] (EVar 1)))
|
||||
# ,TestCase (assertEqual "show expression 6" "z" (showExpr ["z","y","x"] (EVar 0)))
|
||||
# ,TestCase (assertEqual "show expression 7" "y" (showExpr ["z","y","x"] (EVar 1)))
|
||||
|
||||
# expressions: lambda abstractions
|
||||
|
||||
# ,TestCase (assertEqual "show expression 8" "\\w->w" (showExpr ["z","y","x"] (EAbs Explicit "w" (EVar 0))))
|
||||
# ,TestCase (assertEqual "show expression 9" "\\v,w->z" (showExpr ["z","y","x"] (EAbs Explicit "v" (EAbs Explicit "w" (EVar 2)))))
|
||||
# ,TestCase (assertEqual "show expression 10" "\\v,{w}->z" (showExpr ["z","y","x"] (EAbs Explicit "v" (EAbs Implicit "w" (EVar 2)))))
|
||||
# ,TestCase (assertEqual "show expression 11" "\\v,{w},z->z" (showExpr ["y","x"] (EAbs Explicit "v" (EAbs Implicit "w" (EAbs Explicit "z" (EVar 0))))))
|
||||
# ,TestCase (assertEqual "show expression 12" "\\v,{w,z}->v" (showExpr ["y","x"] (EAbs Explicit "v" (EAbs Implicit "w" (EAbs Implicit "z" (EVar 2))))))
|
||||
# ,TestCase (assertEqual "show expression 13" "\\v,{w,z},t->v" (showExpr ["y","x"] (EAbs Explicit "v" (EAbs Implicit "w" (EAbs Implicit "z" (EAbs Explicit "t" (EVar 3)))))))
|
||||
# ,TestCase (assertEqual "show expression 14" "\\u,v,{w,z},t->v" (showExpr ["y","x"] (EAbs Explicit "u" (EAbs Explicit "v" (EAbs Implicit "w" (EAbs Implicit "z" (EAbs Explicit "t" (EVar 3))))))))
|
||||
# ,TestCase (assertEqual "show expression 15" "f (\\x->x)" (showExpr [] (EApp (EFun "f") (EAbs Explicit "x" (EVar 0)))))
|
||||
|
||||
# expressions: meta variables
|
||||
|
||||
def test_readExpr_emeta_1():
|
||||
assert pgf.readExpr("?") == pgf.ExprMeta()
|
||||
assert pgf.readExpr("?") == pgf.ExprMeta(0)
|
||||
|
||||
def test_readExpr_emeta_2():
|
||||
assert pgf.readExpr("?42") == pgf.ExprMeta(42)
|
||||
|
||||
# expressions: typed expressions
|
||||
|
||||
# ,TestCase (assertEqual "show expression 18" "<z : N>" (showExpr [] (ETyped (EFun "z") (DTyp [] "N" []))))
|
||||
|
||||
Reference in New Issue
Block a user