File: test_join.py

package info (click to toggle)
python-inflect 7.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 496 kB
  • sloc: python: 4,807; makefile: 3
file content (59 lines) | stat: -rw-r--r-- 1,678 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import inflect


def test_join():
    p = inflect.engine()

    # Three words...
    words = "apple banana carrot".split()

    assert p.join(words), "apple, banana == and carrot"

    assert p.join(words, final_sep="") == "apple, banana and carrot"

    assert p.join(words, final_sep="...") == "apple, banana... and carrot"

    assert p.join(words, final_sep="...", conj="") == "apple, banana... carrot"

    assert p.join(words, conj="or") == "apple, banana, or carrot"

    # Three words with semicolons...
    words = ("apple,fuji", "banana", "carrot")

    assert p.join(words) == "apple,fuji; banana; and carrot"

    assert p.join(words, final_sep="") == "apple,fuji; banana and carrot"

    assert p.join(words, final_sep="...") == "apple,fuji; banana... and carrot"

    assert p.join(words, final_sep="...", conj="") == "apple,fuji; banana... carrot"

    assert p.join(words, conj="or") == "apple,fuji; banana; or carrot"

    # Two words...
    words = ("apple", "carrot")

    assert p.join(words) == "apple and carrot"

    assert p.join(words, final_sep="") == "apple and carrot"

    assert p.join(words, final_sep="...") == "apple and carrot"

    assert p.join(words, final_sep="...", conj="") == "apple carrot"

    assert p.join(words, final_sep="...", conj="", conj_spaced=False) == "applecarrot"

    assert p.join(words, conj="or") == "apple or carrot"

    # One word...
    words = ["carrot"]

    assert p.join(words) == "carrot"

    assert p.join(words, final_sep="") == "carrot"

    assert p.join(words, final_sep="...") == "carrot"

    assert p.join(words, final_sep="...", conj="") == "carrot"

    assert p.join(words, conj="or") == "carrot"