From adae55d4c9a06f0b83af0e5501f77efa055a0ab7 Mon Sep 17 00:00:00 2001 From: Rami Awar Date: Wed, 1 May 2024 16:49:56 +0200 Subject: [PATCH] Added test for multiline scan --- cmd/new_test.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/cmd/new_test.go b/cmd/new_test.go index 33e1bc4..4959865 100644 --- a/cmd/new_test.go +++ b/cmd/new_test.go @@ -88,7 +88,6 @@ func TestScan_EmptyStringWithoutAllowEmpty(t *testing.T) { // Check if the input was printed got := result - // Check if the result matches the expected result if want != got { t.Errorf("Expected result %q, but got %q", want, got) @@ -99,3 +98,32 @@ func TestScan_EmptyStringWithoutAllowEmpty(t *testing.T) { t.Errorf("Expected error %v, but got %v", expectedError, err) } } + +func TestScanMultiLine_ExitsOnTwoEmptyLines(t *testing.T) { + prompt := "Enter something: " + secondPrompt := "whatever" + + input := "test\nnewline here\nand another;\n\n\n" // Simulated user input + want := "test\nnewline here\nand another;" // Expected output + expectedError := error(nil) + + // Create a buffer for output + var outputBuffer bytes.Buffer + // Create a mock ReadCloser for input + inputReader := &MockReadCloser{strings.NewReader(input)} + + result, err := scanMultiLine(prompt, secondPrompt, &outputBuffer, inputReader) + + // Check if the input was printed + got := result + + // Check if the result matches the expected result + if want != got { + t.Errorf("Expected result %q, but got %q", want, got) + } + + // Check if the error matches the expected error + if err != expectedError { + t.Errorf("Expected error %v, but got %v", expectedError, err) + } +}