Conditions | 5 |
Total Lines | 56 |
Code Lines | 49 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | package tests |
||
11 | func TestParseJa(t *testing.T) { |
||
12 | cases := []struct { |
||
13 | date time.Time |
||
14 | res string |
||
15 | }{ |
||
16 | {utils.SubMinutes(1), "1分前"}, |
||
17 | {utils.SubMinutes(2), "2分前"}, |
||
18 | {utils.SubMinutes(5), "5分前"}, |
||
19 | {utils.SubMinutes(9), "9分前"}, |
||
20 | {utils.SubMinutes(10), "10分前"}, |
||
21 | {utils.SubMinutes(11), "11分前"}, |
||
22 | {utils.SubMinutes(20), "20分前"}, |
||
23 | {utils.SubMinutes(21), "21分前"}, |
||
24 | {utils.SubMinutes(22), "22分前"}, |
||
25 | {utils.SubMinutes(30), "30分前"}, |
||
26 | {utils.SubMinutes(31), "31分前"}, |
||
27 | {utils.SubMinutes(59), "59分前"}, |
||
28 | {utils.SubHours(1), "1時間前"}, |
||
29 | {utils.SubHours(2), "2時間前"}, |
||
30 | {utils.SubHours(9), "9時間前"}, |
||
31 | {utils.SubHours(10), "10時間前"}, |
||
32 | {utils.SubHours(11), "11時間前"}, |
||
33 | {utils.SubHours(20), "20時間前"}, |
||
34 | {utils.SubHours(21), "21時間前"}, |
||
35 | {utils.SubHours(23), "23時間前"}, |
||
36 | {utils.SubDays(1), "1日前"}, |
||
37 | {utils.SubDays(2), "2日前"}, |
||
38 | {utils.SubDays(4), "4日前"}, |
||
39 | {utils.SubDays(5), "5日前"}, |
||
40 | {utils.SubDays(6), "6日前"}, |
||
41 | {utils.SubWeeks(1), "1週間前"}, |
||
42 | {utils.SubWeeks(2), "2週間前"}, |
||
43 | {utils.SubWeeks(3), "3週間前"}, |
||
44 | {utils.SubMonths(1), "1ヶ月前"}, |
||
45 | {utils.SubMonths(2), "2ヶ月前"}, |
||
46 | {utils.SubMonths(9), "9ヶ月前"}, |
||
47 | {utils.SubMonths(11), "11ヶ月前"}, |
||
48 | {utils.SubYears(1), "1年前"}, |
||
49 | {utils.SubYears(2), "2年前"}, |
||
50 | {utils.SubYears(21), "21年前"}, |
||
51 | {utils.SubYears(31), "31年前"}, |
||
52 | {utils.SubYears(100), "100年前"}, |
||
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.LangJa}) |
||
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 %s, but got %s instead", tc.res, res) |
||
67 | } |
||
106 |