method parse for algebric tags
This commit is contained in:
parent
7a21780ec9
commit
919c7c1c5a
@ -30,6 +30,27 @@ def parser(subparsers, config):
|
|||||||
# indistinguisable for argparse. (fabien, 201306)
|
# indistinguisable for argparse. (fabien, 201306)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
import re
|
||||||
|
def _parse_tags(s):
|
||||||
|
tags = []
|
||||||
|
if s[0] not in ['+', '-']:
|
||||||
|
s = '+' + s
|
||||||
|
last = 0
|
||||||
|
for m in re.finditer(r'[+-]', s):
|
||||||
|
if m.start() == last:
|
||||||
|
if last != 0:
|
||||||
|
raise ValueError, 'could not match tag expression'
|
||||||
|
else:
|
||||||
|
tags.append(s[last:(m.start())])
|
||||||
|
last = m.start()
|
||||||
|
if last == len(s):
|
||||||
|
raise ValueError, 'could not match tag expression'
|
||||||
|
else:
|
||||||
|
tags.append(s[last:])
|
||||||
|
return tags
|
||||||
|
|
||||||
|
|
||||||
def command(config, ui, referenceOrTag, tags):
|
def command(config, ui, referenceOrTag, tags):
|
||||||
"""Add, remove and show tags"""
|
"""Add, remove and show tags"""
|
||||||
rp = Repository.from_directory(config)
|
rp = Repository.from_directory(config)
|
||||||
|
15
tests/test_tag.py
Normal file
15
tests/test_tag.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
import testenv
|
||||||
|
from papers.commands.tag_cmd import _parse_tags
|
||||||
|
|
||||||
|
class TestCreateCitekey(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_tag_parsing(self):
|
||||||
|
|
||||||
|
self.assertEqual(['+abc', '+def9'], _parse_tags( 'abc+def9'))
|
||||||
|
self.assertEqual(['+abc', '-def9'], _parse_tags( 'abc-def9'))
|
||||||
|
self.assertEqual(['-abc', '-def9'], _parse_tags('-abc-def9'))
|
||||||
|
self.assertEqual(['+abc', '-def9'], _parse_tags('+abc-def9'))
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user