| 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 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 | } |
||
| 106 |