Return match as separate complex and simple value array
This commit is contained in:
parent
508ae2397f
commit
d2bca51342
@ -1,3 +1,5 @@
|
||||
- 0.0.3
|
||||
* Split match to 2-element tuple, returning complex value and simple values separately
|
||||
- 0.0.2
|
||||
* Fix rename module name errors
|
||||
* Add listing and matcher
|
||||
|
@ -1,6 +1,6 @@
|
||||
[metadata]
|
||||
name = shep
|
||||
version = 0.0.2
|
||||
version = 0.0.3
|
||||
description = Multi-state key value stores using bitmaskings
|
||||
author = Louis Holbrook
|
||||
author_email = dev@holbrook.no
|
||||
|
@ -95,11 +95,11 @@ class State:
|
||||
|
||||
|
||||
def match(self, v, pure=False):
|
||||
r = []
|
||||
alias = None
|
||||
if not pure:
|
||||
m = self.__reverse.get(v)
|
||||
if m != None:
|
||||
r.append(m)
|
||||
alias = self.__reverse.get(v)
|
||||
|
||||
r = []
|
||||
c = 1
|
||||
for i in range(self.__bits):
|
||||
if v & c > 0:
|
||||
@ -110,4 +110,4 @@ class State:
|
||||
pass
|
||||
c <<= 1
|
||||
|
||||
return r
|
||||
return (alias, r,)
|
||||
|
@ -37,17 +37,19 @@ class TestStateReport(unittest.TestCase):
|
||||
def test_match_alias(self):
|
||||
self.states.alias('xyzzy', self.states.FOO | self.states.BAZ)
|
||||
r = self.states.match(self.states.XYZZY)
|
||||
for k in ['FOO', 'BAZ', 'XYZZY']:
|
||||
self.assertIn(k, r)
|
||||
self.assertNotIn('BAR', r)
|
||||
for k in ['FOO', 'BAZ']:
|
||||
self.assertIn(k, r[1])
|
||||
self.assertNotIn('BAR', r[1])
|
||||
self.assertEqual('XYZZY', r[0])
|
||||
|
||||
|
||||
def test_match_alias_pure(self):
|
||||
self.states.alias('xyzzy', self.states.FOO | self.states.BAZ)
|
||||
r = self.states.match(self.states.XYZZY, pure=True)
|
||||
for k in ['FOO', 'BAZ']:
|
||||
self.assertIn(k, r)
|
||||
self.assertNotIn('XYZZY', r)
|
||||
self.assertIn(k, r[1])
|
||||
self.assertNotIn('XYZZY', r[1])
|
||||
self.assertIsNone(r[0])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user