Skip to content

Commit

Permalink
Added test for multiline scan
Browse files Browse the repository at this point in the history
  • Loading branch information
RamiAwar committed May 1, 2024
1 parent 60994f0 commit adae55d
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion cmd/new_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}

0 comments on commit adae55d

Please sign in to comment.