Skip to content

Commit

Permalink
test(reader): Prevent regression with empty files
Browse files Browse the repository at this point in the history
Updated tests in reader_test.go to include checks for handling empty files in ParseContent function of reader package. Added tests to verify that ParseContent correctly returns an empty string when provided with an empty file path and a newline character string. This ensures consistent behavior and addresses potential issues highlighted in #31.
  • Loading branch information
supitsdu committed Jun 30, 2024
1 parent 9a59b6c commit a645436
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tests/reader/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ func TestParseContent(t *testing.T) {
}

// Expected result when parsing an empty file
expected := "\n"
emptyString := ""
newlineString := "\n"

// Create a FileContentReader for the empty file
testReader := reader.FileContentReader{FilePath: emptyFile.Name()}
Expand All @@ -115,9 +116,12 @@ func TestParseContent(t *testing.T) {
t.Fatalf("Expected no error, got: %v", err)
}

// Verify the actual output matches the expected output
if actual != expected {
t.Errorf("Expected %s but got %s", expected, actual)
if actual != emptyString {
t.Error("When given an empty file returned something else.")
}

if actual == newlineString {
t.Error("When given empty file returned one with newline '\\n' character. See: https://github.com/supitsdu/clipper/issues/31#issue-2379691170")
}
})

Expand Down

0 comments on commit a645436

Please sign in to comment.