diff --git a/pkg/parser/prose_tags_test.go b/pkg/parser/prose_tags_test.go new file mode 100644 index 0000000..f73b240 --- /dev/null +++ b/pkg/parser/prose_tags_test.go @@ -0,0 +1,30 @@ +package parser + +import ( + "path/filepath" + "reflect" + "testing" +) + +func TestProseTagsDoNotShareStorage(t *testing.T) { + p := NewParser() + path := filepath.Join("one", "two", "three", "tags.md") + pathTags := make([]string, 3, 8) + copy(pathTags, []string{"one", "two", "three"}) + p.pathTagsCache[filepath.Dir(path)] = pathTags + + p.parseLines(path, []byte("# First\n```sh\necho first\n```\n\n#first\n# Second\n```sh\necho second\n```\n\n#second\nend\n")) + + want := [][]string{ + {"one", "two", "three", "first"}, + {"one", "two", "three", "second"}, + } + if len(p.index.Cheats) != len(want) { + t.Fatalf("got %d cheats, want %d", len(p.index.Cheats), len(want)) + } + for i, cheat := range p.index.Cheats { + if !reflect.DeepEqual(cheat.Tags, want[i]) { + t.Errorf("cheat %q tags = %v, want %v", cheat.Header, cheat.Tags, want[i]) + } + } +} diff --git a/pkg/parser/tags.go b/pkg/parser/tags.go index 4011991..afe6595 100644 --- a/pkg/parser/tags.go +++ b/pkg/parser/tags.go @@ -76,7 +76,7 @@ func (p *Parser) getTagsForPath(path, header string) []string { return append(tags, strings.ToLower(strings.TrimSpace(header[:idx]))) } - return pathTags + return pathTags[:len(pathTags):len(pathTags)] } // mergeTags appends newTags to existing, lowercasing and deduping in place.