func TestNewCommentTime(t *testing.T) { var unix int64 = 1433220431 c, err := NewComment("ELI5?", "123", nil, &Person{Date: time.Unix(unix, 0)}).Dematerialize() comment := c.(*Comment) assert.Nil(t, err) assert.NotNil(t, comment.Author) assert.Equal(t, comment.Author.Date.Unix(), unix) assert.NotNil(t, comment.Amender) assert.Equal(t, comment.Amender.Date, comment.Author.Date) }
func TestNewCommentCommit(t *testing.T) { c, err := NewComment("Wat?", "abcdefg", nil, nil).Dematerialize() comment := c.(*Comment) assert.Nil(t, err) assert.NotNil(t, comment) assert.Equal(t, *comment.Commit, "abcdefg") }
func TestCompareVersionsRepoCorrupted(t *testing.T) { status, err := compareVersion("1.4.5", "2.0").Dematerialize() assert.NotNil(t, err) assert.True(t, strings.Contains(err.Error(), "1.4.5")) assert.True(t, strings.Contains(err.Error(), "2.0")) assert.Nil(t, status) }
func TestNewCommentID(t *testing.T) { c, err := NewComment("This behavior is undocumented", "abcdefg", nil, nil).Dematerialize() comment := c.(*Comment) assert.Nil(t, err) assert.NotNil(t, comment) assert.Nil(t, comment.ID) }
func TestCreateFileRefDeletedLineOverride(t *testing.T) { ref := CreateFileRef("pkg/src/example_item.ft:145", true) assert.NotNil(t, ref) assert.Equal(t, ref.Path, "pkg/src/example_item.ft") assert.Equal(t, ref.Line, 145) assert.Equal(t, ref.LineType, RefLineTypeOld) }
func TestNewCommentDeleted(t *testing.T) { c, err := NewComment("What is happening here?", "abcdefg", nil, nil).Dematerialize() comment := c.(*Comment) assert.Nil(t, err) assert.NotNil(t, comment) assert.False(t, comment.Deleted) }
func TestCreateFileMultiColon(t *testing.T) { ref := CreateFileRef("pkg/src/item:other.txt:98", false) assert.NotNil(t, ref) assert.Equal(t, ref.Path, "pkg/src/item:other.txt") assert.Equal(t, ref.Line, 98) assert.Equal(t, ref.LineType, RefLineTypeNew) }
func TestCategory_ClearCache(t *testing.T) { seed() var c Category var cc int err := mc.Get("Category1_", &c) if err == nil { t.Errorf("mc.Get(Category1_) did not error") } err = mc.Get("Category1_UnreadCount", &cc) if err == nil { t.Errorf("mc.Get(Category1_UnreadCount) did not error") } CacheAllCats() err = mc.Get("Category1_", &c) if err != nil { t.Errorf("mc.Get(Category1_): %s", err) } err = mc.Get("Category1_UnreadCount", &cc) if err != nil { t.Errorf("mc.Get(Category1_UnreadCount): %s", err) } c.ClearCache() err = mc.Get("Category1_", &c) if err == nil { t.Errorf("mc.Get(Category1_) did not error") } err = mc.Get("Category1_UnreadCount", &cc) assert.NotNil(t, err) if err == nil { t.Errorf("mc.Get(Category1_UnreadCount) did not error") } }
func TestCreateFileNoLine(t *testing.T) { ref := CreateFileRef("pkg/src/item:other.txt", false) assert.NotNil(t, ref) assert.Equal(t, ref.Path, "pkg/src/item:other.txt") assert.Equal(t, ref.Line, 0) assert.Equal(t, ref.LineType, RefLineTypeNew) }
func TestNewCommentContent(t *testing.T) { c, err := NewComment("Season the chex mix", "abcdefg", nil, nil).Dematerialize() comment := c.(*Comment) assert.Nil(t, err) assert.NotNil(t, comment) assert.Equal(t, comment.Content, "Season the chex mix") }
func TestCreateFileRefNoLine(t *testing.T) { ref := CreateFileRef("pkg/src/example_item.ft:145", false) assert.NotNil(t, ref) assert.Equal(t, ref.Path, "pkg/src/example_item.ft") assert.Equal(t, ref.Line, 145) assert.Equal(t, ref.LineType, RefLineTypeNew) }
func TestNewCommentAmender(t *testing.T) { author := &Person{"Sam Wafers", "<*****@*****.**>", time.Now(), "-0600"} c, err := NewComment("Doesn't this violate the laws of physics?", "123", nil, author).Dematerialize() comment := c.(*Comment) assert.Nil(t, err) assert.NotNil(t, comment) assert.Equal(t, comment.Amender, author) }
func TestCreatePersonFromNameEmailTime(t *testing.T) { p, err := CreatePerson("Carrie <*****@*****.**> 1437612685 -0700").Dematerialize() assert.Nil(t, err) person := p.(*Person) assert.NotNil(t, person) assert.Equal(t, person.Email, "*****@*****.**") assert.Equal(t, person.Name, "Carrie") }
func TestSerializePersonEmailOnly(t *testing.T) { data := "<*****@*****.**>" p, err := CreatePerson(data).Dematerialize() assert.Nil(t, err) assert.NotNil(t, p) person := p.(*Person) assert.True(t, strings.Contains(person.Serialize(), data)) }
func TestSerializePersonFull(t *testing.T) { data := "Katie Em <*****@*****.**> 1437498360 +0400" p, err := CreatePerson(data).Dematerialize() assert.Nil(t, err) assert.NotNil(t, p) person := p.(*Person) assert.Equal(t, person.Serialize(), data) }
func TestCreatePersonWithoutName(t *testing.T) { p, err := CreatePerson("<*****@*****.**>").Dematerialize() assert.Nil(t, err) person := p.(*Person) assert.NotNil(t, person) assert.Equal(t, person.Email, "*****@*****.**") assert.Equal(t, person.Name, "") }
func TestCreatePersonFromSpacedNameEmailTime(t *testing.T) { p, err := CreatePerson("Carrie Ann McBean <*****@*****.**>").Dematerialize() assert.Nil(t, err) person := p.(*Person) assert.NotNil(t, person) assert.Equal(t, person.Email, "*****@*****.**") assert.Equal(t, person.Name, "Carrie Ann McBean") }
func TestNewCommentFileRef(t *testing.T) { ref := &FileRef{"src/example.c", 12, RefLineTypeNew} c, err := NewComment("This should be more modular", "abcdefg", ref, nil).Dematerialize() comment := c.(*Comment) assert.Nil(t, err) assert.NotNil(t, comment) assert.Equal(t, comment.FileRef, ref) }
func TestNewCommentAuthor(t *testing.T) { author := &Person{"Sam Wafers", "<*****@*****.**>", time.Now(), "-0600"} c, err := NewComment("Curious decision here.", "123", nil, author).Dematerialize() comment := c.(*Comment) assert.Nil(t, err) assert.NotNil(t, comment) assert.Equal(t, comment.Author, author) assert.Equal(t, comment.Amender, author) }
func TestCreateEmptyPerson(t *testing.T) { _, err := CreatePerson("").Dematerialize() assert.NotNil(t, err) }
func TestSerializePersonNameOnly(t *testing.T) { data := "Katie Em" _, err := CreatePerson(data).Dematerialize() assert.NotNil(t, err) }
func TestCompareVersionsToolNewer(t *testing.T) { status, err := compareVersion("2.1.1", "2.1.0").Dematerialize() assert.NotNil(t, err) assert.True(t, strings.Contains(err.Error(), "git-comment --update")) assert.Nil(t, status) }
func TestCreateWithoutContent(t *testing.T) { _, err := NewComment("", "azerty", new(FileRef), new(Person)).Dematerialize() assert.NotNil(t, err) }
func TestCompareVersionsRepoNewer(t *testing.T) { status, err := compareVersion("2.0.1", "2.1.0").Dematerialize() assert.NotNil(t, err) assert.Nil(t, status) }
func TestCreatePersonFromInvalidEmail(t *testing.T) { _, err := CreatePerson("Carrie Ann McBean <carrie.mcbean>").Dematerialize() assert.NotNil(t, err) }