Added possibility to use HashTag/CashTag elements without prefixing content, added sep: str argument to the as_line function.

This commit is contained in:
Alex Root Junior 2023-07-16 23:04:06 +03:00
parent afeb659b82
commit 853b72f38d
No known key found for this signature in database
GPG key ID: 074C1D455EBEA4AC
2 changed files with 75 additions and 2 deletions

View file

@ -276,6 +276,42 @@ class TestNode:
)
class TestHashTag:
def test_only_one_element_in_body(self):
with pytest.raises(ValueError):
HashTag("test", "test")
def test_body_is_not_str(self):
with pytest.raises(ValueError):
HashTag(Text("test"))
def test_with_no_prefix(self):
node = HashTag("test")
assert node._body == ("#test",)
def test_with_prefix(self):
node = HashTag("#test")
assert node._body == ("#test",)
class TestCashTag:
def test_only_one_element_in_body(self):
with pytest.raises(ValueError):
CashTag("test", "test")
def test_body_is_not_str(self):
with pytest.raises(ValueError):
CashTag(Text("test"))
def test_with_no_prefix(self):
node = CashTag("USD")
assert node._body == ("$USD",)
def test_with_prefix(self):
node = CashTag("$USD")
assert node._body == ("$USD",)
class TestUtils:
def test_apply_entity(self):
node = _apply_entity(
@ -289,6 +325,16 @@ class TestUtils:
assert isinstance(node, Text)
assert len(node._body) == 4 # 3 + '\n'
def test_line_with_sep(self):
node = as_line("test", "test", "test", sep=" ")
assert isinstance(node, Text)
assert len(node._body) == 6 # 3 + 2 * ' ' + '\n'
def test_as_line_single_element_with_sep(self):
node = as_line("test", sep=" ")
assert isinstance(node, Text)
assert len(node._body) == 2 # 1 + '\n'
def test_as_list(self):
node = as_list("test", "test", "test")
assert isinstance(node, Text)