def test_macro_tag(self): node_list = [ grammar.MacroTagNode('year', 'Y'), ] self.assertEqual( grammar.RegexScribe(node_list).translate(), r'(?P<year>\d{4})', )
def test_uncaptured_macro_tag(self): node_list = [ grammar.MacroTagNode('', 'Y'), ] self.assertEqual( grammar.RegexScribe(node_list).translate(), r'\d{4}', )
def test_uncaptured_regex_tag(self): node_list = [ grammar.RegexTagNode('', '[0-9]{2}'), ] self.assertEqual( grammar.RegexScribe(node_list).translate(), '[0-9]{2}', )
def test_regex_tag(self): node_list = [ grammar.RegexTagNode('simple', '[0-9]{2}'), ] self.assertEqual( grammar.RegexScribe(node_list).translate(), '(?P<simple>[0-9]{2})', )
def test_tag(self): node_list = [ grammar.TagNode('simple'), ] self.assertEqual( grammar.RegexScribe(node_list).translate(), '(?P<simple>.+)', )
def test_optional(self): node_list = [ grammar.TextNode('required'), grammar.OptionalNode([ grammar.TextNode('optional'), ]), ] self.assertEqual( grammar.RegexScribe(node_list).translate(), 'required(optional)?')
def test_basic(self): node_list = [grammar.TextNode('test')] self.assertEqual(grammar.RegexScribe(node_list).translate(), 'test')