Example #1
0
 def test_only_first_between_match_in_sequence_expands(self):
     self._test_unique_match(
         text='Some text',
         match=SequenceMatch(
             mark_parens(BetweenMatch()),
             mark_braces(BetweenMatch()),
             mark_curlies(BetweenMatch()),
             EndAnchorMatch(),
         ),
         expected_solution={'matched_text': '(Some text)[]{}', 'position': 9})
Example #2
0
 def test_between_match_in_search_at_start_and_end(self):
     self._test_unique_match(
         text='abracadabra',
         match=SearchReplaceMatch(
             SequenceMatch(
                 mark_parens(BetweenMatch()),
                 delete_action(LiteralMatch('r')),
                 mark_braces(BetweenMatch()),
             ),
         ),
         expected_solution={'text': '(ab)[acadab]()[a]', 'matched_text': '', 'position': 0})
Example #3
0
 def test_starts_with_between_match(self):
     self._test_rule(
         text='abc 123',
         rule=Rule(
             SequenceMatch(
                 mark_braces(BetweenMatch()),
                 mark_parens(LiteralMatch('c')),
             ),
         ),
         expected_text='[ab](c) 123'
     )
Example #4
0
 def test_ends_with_between_match(self):
     self._test_rule(
         text='abc 123',
         rule=Rule(
             SequenceMatch(
                 mark_parens(LiteralMatch('ab')),
                 mark_braces(BetweenMatch()),
             ),
         ),
         expected_text='(ab)[c 123]'
     )
Example #5
0
 def test_pattern_matches_are_anchors(self):
     self._test_unique_match(
         text='abcdefghi',
         match=SequenceMatch(
             mark_parens(BetweenMatch()),
             LiteralMatch('d'),
             mark_braces(BetweenMatch()),
             LiteralMatch('g'),
             mark_curlies(BetweenMatch()),
             EndAnchorMatch(),
         ),
         expected_solution={'matched_text': '(abc)d[ef]g{hi}', 'position': 9})
Example #6
0
 def test_insert_matches_are_not_anchors(self):
     self._test_unique_match(
         text='Some text',
         match=SequenceMatch(
             mark_parens(BetweenMatch()),
             InsertLiteralMatch('1'),
             mark_braces(BetweenMatch()),
             InsertLiteralMatch('2'),
             mark_curlies(BetweenMatch()),
             EndAnchorMatch(),
         ),
         expected_solution={'matched_text': '(Some text)1[]2{}', 'position': 9})
Example #7
0
 def test_no_match(self):
     self._test_rule(
         text='abc 123',
         rule=Rule(
             SequenceMatch(
                 mark_parens(LiteralMatch('abc')),
                 delete_action(FormatMatch('ws')),
                 mark_braces(LiteralMatch('x')),
             ),
         ),
         expected_text='abc 123'
     )
Example #8
0
 def test_between_match_before_search_replace(self):
     self._test_match(
         text='abracadabra',
         match=SequenceMatch(
             mark_parens(BetweenMatch()),
             SearchReplaceMatch(mark_braces(LiteralMatch('a'))),
             LiteralMatch('r'),
             BetweenMatch(),
             EndAnchorMatch(),
         ),
         expected_solutions=[
             {'matched_text': '(ab)r[a]c[a]d[a]br[a]', 'position': 19, 'text': 'abr[a]c[a]d[a]br[a]'},
             {'matched_text': '(abracadab)r[a]', 'position': 13, 'text': 'abracadabr[a]'},
         ])
Example #9
0
    def test_optional_match(self):
        match = SequenceMatch(
            mark_parens(FormatMatch('s')),
            mark_braces(RepeatMatch(FormatMatch('d'), 0, 1)),
            mark_curlies(FormatMatch('s')),
            EndAnchorMatch(),
        )

        self._test_unique_match(
            text='Time 2 Die',
            match=match,
            expected_solution={'matched_text': '(Time) [2] {Die}', 'position': 10})
        self._test_unique_match(
            text='Time Die',
            match=match,
            expected_solution={'matched_text': '(Time)[] {Die}', 'position': 8})
        self._test_unique_match(
            text='Time 2',
            match=match,
            expected_solution={'matched_text': '(Time)[] {2}', 'position': 6})