summaryrefslogtreecommitdiff
path: root/internal/entry/entry_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-11-06 11:11:34 +0200
committerPaul Buetow <paul@buetow.org>2024-11-06 11:11:34 +0200
commit2d652249ca36219853b34d9f55101ed3cbd109a1 (patch)
treeb95562d42c98cff62f1c68e6a20b116614819815 /internal/entry/entry_test.go
parent3551fd060242b5c0ca07d4cc371b1032d0983e38 (diff)
initial inline tag support
Diffstat (limited to 'internal/entry/entry_test.go')
-rw-r--r--internal/entry/entry_test.go64
1 files changed, 52 insertions, 12 deletions
diff --git a/internal/entry/entry_test.go b/internal/entry/entry_test.go
index 55d2379..d64531f 100644
--- a/internal/entry/entry_test.go
+++ b/internal/entry/entry_test.go
@@ -18,28 +18,50 @@ func TestEntry(t *testing.T) {
for _, stamp := range stamps {
queuedPath := fmt.Sprintf("gosdir/db/platforms/linkedin/helloworld.txt.%s.%s", stamp, state)
- ent, err := New(queuedPath)
+ en, err := New(queuedPath)
if err != nil {
t.Error(err)
}
- if ent.Path != queuedPath {
- t.Errorf("expected path %s but got %s", queuedPath, ent.Path)
+ if en.Path != queuedPath {
+ t.Errorf("expected path %s but got %s", queuedPath, en.Path)
}
- if ent.State != state {
- t.Errorf("expected state %s but got %s", state, ent.State)
+ if en.State != state {
+ t.Errorf("expected state %s but got %s", state, en.State)
}
expectedTime, err := timestamp.Parse(stamp)
if err != nil {
t.Error(err)
}
- if ent.Time != expectedTime {
- t.Errorf("expected time to be %v but got %v", expectedTime, ent.Time)
+ if en.Time != expectedTime {
+ t.Errorf("expected time to be %v but got %v", expectedTime, en.Time)
}
}
}
}
+func TestEntryTags(t *testing.T) {
+ tagss := []string{"prio", "share:linkedin:mastodon.now", "share:-mastodon", "ask", "invalid"}
+
+ for _, tagsStr := range tagss {
+ queuedPath := fmt.Sprintf("gosdir/db/platforms/linkedin/helloworld.%s.txt.20241111-111111.20241111-111111", tagsStr)
+ en, err := New(queuedPath)
+ if err != nil {
+ t.Error(err)
+ }
+ for _, expectedTag := range strings.Split(tagsStr, ".") {
+ if expectedTag == "invalid" {
+ if en.HasTag(expectedTag) {
+ t.Errorf("didn't expect tag '%s' to be present, but got '%v'", expectedTag, en.tags)
+ }
+ continue
+ }
+ if !en.HasTag(expectedTag) {
+ t.Errorf("expected tag '%s' to be present, but got '%v'", expectedTag, en.tags)
+ }
+ }
+ }
+}
func TestExtractTwoURLs(t *testing.T) {
text := `Hello world https://foo.zone
Hello universe http://world.universe test 123`
@@ -89,21 +111,39 @@ func TestHasTag(t *testing.T) {
}
for fileName, expectedTags := range table {
- ent, err := New(fileName)
+ en, err := New(fileName)
if err != nil {
t.Error(err)
}
- if len(expectedTags) != len(ent.simpleTags) {
- t.Errorf("expected '%d' tags but got '%d'", len(expectedTags), len(ent.simpleTags))
+ if len(expectedTags) != len(en.tags) {
+ t.Errorf("expected '%d' tags but got '%d'", len(expectedTags), len(en.tags))
}
for _, tag := range expectedTags {
- if !ent.HasTag(tag) {
- t.Errorf("expected tag '%s' but got '%s'", tag, ent.simpleTags)
+ if !en.HasTag(tag) {
+ t.Errorf("expected tag '%s' but got '%s'", tag, en.tags)
}
}
}
}
+func TestExtractInlineTags(t *testing.T) {
+ tags, contentWithoutTags, ok := extractInlineTags(`share,foo.bar this is the main content`)
+ if !ok {
+ t.Error("expected inline tags")
+ }
+ if len(tags) != 3 {
+ t.Error("expected 3 inline tags")
+ }
+ for _, expectedTag := range []string{"share", "foo", "bar"} {
+ if !slices.Contains(tags, expectedTag) {
+ t.Errorf("expected '%s' to be an inline tag but got '%v'", expectedTag, tags)
+ }
+ }
+ if contentWithoutTags != "this is the main content" {
+ t.Errorf("expected the main content to be 'this is the main content' but got '%s'", contentWithoutTags)
+ }
+}
+
func FuzzExtractURLs(f *testing.F) {
f.Add("/path?myjfa=lwsr4imj&dgqeg=m3uwwsak")
f.Add("/?amfbm=bwzqu46m&xheuh=nv588d98")