示例#1
0
func Test_Israw(t *testing.T) {
	tp := New(new(mockttyfd), Makecho())
	testhelpers.AssertBool(t, false, tp.Israw())

	tp.Setcook(false)
	testhelpers.AssertBool(t, true, tp.Israw())
	tp.Setcook(true)
	testhelpers.AssertBool(t, false, tp.Israw())
}
示例#2
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())

}
示例#3
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)
}