1
|
|
|
package tests |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"testing" |
5
|
|
|
"time" |
6
|
|
|
|
7
|
|
|
ago "github.com/SerhiiCho/timeago/v3" |
8
|
|
|
"github.com/SerhiiCho/timeago/v3/internal/utils" |
9
|
|
|
) |
10
|
|
|
|
11
|
|
|
func TestParseFr(t *testing.T) { |
12
|
|
|
cases := []struct { |
13
|
|
|
date time.Time |
14
|
|
|
res string |
15
|
|
|
}{ |
16
|
|
|
{utils.SubMinutes(1), "il y a 1 minute"}, |
17
|
|
|
{utils.SubMinutes(2), "il y a 2 minutes"}, |
18
|
|
|
{utils.SubMinutes(5), "il y a 5 minutes"}, |
19
|
|
|
{utils.SubMinutes(9), "il y a 9 minutes"}, |
20
|
|
|
{utils.SubMinutes(10), "il y a 10 minutes"}, |
21
|
|
|
{utils.SubMinutes(11), "il y a 11 minutes"}, |
22
|
|
|
{utils.SubMinutes(20), "il y a 20 minutes"}, |
23
|
|
|
{utils.SubMinutes(21), "il y a 21 minutes"}, |
24
|
|
|
{utils.SubMinutes(22), "il y a 22 minutes"}, |
25
|
|
|
{utils.SubMinutes(30), "il y a 30 minutes"}, |
26
|
|
|
{utils.SubMinutes(31), "il y a 31 minutes"}, |
27
|
|
|
{utils.SubMinutes(59), "il y a 59 minutes"}, |
28
|
|
|
{utils.SubHours(1), "il y a 1 heure"}, |
29
|
|
|
{utils.SubHours(2), "il y a 2 heures"}, |
30
|
|
|
{utils.SubHours(9), "il y a 9 heures"}, |
31
|
|
|
{utils.SubHours(10), "il y a 10 heures"}, |
32
|
|
|
{utils.SubHours(11), "il y a 11 heures"}, |
33
|
|
|
{utils.SubHours(20), "il y a 20 heures"}, |
34
|
|
|
{utils.SubHours(21), "il y a 21 heures"}, |
35
|
|
|
{utils.SubHours(23), "il y a 23 heures"}, |
36
|
|
|
{utils.SubDays(1), "il y a 1 jour"}, |
37
|
|
|
{utils.SubDays(2), "il y a 2 jours"}, |
38
|
|
|
{utils.SubDays(4), "il y a 4 jours"}, |
39
|
|
|
{utils.SubDays(5), "il y a 5 jours"}, |
40
|
|
|
{utils.SubDays(6), "il y a 6 jours"}, |
41
|
|
|
{utils.SubWeeks(1), "il y a 1 semaine"}, |
42
|
|
|
{utils.SubWeeks(2), "il y a 2 semaines"}, |
43
|
|
|
{utils.SubWeeks(3), "il y a 3 semaines"}, |
44
|
|
|
{utils.SubMonths(1), "il y a 1 mois"}, |
45
|
|
|
{utils.SubMonths(2), "il y a 2 mois"}, |
46
|
|
|
{utils.SubMonths(9), "il y a 9 mois"}, |
47
|
|
|
{utils.SubMonths(11), "il y a 11 mois"}, |
48
|
|
|
{utils.SubYears(1), "il y a 1 an"}, |
49
|
|
|
{utils.SubYears(2), "il y a 2 ans"}, |
50
|
|
|
{utils.SubYears(21), "il y a 21 ans"}, |
51
|
|
|
{utils.SubYears(31), "il y a 31 ans"}, |
52
|
|
|
{utils.SubYears(100), "il y a 100 ans"}, |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
for _, tc := range cases { |
56
|
|
|
t.Run("result for "+tc.date.String(), func(test *testing.T) { |
57
|
|
|
ago.Reconfigure(ago.Config{Language: ago.LangFr}) |
58
|
|
|
|
59
|
|
|
res, err := ago.Parse(tc.date) |
60
|
|
|
|
61
|
|
|
if err != nil { |
62
|
|
|
test.Errorf("Error must be nil, but got %v instead", err) |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if res != tc.res { |
66
|
|
|
test.Errorf("Result must be %q, but got %q instead", tc.res, res) |
67
|
|
|
} |
68
|
|
|
}) |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
func TestParseFrWithSeconds(t *testing.T) { |
73
|
|
|
cases := []struct { |
74
|
|
|
date time.Time |
75
|
|
|
res []string |
76
|
|
|
}{ |
77
|
|
|
{utils.SubSeconds(0), []string{"il y a 0 secondes", "il y a 1 seconde"}}, |
78
|
|
|
{utils.SubSeconds(1), []string{"il y a 1 seconde", "il y a 2 secondes"}}, |
79
|
|
|
{utils.SubSeconds(2), []string{"il y a 2 secondes", "il y a 3 secondes"}}, |
80
|
|
|
{utils.SubSeconds(9), []string{"il y a 9 secondes", "il y a 10 secondes"}}, |
81
|
|
|
{utils.SubSeconds(10), []string{"il y a 10 secondes", "il y a 11 secondes"}}, |
82
|
|
|
{utils.SubSeconds(11), []string{"il y a 11 secondes", "il y a 12 secondes"}}, |
83
|
|
|
{utils.SubSeconds(20), []string{"il y a 20 secondes", "il y a 21 secondes"}}, |
84
|
|
|
{utils.SubSeconds(21), []string{"il y a 21 secondes", "il y a 22 secondes"}}, |
85
|
|
|
{utils.SubSeconds(22), []string{"il y a 22 secondes", "il y a 23 secondes"}}, |
86
|
|
|
{utils.SubSeconds(30), []string{"il y a 30 secondes", "il y a 31 secondes"}}, |
87
|
|
|
{utils.SubSeconds(59), []string{"il y a 59 secondes", "il y a 1 minute"}}, |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
for _, tc := range cases { |
91
|
|
|
t.Run("result for "+tc.date.String(), func(test *testing.T) { |
92
|
|
|
ago.Reconfigure(ago.Config{Language: ago.LangFr}) |
93
|
|
|
|
94
|
|
|
res, err := ago.Parse(tc.date) |
95
|
|
|
|
96
|
|
|
if err != nil { |
97
|
|
|
test.Errorf("Error must be nil, but got %v instead", err) |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
if res != tc.res[0] && res != tc.res[1] { |
101
|
|
|
test.Errorf("Result must be %q or %q, but got %q instead", tc.res[0], tc.res[1], res) |
102
|
|
|
} |
103
|
|
|
}) |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|