With typing, Enter, and delete in hand, a sequence of keystrokes should compose into exactly the text you expect. Today you replay a small session end to end and pin the result.
Apply a scripted sequence of edits from an empty buffer and confirm the exact text and cursor.
Individual edits are only trustworthy if they compose, so this lesson runs a
little session and checks the whole outcome at once. Typing "cat" fills the first
line and leaves the cursor at its end; Enter splits to a new line; typing "dog"
fills that; one backspace trims the final g. The result is "cat\ndo" with the
cursor at row 1, column 2 - and getting there exercises the offset translation, the
piece-splitting insert, the line-splitting Enter, and the in-line delete, all in
sequence.
This is the pattern the capstone scales up: an editor is ultimately a machine that turns a stream of keystrokes into a buffer state, and the way to trust it is to feed it a script and assert the exact text and cursor it produces. No terminal is involved - the “keystrokes” are just method calls - which is precisely what makes the behavior reproducible and checkable. The editing core is now complete; the remaining chapters make it something you can see, save, search, and undo.
// drive the editor with the operations from this chapter, in order:for _, c := range "cat" { e.InsertChar(c) }e.Enter()for _, c := range "dog" { e.InsertChar(c) }e.Backspace()// then assert Text() and the cursor position