summary refs log tree commit diff stats
path: root/testing/test_abdl.py
diff options
context:
space:
mode:
Diffstat (limited to 'testing/test_abdl.py')
-rw-r--r--testing/test_abdl.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/testing/test_abdl.py b/testing/test_abdl.py
index 79a0edf..4b151b0 100644
--- a/testing/test_abdl.py
+++ b/testing/test_abdl.py
@@ -269,6 +269,22 @@ def test_optional_value_subtree():
     matcher = pat.match({'bar': 2})
     assert list(matcher) == [{'bar': ('bar', 2)}]
 
+def test_predicate_on_subvalue():
+    # make sure predicates on subvalues compile
+    pat = abdl.compile("(:?$dict->foo'foo'?)?(->bar'bar')", dict(dict=dict))
+    matcher = pat.match({'foo': 1, 'bar': 2})
+    assert list(matcher) == [{'foo': ('foo', 1), 'bar': ('bar', 2)}]
+    matcher = pat.match({'bar': 2})
+    assert list(matcher) == [{'bar': ('bar', 2)}]
+    try:
+        # this should fail on the 'bar' match
+        next(pat.match([]), None)
+    except abdl.exceptions.ValidationError:
+        # but we don't really have a way of checking which part failed
+        pass
+    else:
+        assert False
+
 # FIXME
 #@hypothesis.given(objtree, st.text())
 #def test_exhaustive(foo, pat):