| Conditions | 5 |
| Total Lines | 57 |
| Code Lines | 50 |
| 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 TestParseBe(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(6), "6 дзён таму"}, |
||
| 39 | {utils.SubWeeks(1), "1 тыдзень таму"}, |
||
| 40 | {utils.SubWeeks(2), "2 тыдні таму"}, |
||
| 41 | {utils.SubWeeks(3), "3 тыдні таму"}, |
||
| 42 | {utils.SubMonths(1), "1 месяц таму"}, |
||
| 43 | {utils.SubMonths(2), "2 месяцы таму"}, |
||
| 44 | {utils.SubMonths(9), "9 месяцаў таму"}, |
||
| 45 | {utils.SubMonths(11), "11 месяцаў таму"}, |
||
| 46 | {utils.SubYears(1), "1 год таму"}, |
||
| 47 | {utils.SubYears(2), "2 гады таму"}, |
||
| 48 | {utils.SubYears(5), "5 гадоў таму"}, |
||
| 49 | {utils.SubYears(6), "6 гадоў таму"}, |
||
| 50 | {utils.SubYears(7), "7 гадоў таму"}, |
||
| 51 | {utils.SubYears(21), "21 год таму"}, |
||
| 52 | {utils.SubYears(31), "31 год таму"}, |
||
| 53 | {utils.SubYears(100), "100 гадоў таму"}, |
||
| 54 | } |
||
| 55 | |||
| 56 | for _, tc := range cases { |
||
| 57 | t.Run("result for "+tc.date.String(), func(test *testing.T) { |
||
| 58 | ago.Reconfigure(ago.Config{Language: ago.LangBe}) |
||
| 59 | |||
| 60 | res, err := ago.Parse(tc.date) |
||
| 61 | |||
| 62 | if err != nil { |
||
| 63 | test.Errorf("Error must be nil, but got %v instead", err) |
||
| 64 | } |
||
| 65 | |||
| 66 | if res != tc.res { |
||
| 67 | test.Errorf("Result must be %s, but got %s instead", tc.res, res) |
||
| 68 | } |
||
| 108 |