Skip to content

Commit

Permalink
49: remove possible title doubling, refs #21429
Browse files Browse the repository at this point in the history
  • Loading branch information
miku committed Mar 30, 2022
1 parent 39a2597 commit d54d74b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
7 changes: 4 additions & 3 deletions formats/crossref/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,10 @@ func (d *DateField) Date() (t time.Time, err error) {
// CombinedTitle returns a longish title.
func (doc *Document) CombinedTitle() string {
if len(doc.Title) > 0 {
if len(doc.Subtitle) > 0 {
return strutil.UnescapeTrim(fmt.Sprintf("%s : %s", strings.Join(doc.Title, " "), strings.Join(doc.Subtitle, " ")))
}
// TODO: remove this finally; refs. #21429
// if len(doc.Subtitle) > 0 {
// return strutil.UnescapeTrim(fmt.Sprintf("%s : %s", strings.Join(doc.Title, " "), strings.Join(doc.Subtitle, " ")))
// }
return strutil.UnescapeTrim(strings.Join(doc.Title, " "))
}
if len(doc.Subtitle) > 0 {
Expand Down
45 changes: 45 additions & 0 deletions formats/crossref/document_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package crossref

import "testing"

func TestDocumentCombinedTitle(t *testing.T) {
var cases = []struct {
doc *Document
result string
}{
{
doc: &Document{
Title: nil,
Subtitle: nil,
},
result: "",
},
{
doc: &Document{
Title: []string{"Hello"},
Subtitle: nil,
},
result: "Hello",
},
{
doc: &Document{
Title: []string{"Hello"},
Subtitle: []string{"Sub"},
},
result: "Hello : Sub",
},
{
doc: &Document{
Title: []string{"Hello", "Sub"},
Subtitle: []string{"Sub"},
},
result: "Hello : Sub",
},
}
for _, c := range cases {
result := c.doc.CombinedTitle()
if result != c.result {
t.Fatalf("got %v, want %v", result, c.result)
}
}
}

0 comments on commit d54d74b

Please sign in to comment.