示例#1
0
func Test_WriteHtmlFile(t *testing.T) {
	realisticdate1999, _ := article.ParseDateUnix("1999/03/21 17:00:00")
	realisticdate2012, _ := article.ParseDateUnix("2012/03/19 06:51:15")
	article.SetPathForContent("/am-a-path")

	// Produce output case.
	ms := &mockSystem{test_header_2,
		make([]*mockReadCloser, 0, 4),
		make([]*mockWriteCloser, 0, 4),
		time.Time{},
		make([]string, 0, 4)}

	md := article.NewArticleTest("one.md", realisticdate1999, realisticdate2012, "What I want", true)
	WriteHtmlFile(ms, md)

	testhelpers.AssertInt(t, 1, len(ms.writefiles))
	testhelpers.AssertInt(t, 1, len(ms.readfiles))
	testhelpers.AssertInt(t, 1, int(ms.writefiles[0].closedCount))
	testhelpers.AssertInt(t, 1, int(ms.readfiles[0].closedCount))

	testhelpers.AssertString(t, "one.md", ms.readfiles[0].name)
	testhelpers.AssertString(t, "one.html", ms.writefiles[0].name)
	testhelpers.AssertString(t, "one.html", ms.timedfiles[0])

	// TODO(rjkroege): might want to diff the stirngs?
	testhelpers.AssertString(t, generated_output_2, ms.writefiles[0].String())

	// Output production skipped by date comparison.
	ms = &mockSystem{test_header_2,
		make([]*mockReadCloser, 0, 4),
		make([]*mockWriteCloser, 0, 4),
		realisticdate2012,
		make([]string, 0, 4)}

	md = article.NewArticleTest("one.md", realisticdate1999, realisticdate2012, "What I want", true)
	WriteHtmlFile(ms, md)

	testhelpers.AssertInt(t, 0, len(ms.writefiles))
	testhelpers.AssertInt(t, 1, len(ms.readfiles))
	testhelpers.AssertInt(t, 1, int(ms.readfiles[0].closedCount))

	testhelpers.AssertString(t, "one.md", ms.readfiles[0].name)
	testhelpers.AssertString(t, "one.html", ms.timedfiles[0])

	// TODO(rjkroege): Add additional tests to support validating error handling, etc.
}
func Test_WriteTimeline(t *testing.T) {
	/* General idea: create a constant string. Read from it., validate the resulting output. */
	statdate, _ := article.ParseDateUnix("1999/03/21 17:00:00")
	tagdate, _ := article.ParseDateUnix("2012/03/19 06:51:15")
	article.SetPathForContent("/foo")

	metadatas := []*article.MetaData{
		article.NewArticleTest("bar0.md", statdate, tagdate, "What I want 0", false),
		article.NewArticleTest("bar1.md", statdate, statdate, "What I want 1", false),
		article.NewArticleTest("bar2.md", statdate, tagdate, "What I want 2", false)}

	buffy := make([]byte, 0, 5000)
	fd := bytes.NewBuffer(buffy)

	WriteTimeline(fd, metadatas)

	testhelpers.AssertString(t, expected, fd.String())

	//    t.Errorf("output: {%s}", fd.String())
}