2021-03-21 19:05:59 +00:00
|
|
|
// SPDX-FileCopyrightText: 2021 Luke Granger-Brown <depot@lukegb.com>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package minicheddar_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os/exec"
|
|
|
|
"testing"
|
|
|
|
|
2024-11-16 15:30:41 +00:00
|
|
|
"git.lukegb.com/lukegb/depot/web/fup/minicheddar"
|
2021-03-21 19:05:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSpawn(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
t.Cleanup(cancel)
|
|
|
|
|
|
|
|
cpath, err := exec.LookPath("cheddar")
|
|
|
|
if err != nil {
|
|
|
|
t.Skip("couldn't find cheddar")
|
|
|
|
}
|
|
|
|
|
|
|
|
cheddar, err := minicheddar.Spawn(ctx, cpath)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("minicheddar.Spawn: %v", err)
|
|
|
|
}
|
|
|
|
defer cheddar.Close()
|
|
|
|
|
|
|
|
t.Run("Code", func(t *testing.T) {
|
|
|
|
html, err := cheddar.Code(ctx, "index.html", "Some Theme", "<!DOCTYPE html>\n<html>\n")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("minicheddar.Code: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if html.String() == "" {
|
|
|
|
t.Fatalf("minicheddar.Code = %q; want non-empty string", html.String())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Markdown", func(t *testing.T) {
|
|
|
|
html, err := cheddar.Markdown(ctx, "* Bulleted\n* Lists\n")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("minicheddar.Markdown: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if html.String() == "" {
|
|
|
|
t.Fatalf("minicheddar.Markdown = %q; want non-empty string", html.String())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|