fixed processFrontmatter and added test
This commit is contained in:
parent
35c14f09c0
commit
af81617db5
7 changed files with 162 additions and 183 deletions
37
internal/util/file_test.go
Normal file
37
internal/util/file_test.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
// FILE: internal/util/file_test.go
|
||||
package util
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestReadNLines(t *testing.T) {
|
||||
// Create a temporary file
|
||||
tmpfile, err := os.CreateTemp("", "testfile")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.Remove(tmpfile.Name()) // clean up
|
||||
|
||||
// Write some lines to the temporary file
|
||||
content := []byte("line1\nline2\nline3\nline4\nline5\n")
|
||||
if _, err := tmpfile.Write(content); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := tmpfile.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Test the ReadNLines function
|
||||
lines, err := ReadNLines(tmpfile.Name(), 3)
|
||||
if err != nil {
|
||||
t.Fatalf("ReadNLines failed: %v", err)
|
||||
}
|
||||
|
||||
expected := []byte("line1\nline2\nline3\n")
|
||||
if !bytes.Equal(lines, expected) {
|
||||
t.Errorf("Expected %q, got %q", expected, lines)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue