refactor: extract read all text method to file package

This commit is contained in:
Stevan Freeborn
2025-12-03 10:24:16 -06:00
parent 6633b702c5
commit 3b86c59044
3 changed files with 24 additions and 8 deletions
+10
View File
@@ -24,3 +24,13 @@ func ReadLines(filePath string) []string {
return lines
}
func ReadAllText(filePath string) string {
fileContent, readErr := os.ReadFile(filePath)
if readErr != nil {
return ""
}
return string(fileContent)
}
+10
View File
@@ -19,3 +19,13 @@ func TestReadLines(t *testing.T) {
t.Errorf("got %s but expected %s", result, expectedLines)
}
}
func TestReadAllText(t *testing.T) {
expectedText := "hello\r\nworld\r\n"
result := file.ReadAllText("test.txt")
if result != expectedText {
t.Errorf("got %q but expected %q", result, expectedText)
}
}