Skip to content

Commit

Permalink
append seems to be working now
Browse files Browse the repository at this point in the history
  • Loading branch information
EvilLord666 committed Nov 7, 2024
1 parent 4220ab9 commit 1c1dad1
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion file_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestWriteAllLines(t *testing.T) {
" \"name\": \"Michael Ushakov\"",
"}",
}
testFile := "sample_test.txt"
testFile := "write_all_lines_test.txt"
err := gfu.WriteAllLines(testFile, lines, "\n")
assert.NoError(t, err)
readLines, err := gfu.ReadAllLines(testFile, true)
Expand All @@ -115,5 +115,34 @@ func TestWriteAllLines(t *testing.T) {
}

func TestAppendAllLines(t *testing.T) {
lines := []string{
"Line one",
"Line two",
"Line three",
"Line four",
"{",
" \"id\": 1,",
" \"name\": \"Michael Ushakov\"",
"}",
}
testFile := "append_all_lines_test.txt"
err := gfu.WriteAllLines(testFile, lines, "\n")
assert.NoError(t, err)

appendingLines := []string{
"Line five",
"Line six",
"<html><head><title>This is the simplest demo page</title></head><body><h1>Main page header</h1></body></html>",
"Line seven",
}

err = gfu.AppendAllLines(testFile, appendingLines, "\n")
assert.NoError(t, err)
expectedLines := make([]string, 0)
expectedLines = append(expectedLines, lines...)
expectedLines = append(expectedLines, appendingLines...)
actualLines, err := gfu.ReadAllLines(testFile, true)
assert.NoError(t, err)
testingutils.CheckStrings(t, expectedLines, actualLines, true, true)
_ = os.Remove(testFile)
}

0 comments on commit 1c1dad1

Please sign in to comment.