Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Jul 28, 2023
1 parent fa0a62a commit 482dcee
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## Unreleased

### Fixed

- Fixed Text.expand_tabs not expanding spans.

### Added

- Added Text.extend_style method.

## [13.4.2] - 2023-06-12

### Changed
Expand Down
4 changes: 2 additions & 2 deletions rich/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,12 +565,12 @@ def get_style_at_offset(self, console: "Console", offset: int) -> Style:
return style

def extend_style(self, spaces: int) -> None:
"""Extend the Text and styles by a given number of spaces.
"""Extend the Text given number of spaces where the spaces have the same style as the last character.
Args:
spaces (int): Number of spaces to add to the Text.
"""
if not spaces:
if spaces <= 0:
return
spans = self.spans
new_spaces = " " * spaces
Expand Down
16 changes: 16 additions & 0 deletions tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,3 +898,19 @@ def test_markup_property():
== "[bold]foo [italic]bar[/bold] baz[/italic]"
)
assert Text("[bold]foo").markup == "\\[bold]foo"


def test_extend_style():
text = Text.from_markup("[red]foo[/red] [bold]bar")
text.extend_style(0)

assert text.plain == "foo bar"
assert text.spans == [Span(0, 3, "red"), Span(4, 7, "bold")]

text.extend_style(-1)
assert text.plain == "foo bar"
assert text.spans == [Span(0, 3, "red"), Span(4, 7, "bold")]

text.extend_style(2)
assert text.plain == "foo bar "
assert text.spans == [Span(0, 3, "red"), Span(4, 9, "bold")]

0 comments on commit 482dcee

Please sign in to comment.