Exemple #1
0
    def test_with_source(self):
        qu_map = CombinatoricMap(MakeInto(Letter),
            (Target('q', 'u'), ReplaceWith(('qu',))),
            (Target('q', 'v'), ReplaceWith(('qu',))),
            (Target('a', 'e'), ReplaceWith(('ae',), ('a', 'e'))),
            (Target(Var('A', Any)), ReplaceWith((Var('A'),)))
        )

        word_instance = WordInstance('qvaec', mockSource)
        qvaec = (
            Letter('q', Source(word_instance, 0)),
            Letter('v', Source(word_instance, 1)),
            Letter('a', Source(word_instance, 2)),
            Letter('e', Source(word_instance, 3)),
            Letter('c', Source(word_instance, 4))
        )
        self.assertCountEqual(
            qu_map.map(qvaec),
            (
                (
                    Letter('qu', Source(word_instance, 0)),
                    Letter('a', Source(word_instance, 2)),
                    Letter('e', Source(word_instance, 3)),
                    Letter('c', Source(word_instance, 4)),
                ),
                (
                    Letter('qu', Source(word_instance, 0)),
                    Letter('ae', Source(word_instance, 2)),
                    Letter('c', Source(word_instance, 4)),
                )
            )
        )
Exemple #2
0
    def test_not_followed_by(self):
        c_map = CombinatoricMap(ignore_matched_input,
            (Target('a', NotFollowedBy('b')),
                ReplaceWith(('A',))),
            (Target(Var('A', Any)),
                ReplaceWith((Var('A'),)))
        )

        input = 'axabc'

        self.assertCountEqual(
            c_map.map(input),
            (
                ('A', 'x', 'a', 'b', 'c'),
            )
        )
Exemple #3
0
    def test_optional(self):
        c_map = CombinatoricMap(ignore_matched_input, 
            (Target(Optional('a'), 'b'),
                ReplaceWith(['AB'])),
            (Target(Var('A', Any)),
                ReplaceWith([Var('A')]))
        )

        input = 'xybxabac'

        self.assertCountEqual(
            c_map.map(input),
            (
                ('x', 'y', 'AB', 'x', 'AB', 'a', 'c'),
            )
        )
Exemple #4
0
    def test_testvar(self):
        c_map = CombinatoricMap(MakeInto(Letter),
            (Target('a', TestVar('C', is_consonant), 'e'),
                ReplaceWith(['A', Var('C'), 'E'])),
            (Target(Var('A', Any)),
                ReplaceWith([Var('A')]))
        )

        input = 'garebaie'

        self.assertCountEqual(
            reduce_to_text(c_map.map(input)),
            (
                ['g', 'A', 'r', 'E', 'b', 'a', 'i', 'e'],
            )
        )
Exemple #5
0
    def test_basics(self):
        qu_map = CombinatoricMap(lambda rw_object, source: rw_object,
            (Target('q', 'u'), ReplaceWith(['qu'])),
            (Target('q', 'v'), ReplaceWith(['qu'])),
            (Target('a', 'e'), ReplaceWith(['ae'], ['a', 'e'])),
            (Target(Var('A', Any)), ReplaceWith([Var('A')]))
        )

        qvaec = ('q', 'v', 'a', 'e', 'c')

        self.assertCountEqual(
            qu_map.map(qvaec),
            (
                ('qu', 'a', 'e', 'c'),
                ('qu', 'ae', 'c')
            )
        )