2019-08-28 17:57:16 +02:00
|
|
|
from moulinette.utils.text import search, searchf, prependlines, random_ascii
|
|
|
|
|
|
|
|
|
|
|
|
def test_search():
|
2019-11-25 17:21:13 +01:00
|
|
|
assert search("a", "a a a") == ["a", "a", "a"]
|
|
|
|
assert search("a", "a a a", count=2) == ["a", "a"]
|
2019-12-21 17:36:20 +01:00
|
|
|
assert search("a", "a a a", count=-1) == "a"
|
2019-11-25 17:21:13 +01:00
|
|
|
assert not search("a", "c c d")
|
2019-08-28 17:57:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_searchf(test_file):
|
2019-11-25 17:21:13 +01:00
|
|
|
assert searchf("bar", str(test_file)) == ["bar"]
|
|
|
|
assert not searchf("baz", str(test_file))
|
2019-08-28 17:57:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_prependlines():
|
2019-11-25 17:21:13 +01:00
|
|
|
assert prependlines("abc\nedf\nghi", "XXX") == "XXXabc\nXXXedf\nXXXghi"
|
|
|
|
assert prependlines("", "XXX") == "XXX"
|
2019-08-28 17:57:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_random_ascii():
|
2021-01-20 05:35:35 +01:00
|
|
|
assert isinstance(random_ascii(length=2), str)
|