Refactoring writer_posix_test
Vladimir Bauer
8 years ago
| 9 | 9 | "github.com/vbauerster/mpb/cwriter" |
| 10 | 10 | ) |
| 11 | 11 | |
| 12 | var clearSequence = fmt.Sprintf("%c[%dA%c[2K\r", 27, 1, 27) | |
| 12 | var ( | |
| 13 | cursorUp = fmt.Sprintf("%c[%dA", cwriter.ESC, 1) | |
| 14 | clearLine = fmt.Sprintf("%c[2K\r", cwriter.ESC) | |
| 15 | clearCursorAndLine = cursorUp + clearLine | |
| 16 | ) | |
| 13 | 17 | |
| 14 | 18 | // TestWriterPosix by writing and flushing many times. The output buffer |
| 15 | 19 | // must contain the clearCursor and clearLine sequences. |
| 21 | 25 | input, expectedOutput string |
| 22 | 26 | }{ |
| 23 | 27 | {input: "foo\n", expectedOutput: "foo\n"}, |
| 24 | {input: "bar\n", expectedOutput: "foo\n" + clearSequence + "bar\n"}, | |
| 25 | {input: "fizz\n", expectedOutput: "foo\n" + clearSequence + "bar\n" + clearSequence + "fizz\n"}, | |
| 28 | {input: "bar\n", expectedOutput: "foo\n" + clearCursorAndLine + "bar\n"}, | |
| 29 | {input: "fizz\n", expectedOutput: "foo\n" + clearCursorAndLine + "bar\n" + clearCursorAndLine + "fizz\n"}, | |
| 26 | 30 | } { |
| 27 | 31 | t.Run(tcase.input, func(t *testing.T) { |
| 28 | 32 | w.Write([]byte(tcase.input)) |