diff --git a/title_info.go b/title_info.go index b2d35ea..366d3e2 100644 --- a/title_info.go +++ b/title_info.go @@ -113,7 +113,7 @@ func (ti *TitleInfo) PrintObjectName() string { // TitleName returns the title name segment (+40) FERAG-formatted func (ti *TitleInfo) TitleName() string { - return fmt.Sprintf("+40%-8s", ti.titleName) + return fmt.Sprintf("+40%-8.8s", ti.titleName) } // SetTitleName sets the title name segment (+40) diff --git a/title_info_test.go b/title_info_test.go index 5a165e4..2f39535 100644 --- a/title_info_test.go +++ b/title_info_test.go @@ -2,8 +2,85 @@ package feragstring import "testing" -func TestNewTitleInfo(t *testing.T) { +func TestTitleInfo_PrintObjectName(t *testing.T) { ti := NewTitleInfo() - ti.titleName = "MOP10629" + ti.SetPrintObjectName("FERAGTITLE") + want := "+93FERAGTITLE " + + if ti.PrintObjectName() != want { + t.Errorf("PrintObjectName = %s, wanted %s", ti.PrintObjectName(), want) + } +} + +func TestTitleInfo_TitleName(t *testing.T) { + ti := NewTitleInfo() + ti.SetTitleName("LONGTITLE") + + want := "+40LONGTITL" + + if ti.TitleName() != want { + t.Errorf("TitleName = %s, wanted %s", ti.TitleName(), want) + } +} + +func TestTitleInfo_PublicationDate(t *testing.T) { + ti := NewTitleInfo() + ti.SetPublicationDate("2020-07-06") + + want := "+95200706" + + if ti.PublicationDate() != want { + t.Errorf("PublicationDate = %s, wanted %s", ti.PublicationDate(), want) + } +} + +func TestTitleInfo_CountryCode(t *testing.T) { + ti := NewTitleInfo() + ti.SetCountryCode("13") + + want := "+9713" + + if ti.CountryCode() != want { + t.Errorf("CountryCode = %s, wanted %s", ti.CountryCode(), want) + } +} + +func TestTitleInfo_PrintObjectColor(t *testing.T) { + ti := NewTitleInfo() + ti.SetPrintObjectColor("12345678") + + want := "+9412345678" + + if ti.PrintObjectColor() != want { + t.Errorf("PrintObjectColor = %s, wanted %s", ti.PrintObjectColor(), want) + } +} + +func TestTitleInfo_AdditionalInfo(t *testing.T) { + ti := NewTitleInfo() + ti.SetAdditionalInfo("A really really long text with no real meaning! ") + + want := "+08A really really long text with no real meaning! " + + if ti.AdditionalInfo() != want { + t.Errorf("AdditionalInfo = %s, wanted %s", ti.AdditionalInfo(), want) + } +} + +func TestTitleInfo_Complete(t *testing.T) { + ti := NewTitleInfo() + ti.SetPrintObjectName("FERAGTITLE") + ti.SetTitleName("THETITLE") + ti.SetPublicationDate("2020-07-06") + ti.SetCountryCode("13") + ti.SetPrintObjectColor("87654321") + ti.SetAdditionalInfo("") + + want := "%2440+93FERAGTITLE +40THETITLE+95200706+9713+9487654321!" + linebreak + + if ti.Message() != want { + t.Errorf("Complete = |%s|", ti.Message()) + t.Errorf(" wanted = |%s|", want) + } }