|
| 1 | +import Testing |
| 2 | +@testable import SwiftTerm |
| 3 | + |
| 4 | +/// A full reset (RIS, `ESC c`) replaces the buffer, so any view that derives its |
| 5 | +/// scroll geometry from `lines.count` / `yDisp` has to be told about it. |
| 6 | +/// `syncScrollArea()` is a no-op stub, and none of the other paths that make a |
| 7 | +/// view recompute that geometry run here — there is no buffer switch, no scrolled |
| 8 | +/// line, no keystroke and no resize — so `resetToInitialState()` notifies |
| 9 | +/// explicitly. Without that, a view keeps the contentSize/contentOffset of the |
| 10 | +/// buffer that was just discarded and renders blank. |
| 11 | +@Suite("Full reset scroll area") |
| 12 | +struct ResetScrollAreaTests { |
| 13 | + @Test("RIS notifies the delegate that the buffer changed") |
| 14 | + func fullResetNotifiesDelegate() { |
| 15 | + let (terminal, delegate) = TerminalTestHarness.makeTerminal(cols: 80, rows: 24, scrollback: 500) |
| 16 | + |
| 17 | + // Build up scrollback so the reset is a real change in buffer size. |
| 18 | + for i in 0..<200 { |
| 19 | + terminal.feed(text: "line \(i)\r\n") |
| 20 | + } |
| 21 | + #expect(terminal.buffer.lines.count > terminal.rows) |
| 22 | + |
| 23 | + let before = delegate.bufferActivatedCount |
| 24 | + terminal.feed(text: "\u{1b}c") |
| 25 | + |
| 26 | + // The buffer really did shrink back to a single screen... |
| 27 | + #expect(terminal.buffer.lines.count == terminal.rows) |
| 28 | + #expect(terminal.buffer.yBase == 0) |
| 29 | + #expect(terminal.buffer.yDisp == 0) |
| 30 | + // ...and the delegate heard about it exactly once. |
| 31 | + #expect(delegate.bufferActivatedCount == before + 1) |
| 32 | + } |
| 33 | + |
| 34 | + @Test("Keypad mode changes do not claim the buffer changed") |
| 35 | + func keypadModeDoesNotNotify() { |
| 36 | + let (terminal, delegate) = TerminalTestHarness.makeTerminal(cols: 80, rows: 24, scrollback: 500) |
| 37 | + |
| 38 | + let before = delegate.bufferActivatedCount |
| 39 | + terminal.feed(text: "\u{1b}=") // application keypad |
| 40 | + terminal.feed(text: "\u{1b}>") // numeric keypad |
| 41 | + |
| 42 | + // These also call syncScrollArea(), but they do not touch the buffer, so |
| 43 | + // they must not be reported as a buffer activation: on iOS that resets |
| 44 | + // the scroll-follow state and would yank a user who has scrolled back |
| 45 | + // down to the bottom. |
| 46 | + #expect(delegate.bufferActivatedCount == before) |
| 47 | + } |
| 48 | +} |
0 commit comments