summary refs log tree commit diff stats
path: root/testing/test_examples.py
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2019-12-03 23:21:03 -0300
committerSoniEx2 <endermoneymod@gmail.com>2020-01-22 19:46:23 -0300
commit099e8f957f3c969c148e6106bf50787d471c0d04 (patch)
tree9ced95c0441c4572c3b02d88efd203ef95b8b73a /testing/test_examples.py
parentc055c6ae3d545b928fbb2b77e6f0ddc31fac84f8 (diff)
Add multiple value matches
Diffstat (limited to 'testing/test_examples.py')
-rw-r--r--testing/test_examples.py25
1 files changed, 21 insertions, 4 deletions
diff --git a/testing/test_examples.py b/testing/test_examples.py
index 7341341..02532cc 100644
--- a/testing/test_examples.py
+++ b/testing/test_examples.py
@@ -1,9 +1,26 @@
 import abdl
 
 def test_basic_example():
-    for m in abdl.match("->X:?$dict->Y", {"foo": 1, "bar": {"baz": 2}}, {'dict': dict}):
-        assert m['X'][0] == 'bar' and  m['Y'][0] == 'baz' and m['Y'][1] == 2
+    m = next(abdl.match("->X:?$dict->Y", {"foo": 1, "bar": {"baz": 2}}, {'dict': dict}))
+    assert m['X'][0] == 'bar'
+    assert m['Y'][0] == 'baz'
+    assert m['Y'][1] == 2
 
 def test_basic_2():
-    for m in abdl.match("->'projects':?$d->P/[0-9a-fA-F]{40}|[0-9a-fA-F]{64}/?:?$d->U:?$d->B", {"projects": {"385e734a52e13949a7a5c71827f6de920dbfea43": {"https://soniex2.autistic.space/git-repos/ganarchy.git": {"HEAD": {"active": True}}}}}, {'d': dict}):
-        assert m['P'][0] == "385e734a52e13949a7a5c71827f6de920dbfea43" and m['U'][0] == "https://soniex2.autistic.space/git-repos/ganarchy.git" and m['B'][0] == "HEAD" and m['B'][1] == {"active": True}
+    m = next(abdl.match("->'projects':?$d->P/[0-9a-fA-F]{40}|[0-9a-fA-F]{64}/?:?$d->U:?$d->B", {"projects": {"385e734a52e13949a7a5c71827f6de920dbfea43": {"https://soniex2.autistic.space/git-repos/ganarchy.git": {"HEAD": {"active": True}}}}}, {'d': dict}))
+    assert m['P'][0] == "385e734a52e13949a7a5c71827f6de920dbfea43"
+    assert m['U'][0] == "https://soniex2.autistic.space/git-repos/ganarchy.git"
+    assert m['B'][0] == "HEAD"
+    assert m['B'][1] == {"active": True}
+
+def test_spaces():
+    pat = abdl.compile("""-> 'projects'?
+                             -> commit /[0-9a-fA-F]{40}|[0-9a-fA-F]{64}/? :?$dict
+                                -> url :?$dict
+                                   -> branch :?$dict""", {'dict': dict})
+    data = {"projects": {"385e734a52e13949a7a5c71827f6de920dbfea43": {"https://soniex2.autistic.space/git-repos/ganarchy.git": {"HEAD": {"active": True}}}}}
+    m = next(pat.match(data))
+    assert m['commit'][0] == "385e734a52e13949a7a5c71827f6de920dbfea43"
+    assert m['url'][0] == "https://soniex2.autistic.space/git-repos/ganarchy.git"
+    assert m['branch'][0] == "HEAD"
+    assert m['branch'][1] == {"active": True}