diff options
| -rw-r--r-- | internal/entry/entry_test.go | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/internal/entry/entry_test.go b/internal/entry/entry_test.go index d64531f..f88d848 100644 --- a/internal/entry/entry_test.go +++ b/internal/entry/entry_test.go @@ -127,21 +127,40 @@ func TestHasTag(t *testing.T) { } 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) - } + table := map[string][]string{ + "foo,bar,baz blablablabla...": {"foo", "bar", "baz"}, + "foo.bar.baz blablablabla...": {"foo", "bar", "baz"}, + "foo.bar,baz blablablabla...": {"foo", "bar", "baz"}, + "foo,bar.baz blablablabla...": {"foo", "bar", "baz"}, + "share:li,foo this is the main content": {"share:li", "foo"}, } - if contentWithoutTags != "this is the main content" { - t.Errorf("expected the main content to be 'this is the main content' but got '%s'", contentWithoutTags) + + for input, expectedTags := range table { + t.Run(input, func(t *testing.T) { + tags, contentWithoutTags, ok := extractInlineTags(input) + if !ok { + t.Error("expected inline tags but none were found") + } + if len(tags) != len(expectedTags) { + t.Errorf("expected %d inline tags (%v) but got %d (%v)", + len(expectedTags), expectedTags, len(tags), tags) + } + for _, expectedTag := range expectedTags { + if !slices.Contains(tags, expectedTag) { + t.Errorf("expected '%s' to be an inline tag but got '%v'", + expectedTag, tags) + } + } + parts := strings.Split(input, " ") + expectedMainContent := strings.Join(parts[1:], " ") + if contentWithoutTags != expectedMainContent { + t.Errorf("expected the main content to be '%s' but got '%s'", + expectedMainContent, contentWithoutTags) + } + + }) } + } func FuzzExtractURLs(f *testing.F) { |
