TestGetQuotedInput tests GetQuotedInput
(t *testing.T)
| 67 | |
| 68 | // TestGetQuotedInput tests GetQuotedInput |
| 69 | func TestGetQuotedInput(t *testing.T) { |
| 70 | testCases := []struct { |
| 71 | description string |
| 72 | input string |
| 73 | expected string |
| 74 | }{ |
| 75 | {"Remove single quotes", `'/path/to/file'`, `/path/to/file`}, |
| 76 | {"Remove double quotes", `"/path/to/file"`, `/path/to/file`}, |
| 77 | {"Remove spaces", ` /path/to/file `, `/path/to/file`}, |
| 78 | {"Remove all quotes and spaces", ` ''' """ /path/to/file ''' """ `, `/path/to/file`}, |
| 79 | {"Quotes and spaces are not removed from the middle", `/path/'" to/file`, `/path/'" to/file`}, |
| 80 | } |
| 81 | for _, tc := range testCases { |
| 82 | t.Run(tc.description, func(t *testing.T) { |
| 83 | assert := asrt.New(t) |
| 84 | restoreOutput := util.CaptureUserOut() |
| 85 | scanner := bufio.NewScanner(strings.NewReader(tc.input)) |
| 86 | util.SetInputScanner(scanner) |
| 87 | result := util.GetQuotedInput("nodefault") |
| 88 | assert.EqualValues(tc.expected, result) |
| 89 | _ = restoreOutput() |
| 90 | }) |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | // TestCaptureUserOut ensures capturing of stdout works as expected. |
| 95 | func TestCaptureUserOut(t *testing.T) { |
nothing calls this directly
no test coverage detected