Example #1
0
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)
}
Example #2
0
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)
}
Example #3
0
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)
}
Example #4
0
func TestGetAllWantedGames(t *testing.T) {
	print("GetAllWantedGames\n")
	seedGame()
	user := gu(t)
	c, err := GetConsole("Atari 2600", user)
	assert.Nil(t, err, "GetConsole(Atari 2600,user)")
	c2, err := GetConsole("NES", user)
	assert.Nil(t, err, "GetConsole(NES,user)")
	print("\tInitial\n")
	wg, err := GetAllWantedGames()
	assert.Nil(t, err, "GetAllWantedGames()")
	assert.Equal(t, 0, len(wg), "GetAllWantedGames")

	print("\tMarking individual games\n")
	g, err := GetGame(1, user)
	assert.Nil(t, err, "GetGame(1,user)")
	g.Want = true
	err = g.Save()
	assert.Nil(t, err, "g.Save()")
	wg, err = GetAllWantedGames()
	assert.Nil(t, err, "GetAllWantedGames()")
	assert.Equal(t, 1, len(wg), "GetAllWantedGames()")

	print("\tMarking Console WantGames\n")
	c.WantGames = true
	err = c.Save()
	assert.Nil(t, err, "c.Save()")
	c2.WantGames = true
	err = c2.Save()
	assert.Nil(t, err, "c2.Save()")
	wg, err = GetAllWantedGames()
	assert.Nil(t, err, "GetAllWantedGames()")
	assert.Equal(t, 1321, len(wg), "GetAllWantedGames()")

}
Example #5
0
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 TestAllMarkedEntries(t *testing.T) {
	e := ef()
	assert.Equal(t, 0, len(AllMarkedEntries("test")))
	err := e.Mark()
	assert.Nil(t, err)
	assert.Equal(t, 1, len(AllMarkedEntries("test")))
}
func TestPropertiesFromBlob(t *testing.T) {
	content := "fruit Green Apple\ntree_type Redwood\n\nThe Redwood is the tallest tree in North America"
	blob := CreatePropertyBlob(content)
	fruit := blob.Get("fruit")
	tree := blob.Get("tree_type")
	assert.Equal(t, "Green Apple", *fruit)
	assert.Equal(t, "Redwood", *tree)
}
Example #8
0
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 TestCategory_Excludes(t *testing.T) {
	seed()
	c1 := GetCat("1")
	assert.Equal(t, 0, len(c1.Excludes()))
	c1.Exclude = "a,b,c,d,"
	c1.Save()
	assert.Equal(t, 4, len(c1.Excludes()))
}
Example #10
0
func TestFilter_Manual(t *testing.T) {
	print("Filter_Manual\n")
	c := gsc(t)
	gl, err := c.Games()
	assert.Nil(t, err, "c.Games()")
	assert.Equal(t, 1, len(Filter(gl).Manual(true)), "FilterManual(true)")
	assert.Equal(t, 800, len(Filter(gl).Manual(false)), "FilterManual(false)")
}
Example #11
0
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")
}
Example #12
0
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, "")
}
Example #13
0
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 TestGetCategories(t *testing.T) {
	seed()
	assert.Equal(t, 4, len(GetCategories("test")))
	var newcat Category
	newcat.Name = "newest!"
	newcat.UserName = "******"
	newcat.Insert("test")
	assert.Equal(t, 5, len(GetCategories("test")))
}
func TestCategory_ReadEntries(t *testing.T) {
	seed()
	c1 := GetCat("1")
	assert.Equal(t, 0, len(c1.ReadEntries()))
	e1 := GetEntry("1", "test")
	err := e1.MarkRead()
	assert.Nil(t, err)
	assert.Equal(t, 1, len(c1.ReadEntries()))
}
func TestCategory_DeleteExcludes(t *testing.T) {
	seed()
	c1 := GetCat("1")
	c1.DeleteExcludes()
	assert.Equal(t, 4, c1.Unread())
	c1.Exclude = "asdf"
	c1.DeleteExcludes()
	assert.Equal(t, 2, c1.Unread())
}
func TestCategory_FeedsStr(t *testing.T) {
	seed()
	c1 := GetCat("1")
	assert.Equal(t, 2, len(c1.FeedsStr()))
	f4, err := GetFeed(4)
	assert.Nil(t, err)
	f4.CategoryID = 1
	f4.Save()
	assert.Equal(t, 3, len(c1.FeedsStr()))
}
Example #18
0
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)
}
Example #19
0
func TestEntry_AutoscrollPX(t *testing.T) {
	e := ef()
	assert.Equal(t, 0, e.AutoscrollPX())
	f, err := GetFeed(1)
	assert.Nil(t, err)
	f.AutoscrollPX = 1234
	err = f.Save()
	assert.Nil(t, err)
	assert.Equal(t, 1234, e.AutoscrollPX())
}
Example #20
0
func TestEntry_ViewMode(t *testing.T) {
	e := ef()
	assert.Equal(t, "default", e.ViewMode(), "initial entry.ViewMode")
	f, err := GetFeed(1)
	assert.Nil(t, err, "GetFeed(1)")
	f.ViewMode = "link"
	err = f.Save()
	assert.Nil(t, err)
	assert.Equal(t, "link", e.ViewMode())
}
Example #21
0
func TestEntry_UnMark(t *testing.T) {
	e := ef()
	err := e.Mark()
	assert.Nil(t, err)
	e = ge()
	assert.Equal(t, "1", e.Marked)
	err = e.UnMark()
	assert.Nil(t, err)
	e = ge()
	assert.Equal(t, "0", e.Marked)
}
func TestCategory_SearchTitles(t *testing.T) {
	seed()
	c1 := GetCat("1")
	assert.Equal(t, 2, len(c1.SearchTitles("asdf", "unread")))
	assert.Equal(t, 2, len(c1.SearchTitles("asdf", "all")))
	e1 := GetEntry("1", "test")
	err := e1.MarkRead()
	assert.Nil(t, err)
	assert.Equal(t, 1, len(c1.SearchTitles("asdf", "read")))
	err = e1.Mark()
	assert.Nil(t, err)
	assert.Equal(t, 1, len(c1.SearchTitles("asdf", "marked")))
}
func TestCategory_GetAllCategories(t *testing.T) {
	seed()
	assert.Equal(t, 8, cl())
	var cn Category
	cn.Name = "newcat"
	cn.Insert("test")
	assert.Equal(t, 9, cl())
	c1 := GetCat("1")
	c1.Delete()
	c2 := GetCat("2")
	c2.Delete()
	assert.Equal(t, 7, cl())
}
Example #24
0
func TestDeserializeComment(t *testing.T) {
	author := &Person{"Morpheus", "*****@*****.**", time.Unix(1437498360, 0), "-0600"}
	c, _ := NewComment("Pick one", "afdafdafd", DeserializeFileRef("bin/exec:15"), author).Dematerialize()
	comment := c.(*Comment)
	newC, err := DeserializeComment(comment.Serialize()).Dematerialize()
	newComment := newC.(*Comment)
	assert.Nil(t, err)
	assert.Equal(t, *comment.Commit, *newComment.Commit)
	assert.Equal(t, *comment.FileRef, *newComment.FileRef)
	assert.Equal(t, *comment.Author, *newComment.Author)
	assert.Equal(t, *comment.Amender, *newComment.Amender)
	assert.Equal(t, comment.Content, newComment.Content)
}
Example #25
0
func TestCombineAllSuccess(t *testing.T) {
  results := []Result{NewSuccess("item1"), NewSuccess("item2"), NewSuccess("item3")}
  transform := func(values ...interface{}) Result {
    return NewSuccess(values)
  }

  result := Combine(transform, results...)

  value := result.Success.([]interface{})
  assert.Equal(t, len(value), 3)
  for index, item := range value {
    assert.Equal(t, item, fmt.Sprintf("item%d", index+1))
  }
}
Example #26
0
func TestEntry_ToggleMark(t *testing.T) {
	e := ef()
	nm, err := e.ToggleMark()
	assert.Nil(t, err)
	assert.Equal(t, "set", nm)
	e = ge()
	assert.Equal(t, "1", e.Marked)
	assert.Nil(t, err)
	nm, err = e.ToggleMark()
	assert.Equal(t, "unset", nm)
	assert.Nil(t, err)
	e = ge()
	assert.Equal(t, "0", e.Marked)
}
func TestNewlinesInMessage(t *testing.T) {
	props := "author Elira <*****@*****.**>\nfile src/example.txt\n\n"
	message := "I have a few questions.\nHow do we plan on handling the latter case?\n\nWhere can I get some chili dogs?"
	content := strings.Join([]string{props, message}, "")
	blob := CreatePropertyBlob(content)
	assert.Equal(t, message, blob.Message)
}
Example #28
0
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")
}
Example #29
0
func TestConsole_CheapestGame(t *testing.T) {
	print("Console.CheapestGame\n")
	seedConsole()
	user, err := auth.GetUser(1)
	if err != nil {
		t.Errorf("GetUser(1): %s", err)
	}
	c, err := GetConsole("NES", user)
	assert.Nil(t, err, "GetConsole(NES,user)")
	c.WantGames = true
	c.Save()
	p := 1.01
	gl, err := c.WantedGames()
	fmt.Printf("len(wantedgames): %v\n", len(gl))
	assert.Nil(t, err, "c.Games()")
	for _, g := range gl {
		g.EbayPrice = p
		g.Want = true
		p = p + 1.01
		g.EbayEnds = "2999-01-01 01:00:00"
		err := g.Save()
		assert.Nil(t, err, "g.Save()")
	}

	d, err := GetConsole("NES", user)
	if err != nil {
		t.Errorf("GetConsole(NES,user): %s", err)
	}
	g := d.CheapestGame()
	assert.Equal(t, 1.01, g.EbayPrice, "EbayPrice")
	fmt.Printf("%s, %.2v\n", g.Name, g.EbayPrice)
}
Example #30
0
func TestAllUsers(t *testing.T) {
	initTest(t)
	print("AllUsers\n")
	ul, err := AllUsers()
	assert.Nil(t, err, "AllUsers()")
	assert.Equal(t, len(ul), 12, "len(AllUsers())")
}