예제 #1
0
func Test_Move(t *testing.T) {
	ws := New()

	testhelpers.AssertInt(t, 0, ws.Offset)
	ws.Move(1)
	testhelpers.AssertInt(t, 1, ws.Offset)
	ws.Move(-1)
	testhelpers.AssertInt(t, 0, ws.Offset)
}
예제 #2
0
func Test_EchoedType(t *testing.T) {
	echo := Makecho()
	s := []byte("hello")

	testhelpers.AssertInt(t, 0, len(echo.childbound))

	echo.echoed(s)
	s[0] = 'H'

	testhelpers.AssertInt(t, 1, len(echo.childbound))
	r := <-echo.childbound
	testhelpers.AssertString(t, "hello", string(r))
	testhelpers.AssertInt(t, 0, len(echo.childbound))
}
예제 #3
0
func Test_Cancel_Wholeword(t *testing.T) {
	echo := Makecho()
	echo.echoed([]byte("hello"))

	s := []byte("h")
	r := echo.Cancel(s)
	testhelpers.AssertInt(t, 0, len(r))
	testhelpers.AssertString(t, "ello", string(echo.oldest))

	s = []byte("e")
	r = echo.Cancel(s)
	testhelpers.AssertInt(t, 0, len(r))
	testhelpers.AssertString(t, "llo", string(echo.oldest))
}
예제 #4
0
func Test_Delete_before_offset(t *testing.T) {
	ws := New()
	ws.Move(2)

	n := ws.Delete(1, 2)
	testhelpers.AssertString(t, "", ws.String())
	testhelpers.AssertInt(t, 1, n)
}
예제 #5
0
func Test_Runemodulus(t *testing.T) {

	b, r := Runemodulus([]byte("abcd"))
	testhelpers.AssertString(t, "abcd", string(b))
	testhelpers.AssertInt(t, 0, len(r))

	// 日本語  <- 3 Asian letters.
	s := "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
	sb := []byte(s)

	b, r = Runemodulus(sb)
	testhelpers.AssertString(t, s, string(b))
	testhelpers.AssertInt(t, 0, len(r))

	b, r = Runemodulus(sb[:len(sb)-1])
	testhelpers.AssertString(t, s[0:6], string(b))
	testhelpers.AssertInt(t, 2, len(r))
	testhelpers.AssertInt(t, int(int(r[0])), '\xe8')
	testhelpers.AssertInt(t, int(int(r[1])), '\xaa')

	b, r = Runemodulus(sb[:len(sb)-2])
	testhelpers.AssertInt(t, 1, len(r))
	testhelpers.AssertString(t, s[0:6], string(b))
	testhelpers.AssertInt(t, int(r[0]), '\xe8')

}
예제 #6
0
func Test_Delete_to_empty(t *testing.T) {
	ws := New()
	ws.Move(2)
	ws.Addtyping([]byte{'a'}, 2)

	n := ws.Delete(2, 3)
	testhelpers.AssertString(t, "", ws.String())
	testhelpers.AssertInt(t, 0, n)
}
예제 #7
0
func Test_SendtypeOnechar(t *testing.T) {
	mock := &mockttyfd{make([][]byte, 0, 10)}
	tp := New(mock, Makecho())

	tp.addtype([]byte("h"), 0, true)
	tp.Sendtype()

	testhelpers.AssertInt(t, 0, len(mock.writes))
	testhelpers.AssertString(t, "h", string(tp.Typing))
}
예제 #8
0
func Test_Delete_multi(t *testing.T) {
	ws := New()
	ws.Move(2)
	ws.Addtyping([]byte{'a', 'b', 'c'}, 2)
	testhelpers.AssertString(t, "abc", ws.String())

	n := ws.Delete(3, 5)
	testhelpers.AssertString(t, "a", ws.String())
	testhelpers.AssertInt(t, 0, n)
}
예제 #9
0
func Test_Delete_spanning_offset(t *testing.T) {
	ws := New()
	ws.Move(2)
	ws.Addtyping([]byte{'a', 'b', 'c'}, 2)
	testhelpers.AssertString(t, "abc", ws.String())

	n := ws.Delete(1, 3)
	testhelpers.AssertString(t, "bc", ws.String())
	testhelpers.AssertInt(t, 1, n)
}
예제 #10
0
func Test_Sendtype(t *testing.T) {
	mock := &mockttyfd{make([][]byte, 0, 10)}
	tp := New(mock, Makecho())

	tp.addtype([]byte("hello\nbye"), 0, false)
	tp.Sendtype()

	testhelpers.AssertInt(t, 1, len(mock.writes))
	testhelpers.AssertString(t, "hello\n", string(mock.writes[0]))
	testhelpers.AssertString(t, "bye", string(tp.Typing))
}
예제 #11
0
func Test_TypeCook(t *testing.T) {
	mock := &mockttyfd{make([][]byte, 0, 10)}
	tp := New(mock, Makecho())

	s := "hello\n"
	e := &acme.Event{Nr: len(s), Text: []byte(s)}
	tp.Type(e)

	testhelpers.AssertInt(t, 1, len(mock.writes))
	testhelpers.AssertString(t, "hello\n", string(mock.writes[0]))
	testhelpers.AssertString(t, "", string(tp.Typing))
	testhelpers.AssertBool(t, true, tp.cook)
}
예제 #12
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.
}
예제 #13
0
// Positions 0, 1 are before the buffer.
// Position 2 is the end of the buffer.
func Test_Addtyping(t *testing.T) {
	ws := New()
	ws.Move(2)

	testhelpers.AssertBool(t, true, ws.Beforeslice(0))
	testhelpers.AssertBool(t, true, ws.Beforeslice(1))

	ws.Addtyping([]byte{'a'}, 2)
	testhelpers.AssertString(t, "a", ws.String())

	testhelpers.AssertBool(t, true, ws.Beforeslice(1))

	testhelpers.AssertBool(t, true, ws.Inslice(2))
	testhelpers.AssertBool(t, true, ws.Inslice(3))
	testhelpers.AssertBool(t, false, ws.Inslice(4))

	testhelpers.AssertInt(t, 2, ws.Offset)
	testhelpers.AssertBool(t, true, ws.Afterslice(2, 0))
	testhelpers.AssertBool(t, false, ws.Afterslice(1, 1))

	ws.Addtyping([]byte{'b'}, 3)
	testhelpers.AssertString(t, "ab", ws.String())
	testhelpers.AssertBool(t, true, ws.Inslice(4))
	testhelpers.AssertBool(t, false, ws.Inslice(5))

	p, q := ws.Extent()
	testhelpers.AssertInt(t, 2, p)
	testhelpers.AssertInt(t, 4, q)

	ws.Addtyping([]byte{'c'}, 4)
	testhelpers.AssertString(t, "abc", ws.String())
	testhelpers.AssertInt(t, len("abc"), ws.Ntyper())

	testhelpers.AssertInt(t, 2, ws.Offset)
	ws.Addtyping([]byte{'X'}, 2)
	testhelpers.AssertString(t, "Xabc", ws.String())
	testhelpers.AssertInt(t, len("Xabc"), ws.Ntyper())

	ws.Addtyping([]byte{'Y'}, 3)
	testhelpers.AssertString(t, "XYabc", ws.String())

}