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()
def test_simple_empty_words(self): block = WrapBlock(parent_width=20) # Add empty box. block.start_box() block.end_box() block.add_text('This paragraph will result \nin an indented block of') block.add_text('Another top-level paragraph') pytest.g.assert_lines(list(block.get_lines()), [ 'This paragraph will', 'result in an', 'indented block of', 'Another top-level', 'paragraph' ])
def test_box(self): block = WrapBlock(parent_width=28) block.add_text('This paragraph will result in an indented block') block.add_boxed('of Another') block.add_text('top-level paragraph') block.start_box() block.add_text('protected') block.add_text('text') block.end_box() # NOTE: words between start_box() and end_box() is joined without space. pytest.g.assert_lines(list(block.get_lines()), [ 'This paragraph will result', 'in an indented block', 'of Another top-level', 'paragraph protectedtext' ])
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' ]