Пример #1
0
    def test_construct(self):
        b = WrapBlock()
        assert b.indent == 0
        assert b.first_offset is None
        assert b.child_indent == 0
        assert b.width is None
        assert b.top_margin == 0
        assert b.bottom_margin == 0
        assert b.words == []
        assert b._box is None
        assert not b.is_box_started()
        assert list(b.get_lines()) == []

        b = WrapBlock(1, 2, 3, 4, 5, 6)
        assert b.indent == 1
        assert b.first_offset == 2
        assert b.child_indent == 3
        assert b.width == 3
        assert b.top_margin == 5
        assert b.bottom_margin == 6
        assert b.words == []
        assert b._box is None

        assert not b.is_box_started()
        assert b.is_empty()
Пример #2
0
    def test_add(self):
        block = WrapBlock()

        # Add to empty block - just add it a a line.
        block.add_text('text')
        assert block.words == ['text']

        assert not block.is_empty()

        # Add to non empty block - add it to the last line.
        block.add_text('-xx')
        assert block.words == ['text', '-xx']
        assert not block.is_box_started()

        # Add empty - add nothing to the last line
        block.add_text('')
        assert block.words == ['text', '-xx']

        # Add multiple words.
        block.add_text('two words')
        assert block.words == ['text', '-xx', 'two', 'words']

        # This adds empty word which will be skipped in further processing.
        block.add_text('\n')
        # assert block.words == ['text', '-xx', 'two', 'words', '']
        assert block.words == ['text', '-xx', 'two', 'words']

        # Add empty string to empyt block.
        block = WrapBlock()
        block.add_text('')
        assert block.words == []
Пример #3
0
    def test_add_boxed(self):
        block = WrapBlock()
        block.add_text('one two')

        # Internal list is not set by default.
        assert block._box is None

        # Add boxed in one call.
        block.add_boxed('b x')
        assert block.words == ['one', 'two', ['b x']]

        # Internal list is reset after the call.
        assert block._box is None

        # Add boxed with explicit start/end.
        block.start_box()

        # Internal list is initialized now.
        assert block._box == []
        assert block.is_box_started()

        # And boxed list is added right after the call.
        assert block.words == ['one', 'two', ['b x'], []]

        # These words will be added after the boxed.
        block.add_text('one')
        block.add_text('two')

        # Still not added to the words.
        assert block.words == ['one', 'two', ['b x'], ['one', 'two']]

        # But internal box list if filled.
        assert block._box == ['one', 'two']

        # Do nothing if already started.
        block.start_box()
        assert block._box == ['one', 'two']

        block.end_box()
        assert not block.is_box_started()
        assert block._box is None
        assert block.words == ['one', 'two', ['b x'], ['one', 'two']]

        # Don't add empty box to words.
        block.start_box()
        block.end_box()
        assert block.words == ['one', 'two', ['b x'], ['one', 'two'], []]

        block.start_box()
        block.add_boxed('1')
        block.add_text('2')
        block.end_box()
        assert block.words == [
            'one', 'two', ['b x'], ['one', 'two'], [], ['2'], ['1']
        ]

        # This will force line break.
        block.add_boxed('\n')
        assert block.words == [
            'one', 'two', ['b x'], ['one', 'two'], [], ['2'], ['1'], '\n'
        ]