File: words_test.go

package info (click to toggle)
golang-github-dustin-go-humanize 0.0~git20171111.bb3d318-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, buster-backports
  • size: 168 kB
  • sloc: makefile: 2
file content (94 lines) | stat: -rw-r--r-- 2,447 bytes parent folder | download
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package english

import (
	"testing"
)

func TestPluralWord(t *testing.T) {
	tests := []struct {
		n                int
		singular, plural string
		want             string
	}{
		{0, "object", "", "objects"},
		{1, "object", "", "object"},
		{-1, "object", "", "objects"},
		{42, "object", "", "objects"},
		{2, "vax", "vaxen", "vaxen"},

		// special cases
		{2, "index", "", "indices"},

		// ending in a sibilant sound
		{2, "bus", "", "buses"},
		{2, "bush", "", "bushes"},
		{2, "watch", "", "watches"},
		{2, "box", "", "boxes"},

		// ending with 'o' preceded by a consonant
		{2, "hero", "", "heroes"},

		// ending with 'y' preceded by a consonant
		{2, "lady", "", "ladies"},
		{2, "day", "", "days"},
	}
	for _, tt := range tests {
		if got := PluralWord(tt.n, tt.singular, tt.plural); got != tt.want {
			t.Errorf("PluralWord(%d, %q, %q)=%q; want: %q", tt.n, tt.singular, tt.plural, got, tt.want)
		}
	}
}

func TestPlural(t *testing.T) {
	tests := []struct {
		n                int
		singular, plural string
		want             string
	}{
		{1, "object", "", "1 object"},
		{42, "object", "", "42 objects"},
	}
	for _, tt := range tests {
		if got := Plural(tt.n, tt.singular, tt.plural); got != tt.want {
			t.Errorf("Plural(%d, %q, %q)=%q; want: %q", tt.n, tt.singular, tt.plural, got, tt.want)
		}
	}
}

func TestWordSeries(t *testing.T) {
	tests := []struct {
		words       []string
		conjunction string
		want        string
	}{
		{[]string{}, "and", ""},
		{[]string{"foo"}, "and", "foo"},
		{[]string{"foo", "bar"}, "and", "foo and bar"},
		{[]string{"foo", "bar", "baz"}, "and", "foo, bar and baz"},
		{[]string{"foo", "bar", "baz"}, "or", "foo, bar or baz"},
	}
	for _, tt := range tests {
		if got := WordSeries(tt.words, tt.conjunction); got != tt.want {
			t.Errorf("WordSeries(%q, %q)=%q; want: %q", tt.words, tt.conjunction, got, tt.want)
		}
	}
}

func TestOxfordWordSeries(t *testing.T) {
	tests := []struct {
		words       []string
		conjunction string
		want        string
	}{
		{[]string{}, "and", ""},
		{[]string{"foo"}, "and", "foo"},
		{[]string{"foo", "bar"}, "and", "foo and bar"},
		{[]string{"foo", "bar", "baz"}, "and", "foo, bar, and baz"},
		{[]string{"foo", "bar", "baz"}, "or", "foo, bar, or baz"},
	}
	for _, tt := range tests {
		if got := OxfordWordSeries(tt.words, tt.conjunction); got != tt.want {
			t.Errorf("OxfordWordSeries(%q, %q)=%q; want: %q", tt.words, tt.conjunction, got, tt.want)
		}
	}
}