2023-04-10 09:07:08 +02:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"git.defalsify.org/festive/cache"
|
|
|
|
"git.defalsify.org/festive/resource"
|
|
|
|
"git.defalsify.org/festive/state"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLoopCorrect(t *testing.T) {
|
|
|
|
generateTestData(t)
|
|
|
|
ctx := context.TODO()
|
|
|
|
st := state.NewState(0)
|
|
|
|
//rs := NewFsWrapper(dataDir, &st)
|
|
|
|
rs := resource.NewFsResource(dataDir)
|
|
|
|
ca := cache.NewCache().WithCacheSize(1024)
|
|
|
|
|
2023-04-10 17:12:22 +02:00
|
|
|
en := NewEngine(Config{}, &st, &rs, ca)
|
2023-04-10 09:07:08 +02:00
|
|
|
err := en.Init("root", ctx)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
input := []string{
|
|
|
|
"1",
|
|
|
|
"0",
|
|
|
|
"1",
|
|
|
|
"0",
|
|
|
|
}
|
|
|
|
inputStr := strings.Join(input, "\n")
|
|
|
|
inputBuf := bytes.NewBuffer(append([]byte(inputStr), 0x0a))
|
|
|
|
outputBuf := bytes.NewBuffer(nil)
|
|
|
|
log.Printf("running with input: %s", inputBuf.Bytes())
|
|
|
|
|
|
|
|
err = Loop(&en, "root", ctx, inputBuf, outputBuf)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|