コード例 #1
0
 def test_visit_in_space_category(self):
     in_node = InNode("")
     in_node.children.extend([
         CategoryNode("space", ""),
     ])
     msg = self.visitor.visit_node(in_node)
     self.assertIn(msg, string.whitespace)
コード例 #2
0
 def test_visit_in_digit_category(self):
     in_node = InNode("")
     in_node.children.extend([
         CategoryNode("digit", ""),
     ])
     msg = self.visitor.visit_node(in_node)
     self.assertIn(msg, string.digits)
コード例 #3
0
def getnode(line):
    line_type = LineType.getLineType(line.strip())
    if line_type == LineType.LITERAL:
        node = LiteralNode(parse_literal(line), line)
    elif line_type == LineType.RANGE:
        r = parse_range(line)
        node = RangeNode(r[0], r[1], line)
    elif line_type == LineType.IN:
        node = InNode(line)
    elif line_type == LineType.REPEAT:
        ranged, minr, maxr = parse_repeat(line.strip())
        node = RepeatNode(ranged, minr, maxr, line)
    elif line_type == LineType.BRANCH:
        node = ChoiceNode(line)
    elif line_type == LineType.OR:
        node = ChoiceNode(line)
    elif line_type == LineType.SUBPATTERN:
        node = GroupNode(line)
    elif line_type == LineType.NEGATE:
        node = NegateNode(line)
    elif line_type == LineType.CATEGORY:
        node = CategoryNode(parse_category(line), line)
    elif line_type == LineType.ANY:
        node = AnyNode(line)
    else:
        node = Node(line)
    return node
コード例 #4
0
 def test_visit_in_word_category(self):
     in_node = InNode("")
     in_node.children.extend([
         CategoryNode("word", ""),
     ])
     msg = self.visitor.visit_node(in_node)
     self.assertIn(msg, "".join([string.digits, string.ascii_letters]))
コード例 #5
0
 def test_visit_repeat_get_random_word(self):
     rpt_node = RepeatNode(True, 1, sre_constants.MAXREPEAT)
     in_node = InNode("")
     in_node.children.extend([
         LiteralNode(ord('c'), ""),
     ])
     rpt_node.children.append(in_node)
     msg = self.visitor.visit_node(rpt_node)
     self.assertEqual(msg, 'c' * regex_examples.RANDOM_WORD_LEN)
コード例 #6
0
 def test_visit_repeat_get_dict_word(self):
     rpt_node = RepeatNode(True, 1, sre_constants.MAXREPEAT)
     in_node = InNode("")
     in_node.children.extend([
         LiteralNode(ord('a'), ""),
     ])
     rpt_node.children.append(in_node)
     msg = self.visitor.visit_node(rpt_node)
     self.assertEqual(msg, "aaaa")
コード例 #7
0
 def test_visit_repeat_charclass_with_literal_and_range(self):
     rpt_node = RepeatNode(True, 1, sre_constants.MAXREPEAT)
     in_node = InNode("")
     in_node.children.extend([
         LiteralNode(ord('d'), ""),
         RangeNode(ord('e'), ord('g'), ""),
     ])
     rpt_node.children.append(in_node)
     msg = self.visitor.visit_node(rpt_node)
     self.assertEqual(msg, 'gfed')
コード例 #8
0
 def test_visit_repeat_skip_negated_characters(self):
     rpt_node = RepeatNode(True, 2, sre_constants.MAXREPEAT)
     in_node = InNode("")
     in_node.children.extend([
         NegateNode(""),
         RangeNode(ord('a'), ord('g'), ""),
         RangeNode(ord('A'), ord('G'), ""),
     ])
     rpt_node.children.append(in_node)
     msg = self.visitor.visit_node(rpt_node)
     self.assertEqual(msg.lower(), 'yxxy')
コード例 #9
0
 def test_visit_in(self):
     in_node = InNode("")
     in_node.children.extend([LiteralNode(ord('a'), "")])
     msg = self.visitor.visit_node(in_node)
     self.assertEqual(msg, "a")