From 6db8b61e4cc4e46ea91e61ee0b48c36607774339 Mon Sep 17 00:00:00 2001 From: Kyle Maxwell Date: Wed, 1 Apr 2009 18:29:20 -0700 Subject: [PATCH] flag test --- pyparsleymodule.c | 4 +++- test/test_pyparsley.py | 13 +++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pyparsleymodule.c b/pyparsleymodule.c index 9a9eb1f..cd64480 100644 --- a/pyparsleymodule.c +++ b/pyparsleymodule.c @@ -173,7 +173,7 @@ PyParsley_parse_doc(parsedParsleyPtr ptr, char *type) { return output; } -#define SET_FLAG(C, B) if(!B) flags -= C +#define SET_FLAG(C, B) if(B) flags |= C static PyObject * @@ -206,6 +206,8 @@ PyParsley_parse(PyParsley *self, PyObject *args, PyObject *keywords) SET_FLAG(PARSLEY_OPTIONS_COLLATE, collate); SET_FLAG(PARSLEY_OPTIONS_ALLOW_NET, allow_net); SET_FLAG(PARSLEY_OPTIONS_ALLOW_LOCAL, allow_local); + + // printf("%d %d %d %d %d \n", prune, collate, allow_net, allow_local, flags); if(self->parsley == NULL) { PyErr_SetString(PyExc_RuntimeError, "parsley data is NULL"); diff --git a/test/test_pyparsley.py b/test/test_pyparsley.py index 931959b..c5291b5 100755 --- a/test/test_pyparsley.py +++ b/test/test_pyparsley.py @@ -9,22 +9,31 @@ class TestPyParsley(unittest.TestCase): def setUp(self): self.parsley = PyParsley({'title': 'title'}) self.alt_parsley = PyParsley('{"title": "title"}') + self.a_parsley = PyParsley({'links': ['regexp:match(a @href, ".*sign.*")']}) self.__file__ = currentframe().f_code.co_filename self.__dir__ = dirname(self.__file__) self.file = self.__dir__ + '/yelp.html' self.json = '{ "title": "\\t\\tNick\'s Crispy Tacos - Russian Hill - San Francisco, CA\\n" }' + self.native = { "title": "\t\tNick's Crispy Tacos - Russian Hill - San Francisco, CA\n" } + self.links = '{ "links": [ "\\/signup?return_url=%2Fuser_details", "\\/signup?return_url=%2Fwriteareview", "\\/signup?return_url=%2Finvite_friends", "\\/signup?return_url=%2Fmail", "\\/signup?return_url=%2Fprofile", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup", "\\/signup" ] }' def test_file_xml(self): parsed = self.parsley.parse(file = self.file, output = "json") self.assertEquals(self.json, parsed) - + + def test_pruning(self): + parsed = self.a_parsley.parse(file = self.file, output = "json") + self.assertEquals(self.links, parsed) + def test_json_file_xml(self): parsed = self.alt_parsley.parse(file = self.file, output = "json") self.assertEquals(self.json, parsed) def test_native(self): parsed = self.alt_parsley.parse(file = self.file, output = "python") - self.assertEquals({ "title": "\t\tNick's Crispy Tacos - Russian Hill - San Francisco, CA\n" }, parsed) + self.assertEquals(self.native, parsed) + parsed = self.alt_parsley.parse(file = self.file) + self.assertEquals(self.native, parsed) if __name__ == '__main__': unittest.main() \ No newline at end of file