Exemplo n.º 1
0
 def test_clear(self):
     block = WrapBlock(parent_width=20)
     block.add_text('This paragraph will result in an indented block of')
     block.start_box()
     block.add_text('sss')
     block.clear()
     assert block.words == []
     assert block._box is None
     assert block.is_empty()
Exemplo n.º 2
0
    def test_add_multiline(self):
        block = WrapBlock()

        # Add to empty block - add to the end of the block.
        block.add_text('1\n2')
        assert block.words == ['1', '2']

        # Add to non empty block:
        block.add_text('3\n4\n5')
        assert block.words == ['1', '2', '3', '4', '5']

        # Add list with first blank line - it will skipped.
        block.add_text('\n6')
        assert block.words == ['1', '2', '3', '4', '5', '6']

        # Single '\n' is skipped too.
        block.add_text('\n')
        assert block.words == ['1', '2', '3', '4', '5', '6']

        # In this case first \n will be stripped.
        block.add_text('\n\n')
        # First \n forces line break and second one forces blank line
        assert block.words == ['1', '2', '3', '4', '5', '6', '\n', '\n']

        # Add to the block where last line is blank.
        block.add_text('7\n8\n')
        assert block.words == [
            '1', '2', '3', '4', '5', '6', '\n', '\n', '7', '8'
        ]

        block.add_text('9')
        assert block.words == [
            '1', '2', '3', '4', '5', '6', '\n', '\n', '7', '8', '9'
        ]

        block.add_text('10 11\n 12\n13')
        assert block.words == [
            '1', '2', '3', '4', '5', '6', '\n', '\n', '7', '8', '9', '10',
            '11', '12', '13'
        ]

        block.clear()
        block.add_text('1\n 2\n\n3')
        assert block.words == ['1', '2', '\n', '\n', '3']