fixed processFrontmatter and added test

This commit is contained in:
Daniel Fichtinger 2025-01-01 23:55:16 -05:00
parent 35c14f09c0
commit af81617db5
No known key found for this signature in database
GPG key ID: D1B0947B25420214
7 changed files with 162 additions and 183 deletions

View 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)
}
}