コード例 #1
0
ファイル: generate_test.go プロジェクト: rjkroege/wikitools
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.
}
コード例 #2
0
ファイル: filter_test.go プロジェクト: rjkroege/wikitools
func Test_UniqueValidName(t *testing.T) {
	realisticdate, _ := article.ParseDateUnix("1999/03/21 17:00:00")

	nd := &MockSystem{false, time.Time{}}
	testhelpers.AssertString(t, "hello/there.md", UniqueValidName("hello/", "there", ".md", nd))

	nd = &MockSystem{true, realisticdate}
	testhelpers.AssertString(t, "hello/there-19990321-170000.md", UniqueValidName("hello/", "there", ".md", nd))
}
コード例 #3
0
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())
}