summary refs log tree commit diff stats
path: root/testing
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2020-11-06 22:25:12 -0300
committerSoniEx2 <endermoneymod@gmail.com>2020-11-06 22:25:12 -0300
commitff3628c36eab5ec19ab850e9126a951f5c203568 (patch)
treed05f7bf27b0141f779a013bcfa22a16543b33c18 /testing
parent436939628ff1c5bbc37d5c91c4a7c68d83f12f49 (diff)
Fix subvalue not parsing predicates
Diffstat (limited to 'testing')
-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):