(t *testing.T)
| 35 | } |
| 36 | |
| 37 | func Test_formatExamples(t *testing.T) { |
| 38 | t.Parallel() |
| 39 | |
| 40 | tests := []struct { |
| 41 | name string |
| 42 | examples []Example |
| 43 | wantMatches []string |
| 44 | }{ |
| 45 | { |
| 46 | name: "No examples", |
| 47 | examples: nil, |
| 48 | wantMatches: nil, |
| 49 | }, |
| 50 | { |
| 51 | name: "Output examples", |
| 52 | examples: []Example{ |
| 53 | { |
| 54 | Description: "Hello world.", |
| 55 | Command: "echo hello", |
| 56 | }, |
| 57 | { |
| 58 | Description: "Bye bye.", |
| 59 | Command: "echo bye", |
| 60 | }, |
| 61 | }, |
| 62 | wantMatches: []string{ |
| 63 | "Hello world", "echo hello", |
| 64 | "Bye bye", "echo bye", |
| 65 | }, |
| 66 | }, |
| 67 | { |
| 68 | name: "No description outputs commands", |
| 69 | examples: []Example{ |
| 70 | { |
| 71 | Command: "echo hello", |
| 72 | }, |
| 73 | }, |
| 74 | wantMatches: []string{ |
| 75 | "echo hello", |
| 76 | }, |
| 77 | }, |
| 78 | } |
| 79 | for _, tt := range tests { |
| 80 | t.Run(tt.name, func(t *testing.T) { |
| 81 | t.Parallel() |
| 82 | |
| 83 | got := FormatExamples(tt.examples...) |
| 84 | if len(tt.wantMatches) == 0 { |
| 85 | require.Empty(t, got) |
| 86 | } else { |
| 87 | for _, want := range tt.wantMatches { |
| 88 | require.Contains(t, got, want) |
| 89 | } |
| 90 | } |
| 91 | }) |
| 92 | } |
| 93 | } |
| 94 |
nothing calls this directly
no test coverage detected