|
20 | 20 | # this package
|
21 | 21 | from domdf_python_tools import utils
|
22 | 22 | from domdf_python_tools.testing import testing_boolean_values
|
23 |
| -from domdf_python_tools.utils import Len, chunks, double_chain, list2str, posargs2kwargs, pyversion, str2tuple |
| 23 | +from domdf_python_tools.utils import ( |
| 24 | + Len, chunks, convert_indents, double_chain, list2str, posargs2kwargs, pyversion, str2tuple, word_join |
| 25 | + ) |
24 | 26 |
|
25 | 27 |
|
26 | 28 | def test_pyversion():
|
@@ -397,3 +399,57 @@ def demo_function(arg1, arg2, arg3):
|
397 | 399 | )
|
398 | 400 | def test_posargs2kwargs(args, posarg_names, kwargs, expects):
|
399 | 401 | assert posargs2kwargs(args, posarg_names, kwargs) == expects
|
| 402 | + |
| 403 | + |
| 404 | +def test_word_join(): |
| 405 | + assert word_join([]) == '' |
| 406 | + |
| 407 | + assert word_join(["bob"]) == "bob" |
| 408 | + assert word_join(["bob", "alice"]) == "bob and alice" |
| 409 | + assert word_join(["bob", "alice", "fred"]) == "bob, alice and fred" |
| 410 | + |
| 411 | + assert word_join(["bob"], use_repr=True) == "'bob'" |
| 412 | + assert word_join(["bob", "alice"], use_repr=True) == "'bob' and 'alice'" |
| 413 | + assert word_join(["bob", "alice", "fred"], use_repr=True) == "'bob', 'alice' and 'fred'" |
| 414 | + |
| 415 | + assert word_join(["bob"], use_repr=True, oxford=True) == "'bob'" |
| 416 | + assert word_join(["bob", "alice"], use_repr=True, oxford=True) == "'bob' and 'alice'" |
| 417 | + assert word_join(["bob", "alice", "fred"], use_repr=True, oxford=True) == "'bob', 'alice', and 'fred'" |
| 418 | + |
| 419 | + assert word_join(()) == '' |
| 420 | + |
| 421 | + assert word_join(("bob", )) == "bob" |
| 422 | + assert word_join(("bob", "alice")) == "bob and alice" |
| 423 | + assert word_join(("bob", "alice", "fred")) == "bob, alice and fred" |
| 424 | + |
| 425 | + assert word_join(("bob", ), use_repr=True) == "'bob'" |
| 426 | + assert word_join(("bob", "alice"), use_repr=True) == "'bob' and 'alice'" |
| 427 | + assert word_join(("bob", "alice", "fred"), use_repr=True) == "'bob', 'alice' and 'fred'" |
| 428 | + |
| 429 | + assert word_join(("bob", ), use_repr=True, oxford=True) == "'bob'" |
| 430 | + assert word_join(("bob", "alice"), use_repr=True, oxford=True) == "'bob' and 'alice'" |
| 431 | + assert word_join(("bob", "alice", "fred"), use_repr=True, oxford=True) == "'bob', 'alice', and 'fred'" |
| 432 | + |
| 433 | + |
| 434 | +def test_convert_indents(): |
| 435 | + |
| 436 | + # TODO: test 'to' |
| 437 | + |
| 438 | + assert convert_indents("hello world") == "hello world" |
| 439 | + assert convert_indents(" hello world") == " hello world" |
| 440 | + assert convert_indents(" hello world") == " hello world" |
| 441 | + assert convert_indents(" hello world") == " hello world" |
| 442 | + |
| 443 | + assert convert_indents("hello world", tab_width=2) == "hello world" |
| 444 | + assert convert_indents(" hello world", tab_width=2) == " hello world" |
| 445 | + assert convert_indents(" hello world", tab_width=2) == " hello world" |
| 446 | + assert convert_indents(" hello world", tab_width=2) == " hello world" |
| 447 | + |
| 448 | + assert convert_indents("hello world", from_=" ") == "hello world" |
| 449 | + assert convert_indents(" hello world", from_=" ") == " hello world" |
| 450 | + assert convert_indents(" hello world", from_=" ") == " hello world" |
| 451 | + assert convert_indents(" hello world", from_=" ") == " hello world" |
| 452 | + |
| 453 | + assert convert_indents("hello world", tab_width=2, from_=" ") == "hello world" |
| 454 | + assert convert_indents(" hello world", tab_width=2, from_=" ") == " hello world" |
| 455 | + assert convert_indents(" hello world", tab_width=2, from_=" ") == " hello world" |
0 commit comments