aboutsummaryrefslogtreecommitdiff
path: root/internal/bookmarks/bookmarks_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/bookmarks/bookmarks_test.go')
-rw-r--r--internal/bookmarks/bookmarks_test.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/internal/bookmarks/bookmarks_test.go b/internal/bookmarks/bookmarks_test.go
new file mode 100644
index 0000000..40e10e0
--- /dev/null
+++ b/internal/bookmarks/bookmarks_test.go
@@ -0,0 +1,46 @@
+package bookmarks
+
+import (
+ "testing"
+)
+
+func TestStoreRoundTrip(t *testing.T) {
+ t.Setenv("XDG_DATA_HOME", t.TempDir())
+ s := Open()
+
+ if got, _ := s.List(""); len(got) != 0 {
+ t.Fatalf("empty store should list nothing, got %d", len(got))
+ }
+ b, err := s.Add(Bookmark{Book: "John", Chapter: 3, Note: "for God so loved", Tags: []string{"grace", "gospel"}})
+ if err != nil || b.ID == "" || b.Created == "" {
+ t.Fatalf("add: %+v err=%v", b, err)
+ }
+ if _, err := s.Add(Bookmark{Book: "Luke", Chapter: 15, Tags: []string{"gospel"}}); err != nil {
+ t.Fatal(err)
+ }
+
+ all, _ := s.List("")
+ if len(all) != 2 || all[0].Book != "Luke" { // newest first
+ t.Errorf("list = %+v", all)
+ }
+ tagged, _ := s.List("grace")
+ if len(tagged) != 1 || tagged[0].Book != "John" {
+ t.Errorf("tag filter = %+v", tagged)
+ }
+ if tags, _ := s.Tags(); len(tags) != 2 || tags[0] != "gospel" {
+ t.Errorf("tags = %v", tags)
+ }
+ if err := s.Delete(b.ID); err != nil {
+ t.Fatal(err)
+ }
+ if all, _ := s.List(""); len(all) != 1 || all[0].Book != "Luke" {
+ t.Errorf("after delete = %+v", all)
+ }
+}
+
+func TestParseTags(t *testing.T) {
+ got := ParseTags(" grace , gospel ,, mercy ")
+ if len(got) != 3 || got[0] != "grace" || got[2] != "mercy" {
+ t.Errorf("ParseTags = %v", got)
+ }
+}