From faa9c2c410212680e3cd0492d8b29cfabfc8e635 Mon Sep 17 00:00:00 2001 From: Luke Wilson Date: Tue, 13 Apr 2021 11:19:23 -0500 Subject: [PATCH] Added rope buffer anchors test --- ui/buffer/rope_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/ui/buffer/rope_test.go b/ui/buffer/rope_test.go index c67bf2e..c16c2ac 100644 --- a/ui/buffer/rope_test.go +++ b/ui/buffer/rope_test.go @@ -127,3 +127,22 @@ func TestRopeSlice(t *testing.T) { t.Errorf("Second line and slice were not equal, got \"%s\"", secondLine) } } + +func TestRopeAnchors(t *testing.T) { + var buf Buffer = NewRopeBuffer([]byte("abc\ndef\nghi")) + myCursor := Cursor{buffer: &buf, position: position{1, 1}} // Points to 'e' on second line + + buf.RegisterCursor(&myCursor) // Now the buffer will move the cursor based on changes to contents + + buf.Remove(1, 0, 1, 3) // Remove whole second line ('d' to '\n') + if line, col := myCursor.GetLineCol(); line != 1 && col != 0 { + t.Errorf("Expected cursor line,col: %d,%d ; got %d,%d", 1, 0, line, col) + } + + buf.Insert(0, 0, []byte("def\n")) // "def\nabc\nghi" + if line, col := myCursor.GetLineCol(); line != 2 && col != 0 { + t.Errorf("Expected cursor line,col: %d,%d ; got %d,%d", 2, 0, line, col) + } + + buf.UnregisterCursor(&myCursor) +}