def test_simple(self): block = WrapBlock(parent_width=20) block.add_text('This paragraph will result in 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_oneline(self, data): block = WrapBlock(parent_width=128) for line in data[:-1]: if isinstance(line, list): block.add_boxed(line[0]) else: block.add_text(line) pytest.g.assert_lines(list(block.get_lines()), [data[-1]])
def test_first_offset(self): block = WrapBlock(first_offset=10, parent_width=30) block.add_text('This paragraph will result in 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_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_combined(self): block = WrapBlock(parent_width=128) block.add_text('Bla (') block.add_boxed(':func:`foo`') block.add_text(').') block.add_text('After test.') block.add_boxed('\n') block.add_boxed('\n') block.add_boxed(':any:`xxx`') block.add_text(', <- must be no space!') block.add_text('...some word') pytest.g.assert_lines(list(block.get_lines()), [ 'Bla (:func:`foo`). After test.', '', ':any:`xxx`, <- must be no space! ...some word', ])
def test_line_break(self): block = WrapBlock(parent_width=28) block.add_text('This paragraph will result in an indented block') block.add_text('top-') block.add_boxed('\n') # Force line break block.add_text('level paragraph') block.add_boxed('\n') # Force line break block.add_boxed('\n') # Force line break block.add_text('protected text') block.add_boxed('\n') # Force line break block.add_boxed('\n') # Force line break pytest.g.assert_lines(list(block.get_lines()), [ 'This paragraph will result', 'in an indented block top-', 'level paragraph', '', 'protected text', '', '' ])
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_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']
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' ]
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 == []