diff options
| author | Paul Buetow <paul@buetow.org> | 2024-11-19 10:14:25 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-11-19 10:14:25 +0200 |
| commit | f2318c4946db3ffd60a2b955e47660c2f77007df (patch) | |
| tree | 2ef8ab8ec01e1ad216750ed9f4ccd94f79de905e | |
| parent | 905e733a3aec46ff89358b49456da78199a8ed7d (diff) | |
more tests for inline tags
| -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) { |
