forked from GitHub/gf-core
Add constructor for ExprLit, use it in tests
This commit is contained in:
@@ -125,6 +125,29 @@ PyTypeObject pgf_ExprType = {
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static ExprLitObject *
|
||||||
|
ExprLit_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
|
||||||
|
{
|
||||||
|
ExprLitObject* self = (ExprLitObject *)subtype->tp_alloc(subtype, 0);
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
ExprLit_init(ExprLitObject *self, PyObject *args, PyObject *kwds)
|
||||||
|
{
|
||||||
|
PyObject* lit = NULL;
|
||||||
|
if (!PyArg_ParseTuple(args, "O", &lit)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (PyLong_Check(lit) || PyFloat_Check(lit) || PyUnicode_Check(lit)) {
|
||||||
|
self->value = lit;
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
PyErr_SetString(PyExc_TypeError, "invalid argument in ExprLit_init");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
ExprLit_richcompare(ExprLitObject *t1, ExprLitObject *t2, int op)
|
ExprLit_richcompare(ExprLitObject *t1, ExprLitObject *t2, int op)
|
||||||
{
|
{
|
||||||
@@ -197,9 +220,9 @@ PyTypeObject pgf_ExprLitType = {
|
|||||||
0, /*tp_descr_get */
|
0, /*tp_descr_get */
|
||||||
0, /*tp_descr_set */
|
0, /*tp_descr_set */
|
||||||
0, /*tp_dictoffset */
|
0, /*tp_dictoffset */
|
||||||
0, //(initproc)Expr_init, /*tp_init */
|
(initproc) ExprLit_init, /*tp_init */
|
||||||
0, /*tp_alloc */
|
0, /*tp_alloc */
|
||||||
0, //(newfunc) Expr_new, /*tp_new */
|
(newfunc) ExprLit_new, /*tp_new */
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -162,31 +162,31 @@ def test_readExpr_invalid():
|
|||||||
pgf.readExpr("->")
|
pgf.readExpr("->")
|
||||||
|
|
||||||
def test_readExpr_equality_int():
|
def test_readExpr_equality_int():
|
||||||
assert pgf.readExpr("123") == pgf.readExpr("123")
|
assert pgf.readExpr("123") == pgf.ExprLit(123)
|
||||||
|
|
||||||
def test_readExpr_equality_int_neg():
|
def test_readExpr_equality_int_neg():
|
||||||
assert pgf.readExpr("-123") == pgf.readExpr("-123")
|
assert pgf.readExpr("-123") == pgf.ExprLit(-123)
|
||||||
|
|
||||||
def test_readExpr_equality_int_big():
|
def test_readExpr_equality_int_big():
|
||||||
assert pgf.readExpr("774763251095801167872") == pgf.readExpr("774763251095801167872")
|
assert pgf.readExpr("774763251095801167872") == pgf.ExprLit(774763251095801167872)
|
||||||
|
|
||||||
def test_readExpr_equality_int_big_neg():
|
def test_readExpr_equality_int_big_neg():
|
||||||
assert pgf.readExpr("-774763251095801167872") == pgf.readExpr("-774763251095801167872")
|
assert pgf.readExpr("-774763251095801167872") == pgf.ExprLit(-774763251095801167872)
|
||||||
|
|
||||||
def test_readExpr_inequality_int():
|
def test_readExpr_inequality_int():
|
||||||
assert pgf.readExpr("123") != pgf.readExpr("456")
|
assert pgf.readExpr("123") != pgf.ExprLit(456)
|
||||||
|
|
||||||
def test_readExpr_equality_float():
|
def test_readExpr_equality_float():
|
||||||
assert pgf.readExpr("3.142") == pgf.readExpr("3.142")
|
assert pgf.readExpr("3.142") == pgf.ExprLit(3.142)
|
||||||
|
|
||||||
def test_readExpr_inequality_float():
|
def test_readExpr_inequality_float():
|
||||||
assert pgf.readExpr("3.142") != pgf.readExpr("3")
|
assert pgf.readExpr("3.142") != pgf.ExprLit(3)
|
||||||
|
|
||||||
def test_readExpr_equality_string():
|
def test_readExpr_equality_string():
|
||||||
assert pgf.readExpr("\"abc\"") == pgf.readExpr("\"abc\"")
|
assert pgf.readExpr("\"abc\"") == pgf.ExprLit("abc")
|
||||||
|
|
||||||
def test_readExpr_inequality_string():
|
def test_readExpr_inequality_string():
|
||||||
assert pgf.readExpr("\"abc\"") != pgf.readExpr("\"def\"")
|
assert pgf.readExpr("\"abc\"") != pgf.ExprLit("def")
|
||||||
|
|
||||||
def test_readExpr_str_int():
|
def test_readExpr_str_int():
|
||||||
assert str(pgf.readExpr("123")) == "123"
|
assert str(pgf.readExpr("123")) == "123"
|
||||||
|
|||||||
Reference in New Issue
Block a user