Conditions | 3 |
Total Lines | 53 |
Code Lines | 31 |
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 urlpath_test |
||
12 | func TestJoin(t *testing.T) { |
||
13 | testCases := []struct { |
||
14 | input []string |
||
15 | expectedOutput string |
||
16 | }{ |
||
17 | { |
||
18 | input: []string{"/home"}, |
||
19 | expectedOutput: "/home", |
||
20 | }, |
||
21 | { |
||
22 | input: []string{"/home/"}, |
||
23 | expectedOutput: "/home/", |
||
24 | }, |
||
25 | { |
||
26 | input: []string{"/home/", "test"}, |
||
27 | expectedOutput: "/home/test", |
||
28 | }, |
||
29 | { |
||
30 | input: []string{"/home/", "/test"}, |
||
31 | expectedOutput: "/home/test", |
||
32 | }, |
||
33 | { |
||
34 | input: []string{"/home/", "/test/"}, |
||
35 | expectedOutput: "/home/test/", |
||
36 | }, |
||
37 | { |
||
38 | input: []string{"/home", "/test/"}, |
||
39 | expectedOutput: "/home/test/", |
||
40 | }, |
||
41 | { |
||
42 | input: []string{"/home", "test/"}, |
||
43 | expectedOutput: "/home/test/", |
||
44 | }, |
||
45 | { |
||
46 | input: []string{"/home", "test"}, |
||
47 | expectedOutput: "/home/test", |
||
48 | }, |
||
49 | } |
||
50 | |||
51 | for _, tc := range testCases { |
||
52 | tc := tc |
||
53 | scenario := fmt.Sprintf( |
||
54 | "Input: `%s`, Expected output: `%s`", |
||
55 | strings.Join(tc.input, ","), |
||
56 | tc.expectedOutput, |
||
57 | ) |
||
58 | |||
59 | t.Run(scenario, func(t *testing.T) { |
||
60 | t.Parallel() |
||
61 | |||
62 | output := urlpath.Join(tc.input...) |
||
63 | |||
64 | assert.Equal(t, tc.expectedOutput, output) |
||
65 | }) |
||
68 |