diff options
-rw-r--r-- | testing/test_abdl.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/testing/test_abdl.py b/testing/test_abdl.py index 2cea90d..d951c7b 100644 --- a/testing/test_abdl.py +++ b/testing/test_abdl.py @@ -169,6 +169,21 @@ def test_subtree_partial(foo, pat): yield {"A": a, "D": d} assert all(LogAndCompare(pat.match(foo), deep(foo))) +@hypothesis.given(objtree, st.just(abdl.compile("->tag[]"))) +def test_tagged_key(foo, pat): + def deep(foo): + for x in pairs(foo): + yield {"tag": x} + assert all(LogAndCompare(pat.match(foo), deep(foo))) + +@hypothesis.given(objtree, st.just(abdl.compile("->[]->D"))) +def test_key_dummy(foo, pat): + def deep(foo): + for x in pairs(foo): + for d in pairs(x[1]): + yield {"D": d} + assert all(LogAndCompare(pat.match(foo), deep(foo))) + @hypothesis.given(objtree, st.just(abdl.compile("->X->$a->Z", {'a': '0'}))) def test_param(foo, pat): def deep(foo): @@ -182,10 +197,45 @@ def test_param(foo, pat): yield {"X": x, "Z": z} assert all(LogAndCompare(pat.match(foo), deep(foo))) +@hypothesis.given(objtree, st.just(abdl.compile("->tag/.../?"))) +def test_tagged_regex(foo, pat): + def deep(foo): + for x in pairs(foo): + if isinstance(x[0], str) and re.search("...", x[0]): + yield {"tag": x} + assert all(LogAndCompare(pat.match(foo), deep(foo))) + +@hypothesis.given(objtree, st.just(abdl.compile("->tag'0'?"))) +def test_tagged_str(foo, pat): + def deep(foo): + try: + yield {"tag": ('0', foo['0'])} + except (TypeError, IndexError, KeyError): + pass + assert all(LogAndCompare(pat.match(foo), deep(foo))) + +@hypothesis.given(objtree, st.just(abdl.compile("->tag$?a", {'a': '0'}))) +def test_tagged_param(foo, pat): + def deep(foo): + try: + yield {"tag": ('0', foo['0'])} + except (TypeError, IndexError, KeyError): + pass + assert all(LogAndCompare(pat.match(foo), deep(foo))) + def test_basic_value_subtree(): matcher = abdl.match("(->foo'foo')(->bar'bar')", {'foo': 1, 'bar': 2}) assert list(matcher) == [{'foo': ('foo', 1), 'bar': ('bar', 2)}] +@hypothesis.given(objtree, st.just(abdl.compile("->[:?$sets]->D", {'sets': collections.abc.Set}))) +def test_key_predicate(foo, pat): + def deep(foo): + for x in pairs(foo): + if isinstance(x[0], collections.abc.Set): + for d in pairs(x[1]): + yield {"D": d} + assert all(LogAndCompare(pat.match(foo), deep(foo))) + # FIXME #@hypothesis.given(objtree, st.text()) #def test_exhaustive(foo, pat): |