示例#1
0
 def test_macro_tag(self):
     node_list = [
         grammar.MacroTagNode('year', 'Y'),
     ]
     self.assertEqual(
         grammar.RegexScribe(node_list).translate(),
         r'(?P<year>\d{4})',
     )
示例#2
0
 def test_uncaptured_macro_tag(self):
     node_list = [
         grammar.MacroTagNode('', 'Y'),
     ]
     self.assertEqual(
         grammar.RegexScribe(node_list).translate(),
         r'\d{4}',
     )
示例#3
0
 def test_uncaptured_regex_tag(self):
     node_list = [
         grammar.RegexTagNode('', '[0-9]{2}'),
     ]
     self.assertEqual(
         grammar.RegexScribe(node_list).translate(),
         '[0-9]{2}',
     )
示例#4
0
 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})',
     )
示例#5
0
 def test_tag(self):
     node_list = [
         grammar.TagNode('simple'),
     ]
     self.assertEqual(
         grammar.RegexScribe(node_list).translate(),
         '(?P<simple>.+)',
     )
示例#6
0
 def test_optional(self):
     node_list = [
         grammar.TextNode('required'),
         grammar.OptionalNode([
             grammar.TextNode('optional'),
         ]),
     ]
     self.assertEqual(
         grammar.RegexScribe(node_list).translate(), 'required(optional)?')
示例#7
0
 def test_basic(self):
     node_list = [grammar.TextNode('test')]
     self.assertEqual(grammar.RegexScribe(node_list).translate(), 'test')