Passed
Push — v3.0.0 ( 670783...5b9f70 )
by Serhii
01:17
created

tests.TestParseWithNoSuffixFlag   B

Complexity

Conditions 4

Size

Total Lines 62
Code Lines 58

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 58
dl 0
loc 62
rs 8.3745
c 0
b 0
f 0
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
package tests
2
3
import (
4
	"testing"
5
	"time"
6
7
	"github.com/SerhiiCho/timeago/v3"
8
	"github.com/SerhiiCho/timeago/v3/config"
9
)
10
11
func TestParseWithNoSuffixFlag(t *testing.T) {
12
	cases := []struct {
13
		date   time.Time
14
		result string
15
		lang   string
16
	}{
17
		{subMinutes(1), "1 minute", "en"},
18
		{subMinutes(2), "2 minutes", "en"},
19
		{subMinutes(3), "3 minutes", "en"},
20
		{subMinutes(4), "4 minutes", "en"},
21
		{subMinutes(5), "5 minutes", "en"},
22
		{subMinutes(10), "10 minutes", "en"},
23
		{subMinutes(11), "11 minutes", "en"},
24
		{subMinutes(20), "20 minutes", "en"},
25
		{subMinutes(21), "21 minutes", "en"},
26
		{subMinutes(22), "22 minutes", "en"},
27
		{subMinutes(30), "30 minutes", "en"},
28
		{subMinutes(31), "31 minutes", "en"},
29
		{subHours(1), "1 hour", "en"},
30
		{subHours(2), "2 hours", "en"},
31
		{subHours(9), "9 hours", "en"},
32
		{subHours(10), "10 hours", "en"},
33
		{subHours(11), "11 hours", "en"},
34
		{subHours(20), "20 hours", "en"},
35
		{subHours(21), "21 hours", "en"},
36
		{subHours(23), "23 hours", "en"},
37
		{subDays(1), "1 day", "en"},
38
		{subDays(2), "2 days", "en"},
39
		{subDays(6), "6 days", "en"},
40
		{subWeeks(1), "1 week", "en"},
41
		{subWeeks(2), "2 weeks", "en"},
42
		{subWeeks(3), "3 weeks", "en"},
43
		{subMonths(1), "1 month", "en"},
44
		{subMonths(2), "2 months", "en"},
45
		{subMonths(3), "3 months", "en"},
46
		{subMonths(4), "4 months", "en"},
47
		{subMonths(5), "5 months", "en"},
48
		{subMonths(6), "6 months", "en"},
49
		{subMonths(7), "7 months", "en"},
50
		{subMonths(8), "8 months", "en"},
51
		{subMonths(9), "9 months", "en"},
52
		{subMonths(10), "10 months", "en"},
53
		{subMonths(11), "11 months", "en"},
54
		{subMonths(12), "1 year", "en"},
55
		{subYears(4), "4 years", "en"},
56
		{subYears(5), "5 years", "en"},
57
		{subYears(11), "11 years", "en"},
58
		{subYears(29), "29 years", "en"},
59
		{subYears(92), "92 years", "en"},
60
		{subMinutes(1), "1 минута", "ru"},
61
		{subMinutes(2), "2 минуты", "ru"},
62
		{subMonths(3), "3 месяца", "ru"},
63
		{subWeeks(2), "2 недели", "ru"},
64
		{subYears(77), "77 лет", "ru"},
65
	}
66
67
	for _, tc := range cases {
68
		t.Run("result for "+tc.date.String(), func(test *testing.T) {
69
			timeago.Configure(&config.Config{Language: tc.lang})
70
71
			if res := timeago.Parse(tc.date, "noSuffix"); res != tc.result {
72
				test.Errorf("Result must be %s, but got %s instead", tc.result, res)
73
			}
74
		})
75
	}
76
}
77