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