44 lines
992 B
Go
44 lines
992 B
Go
package parser_test
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"git.max-richter.dev/max/marka/parser"
|
|
)
|
|
|
|
func TestParseRecipe_Golden(t *testing.T) {
|
|
td := filepath.Join("testdata", "recipe_salad")
|
|
input := filepath.Join(td, "input.md")
|
|
output := filepath.Join(td, "output.json")
|
|
|
|
inputContent, err := os.ReadFile(input)
|
|
if err != nil {
|
|
t.Fatalf("read input.md: %v", err)
|
|
}
|
|
|
|
got, err := parser.ParseFile(string(inputContent))
|
|
if err != nil {
|
|
t.Fatalf("ParseFile: %v", err)
|
|
}
|
|
|
|
var want map[string]any
|
|
b, err := os.ReadFile(output)
|
|
if err != nil {
|
|
t.Fatalf("read expected.json: %v", err)
|
|
}
|
|
if err := json.Unmarshal(b, &want); err != nil {
|
|
t.Fatalf("unmarshal expected.json: %v", err)
|
|
}
|
|
|
|
// Deep structural compare
|
|
if !reflect.DeepEqual(want, got) {
|
|
gb, _ := json.MarshalIndent(got, "", " ")
|
|
wb, _ := json.MarshalIndent(want, "", " ")
|
|
t.Fatalf("parsed JSON mismatch\n--- got ---\n%s\n--- want ---\n%s", string(gb), string(wb))
|
|
}
|
|
}
|