Ejemplo n.º 1
0
    def test_single_initial_tab_is_removed(self):
        paragraph = Paragraph(children=[
            Run(children=[TabChar()]),
        ])
        expected = Paragraph(children=[
            Run(),
        ])

        self.builder.remove_initial_tab_chars_from_paragraph(paragraph)
        self.assertEqual(repr(paragraph), repr(expected))
Ejemplo n.º 2
0
    def test_only_tabs_before_first_text_are_removed(self):
        paragraph = Paragraph(children=[
            Run(children=[
                TabChar(),
            ]),
            Run(children=[
                TabChar(),
                Text(),
                TabChar(),
            ]),
        ])
        expected = Paragraph(children=[
            Run(),
            Run(children=[
                Text(),
                TabChar(),
            ]),
        ])

        self.builder.remove_initial_tab_chars_from_paragraph(paragraph)
        self.assertEqual(repr(paragraph), repr(expected))
Ejemplo n.º 3
0
    def test_tab_char_is_not_removed_when_tab_char_is_not_set(self):
        paragraph = Paragraph(children=[
            Run(children=[
                Text(text='a'),
                TabChar(),
                Text(text='b'),
            ]),
        ])
        expected = Paragraph(children=[
            Run(children=[
                Text(text=''),
                TabChar(),
                Text(text=''),
            ]),
        ])

        self.builder.remove_initial_text_from_paragraph(
            paragraph,
            initial_text='ab',
        )
        self.assertEqual(repr(paragraph), repr(expected))
Ejemplo n.º 4
0
    def test_multiple_tab_chars_are_removed(self):
        paragraph = Paragraph(children=[
            Run(children=[
                Text(text='a'),
                TabChar(),
                TabChar(),
                TabChar(),
                Text(text='b'),
            ]),
        ])
        expected = Paragraph(children=[
            Run(children=[
                Text(text=''),
                Text(text=''),
            ]),
        ])

        self.builder.remove_initial_text_from_paragraph(
            paragraph,
            initial_text='aFOOFOOFOOb',
            tab_char='FOO',
        )
        self.assertEqual(repr(paragraph), repr(expected))
Ejemplo n.º 5
0
    def test_many_runs_many_tabs_are_removed(self):
        paragraph = Paragraph(children=[
            Run(children=[
                TabChar(),
                TabChar(),
            ]),
            Run(children=[
                TabChar(),
            ]),
            Run(),
            Run(children=[
                TabChar(),
                TabChar(),
            ]),
        ])
        expected = Paragraph(children=[
            Run(),
            Run(),
            Run(),
            Run(),
        ])

        self.builder.remove_initial_tab_chars_from_paragraph(paragraph)
        self.assertEqual(repr(paragraph), repr(expected))
Ejemplo n.º 6
0
    def test_invalid_input_components(self):
        components = [
            Paragraph(),
            Paragraph(children=[Run(children=[
                TabChar(),
            ])]),
            Paragraph(properties=ParagraphProperties()),
            Paragraph(properties=ParagraphProperties(
                numbering_properties=NumberingProperties())),
            self.create_numbering_paragraph('1', '0', container=False),
        ]

        builder = NumberingSpanBuilder(components)
        result = builder.detect_parent_child_map_for_items()

        self.assertEqual(builder.parent_child_num_map, {})
        self.assertEqual(builder.child_parent_num_map, {})
        self.assertFalse(result)
Ejemplo n.º 7
0
    def test_tabs_embedded_within_initial_text_can_be_removed(self):
        paragraph = Paragraph(children=[
            Run(children=[
                Text(text='a'),
                TabChar(),
                Text(text='b'),
            ]),
        ])
        expected = Paragraph(children=[
            Run(children=[
                Text(text=''),
                Text(text=''),
            ]),
        ])

        self.builder.remove_initial_text_from_paragraph(
            paragraph,
            initial_text='aFOOb',
            tab_char='FOO',
        )
        self.assertEqual(repr(paragraph), repr(expected))