2013-08-04 21:06:56 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Terminal do
|
|
|
|
|
|
|
|
let(:terminal) { Terminal.new(20, 10) }
|
|
|
|
let(:tsm_screen) { double('tsm_screen', :draw => nil) }
|
|
|
|
let(:tsm_vte) { double('tsm_vte', :input => nil) }
|
|
|
|
let(:snapshot) { double('snapshot') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(TSM::Screen).to receive(:new).with(20, 10) { tsm_screen }
|
|
|
|
allow(TSM::Vte).to receive(:new).with(tsm_screen) { tsm_vte }
|
|
|
|
allow(Snapshot).to receive(:build).with([:array]) { snapshot }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#feed' do
|
|
|
|
subject { terminal.feed('foo') }
|
|
|
|
|
|
|
|
it 'feeds the vte with the data' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(tsm_vte).to have_received(:input).with('foo')
|
|
|
|
end
|
2013-08-13 17:33:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#snapshot' do
|
|
|
|
subject { terminal.snapshot }
|
2013-08-04 21:06:56 +00:00
|
|
|
|
2013-08-21 20:41:31 +00:00
|
|
|
def make_attr(attrs = {})
|
|
|
|
TSM::ScreenAttribute.new.tap do |screen_attribute|
|
|
|
|
attrs.each { |name, value| screen_attribute[name] = value }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns each screen cell with its character attributes" do
|
2013-08-04 21:06:56 +00:00
|
|
|
expect(tsm_screen).to receive(:draw).
|
2013-08-21 20:41:31 +00:00
|
|
|
and_yield(0, 0, 'f', make_attr(fg: 1)).
|
|
|
|
and_yield(1, 0, 'o', make_attr(bg: 2)).
|
|
|
|
and_yield(0, 1, 'o', make_attr(bold?: true)).
|
|
|
|
and_yield(1, 1, 'b', make_attr(fg: 2, bg: 3,
|
|
|
|
bold?: true, underline?: true,
|
|
|
|
inverse?: true, blink?: true))
|
2013-08-04 21:06:56 +00:00
|
|
|
|
|
|
|
expect(subject).to eq([
|
2013-08-21 20:41:31 +00:00
|
|
|
[
|
|
|
|
['f', fg: 1],
|
|
|
|
['o', bg: 2]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
['o', bold: true],
|
|
|
|
['b', fg: 2, bg: 3, bold: true, underline: true, inverse: true,
|
|
|
|
blink: true]
|
|
|
|
]
|
2013-08-04 21:06:56 +00:00
|
|
|
])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|