Class: TuiTui::TestRuntime
- Inherits:
-
Object
- Object
- TuiTui::TestRuntime
- Defined in:
- lib/tui_tui/test_runtime.rb
Overview
The Runtime with the Screen removed, for testing apps: inject events, then
assert on the folded model (app), the accumulated commands, quit?,
and the rendered view (screen / canvas). Events fold exactly as in
Runtime (via Runtime.step — the shared pure part of the loop, including
the inert-tick rule and unknown-command validation). Not loaded by
require "tui_tui" — opt in with require "tui_tui/test_runtime".
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
Instance Method Summary collapse
-
#canvas ⇒ Object
The current view's Canvas, for cell-level style assertions.
-
#initialize(app, rows: 24, cols: 80) ⇒ TestRuntime
constructor
A new instance of TestRuntime.
- #key(k) ⇒ Object
- #mouse(action:, col:, row:, button: nil) ⇒ Object
- #quit? ⇒ Boolean
- #resize(rows:, cols:) ⇒ Object
-
#screen ⇒ Object
The current view as Canvas#to_text (a style-free string).
-
#tick ⇒ Object
Same rule as Runtime: a tick reaches
updateonly when the app implementswants_tick?and it returns true; otherwise Runtime.step treats the tick as inert and nothing is folded. -
#type(str) ⇒ Object
One KeyEvent per grapheme cluster, as typing arrives from a terminal.
Constructor Details
#initialize(app, rows: 24, cols: 80) ⇒ TestRuntime
Returns a new instance of TestRuntime.
19 20 21 22 23 24 |
# File 'lib/tui_tui/test_runtime.rb', line 19 def initialize(app, rows: 24, cols: 80) @app = app @size = Size.new(rows: rows, cols: cols) @commands = [] @quit = false end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
17 18 19 |
# File 'lib/tui_tui/test_runtime.rb', line 17 def app @app end |
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
17 18 19 |
# File 'lib/tui_tui/test_runtime.rb', line 17 def commands @commands end |
Instance Method Details
#canvas ⇒ Object
The current view's Canvas, for cell-level style assertions. Built like
Runtime's: a RenderContext, so legacy view(size) apps work too.
55 |
# File 'lib/tui_tui/test_runtime.rb', line 55 def canvas = @app.view(RenderContext.new(size: @size, chrome: BoxChrome::ASCII)) |
#key(k) ⇒ Object
28 |
# File 'lib/tui_tui/test_runtime.rb', line 28 def key(k) = fold(KeyEvent.new(key: k)) |
#mouse(action:, col:, row:, button: nil) ⇒ Object
46 47 48 |
# File 'lib/tui_tui/test_runtime.rb', line 46 def mouse(action:, col:, row:, button: nil) fold(MouseEvent.new(action: action, button: , col: col, row: row)) end |
#quit? ⇒ Boolean
26 |
# File 'lib/tui_tui/test_runtime.rb', line 26 def quit? = @quit |
#resize(rows:, cols:) ⇒ Object
41 42 43 44 |
# File 'lib/tui_tui/test_runtime.rb', line 41 def resize(rows:, cols:) @size = Size.new(rows: rows, cols: cols) fold(ResizeEvent.new(size: @size)) end |
#screen ⇒ Object
The current view as Canvas#to_text (a style-free string).
51 |
# File 'lib/tui_tui/test_runtime.rb', line 51 def screen = canvas.to_text |
#tick ⇒ Object
Same rule as Runtime: a tick reaches update only when the app
implements wants_tick? and it returns true; otherwise Runtime.step
treats the tick as inert and nothing is folded.
39 |
# File 'lib/tui_tui/test_runtime.rb', line 39 def tick = fold(TickEvent.new) |
#type(str) ⇒ Object
One KeyEvent per grapheme cluster, as typing arrives from a terminal.
31 32 33 34 |
# File 'lib/tui_tui/test_runtime.rb', line 31 def type(str) str.each_grapheme_cluster { |grapheme| key(grapheme) } self end |