package editor import ( "strings" "testing" ) func cacheDoc() *Editor { e := New() var b strings.Builder for i := 0; i < 200; i++ { b.WriteString("Some **prose** line with a [link](http://x) and `code` here.\n") } e.SetContent([]byte(b.String())) e.SetSize(80, 24) return e } // Scrolling and rendering must not re-scan the whole document: the visual model // depends only on content/width/theme/spell, none of which a scroll changes. func TestScrollReusesVisualCache(t *testing.T) { e := cacheDoc() e.buildCount = 0 for i := 0; i < 10; i++ { e.ScrollBy(1) _ = e.View() } if e.buildCount > 1 { t.Errorf("scroll+view rebuilt visual %d times, want <= 1", e.buildCount) } } // An edit must invalidate the cache so the next render reflects new content. func TestEditInvalidatesCache(t *testing.T) { e := cacheDoc() _ = e.View() // prime cache e.SetContent([]byte("brand new content\n")) out := e.View() if !strings.Contains(out, "brand new content") { t.Errorf("View after SetContent did not reflect new content:\n%s", out) } }