47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
package store
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// stopmemory_test.go: the v16 presented memory — accumulation semantics only; the predicate that reads
|
|
// it lives in the pipeline and is pinned there.
|
|
|
|
func TestStopMemoryAccumulatesAndNeverInventsRows(t *testing.T) {
|
|
s, err := Open(filepath.Join(t.TempDir(), "m.db"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer s.Close()
|
|
|
|
got, err := s.StopPresentedSurfaces("b1")
|
|
if err != nil || len(got) != 0 {
|
|
t.Fatalf("an untouched book has an empty memory: %v / %v", got, err)
|
|
}
|
|
if err := s.MarkStopPresented("b1", []string{"方源", "", "花家"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// Idempotent, and growth-only: re-marking adds nothing, marking more only adds.
|
|
if err := s.MarkStopPresented("b1", []string{"方源", "青茅山"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, err = s.StopPresentedSurfaces("b1")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want := map[string]bool{"方源": true, "花家": true, "青茅山": true}
|
|
if len(got) != len(want) {
|
|
t.Fatalf("got %v, want %v (a blank surface must be dropped, not stored as «everything blank is seen»)", got, want)
|
|
}
|
|
for k := range want {
|
|
if !got[k] {
|
|
t.Fatalf("missing %q in %v", k, got)
|
|
}
|
|
}
|
|
// Book-scoped: another book's memory is untouched.
|
|
other, err := s.StopPresentedSurfaces("b2")
|
|
if err != nil || len(other) != 0 {
|
|
t.Fatalf("the memory is per book: %v / %v", other, err)
|
|
}
|
|
}
|