package editor import ( "testing" ) func TestInsertChar(t *testing.T) { state := NewState() TheState = state state.Editor.Buffer = "Hello" state.Editor.CursorPosition = 5 // End of "Hello" HandleInsert("!") // Assuming we create this function expected := "Hello!" if state.Editor.Buffer != expected { t.Errorf("Expected buffer %q, got %q", expected, state.Editor.Buffer) } if state.Editor.CursorPosition != 6 { t.Errorf("Expected cursor position 6, got %d", state.Editor.CursorPosition) } } func TestBackspace(t *testing.T) { state := NewState() TheState = state state.Editor.Buffer = "Hello" state.Editor.CursorPosition = 5 HandleBackspace() // Assuming we create this function expected := "Hell" if state.Editor.Buffer != expected { t.Errorf("Expected buffer %q, got %q", expected, state.Editor.Buffer) } if state.Editor.CursorPosition != 4 { t.Errorf("Expected cursor position 4, got %d", state.Editor.CursorPosition) } }