2013-08-29 13:10:46 +00:00
|
|
|
|
# encoding: utf-8
|
|
|
|
|
|
2013-08-04 21:06:56 +00:00
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
|
|
describe Terminal do
|
|
|
|
|
|
2013-09-15 12:47:15 +00:00
|
|
|
|
let(:terminal) { Terminal.new(6, 3) }
|
2013-09-14 11:16:47 +00:00
|
|
|
|
let(:first_line_text) { subject.as_json.first.map(&:first).join.strip }
|
2013-08-04 21:06:56 +00:00
|
|
|
|
|
|
|
|
|
before do
|
2013-09-14 11:16:47 +00:00
|
|
|
|
data.each do |chunk|
|
|
|
|
|
terminal.feed(chunk)
|
|
|
|
|
end
|
2013-08-04 21:06:56 +00:00
|
|
|
|
end
|
|
|
|
|
|
2013-09-14 11:16:47 +00:00
|
|
|
|
after do
|
|
|
|
|
terminal.release
|
2013-08-13 17:33:01 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '#snapshot' do
|
|
|
|
|
subject { terminal.snapshot }
|
2013-08-04 21:06:56 +00:00
|
|
|
|
|
2013-09-15 12:47:15 +00:00
|
|
|
|
let(:data) { ["fo\e[31mo\e[42mba\n", "\rr\e[0mb\e[1;4;5;7maz"] }
|
2013-08-04 21:06:56 +00:00
|
|
|
|
|
2013-09-10 19:29:17 +00:00
|
|
|
|
it 'returns an instance of Snapshot' do
|
|
|
|
|
expect(subject).to be_kind_of(Snapshot)
|
|
|
|
|
end
|
|
|
|
|
|
2013-09-15 12:47:15 +00:00
|
|
|
|
it "returns screen cells groupped by the character attributes" do
|
2013-09-10 19:29:17 +00:00
|
|
|
|
expect(subject.as_json).to eq([
|
2013-08-21 20:41:31 +00:00
|
|
|
|
[
|
2013-09-15 12:47:15 +00:00
|
|
|
|
['fo', {}],
|
|
|
|
|
['o', fg: 1],
|
|
|
|
|
['ba', fg: 1, bg: 2],
|
|
|
|
|
[' ', {}],
|
2013-09-14 11:16:47 +00:00
|
|
|
|
],
|
|
|
|
|
[
|
2013-09-15 12:47:15 +00:00
|
|
|
|
['r', fg: 1, bg: 2],
|
|
|
|
|
['b', {}],
|
|
|
|
|
['az', bold: true, underline: true, inverse: true, blink: true],
|
|
|
|
|
[' ', inverse: true], # <- cursor here
|
|
|
|
|
[' ', {}]
|
2013-08-21 20:41:31 +00:00
|
|
|
|
],
|
|
|
|
|
[
|
2013-09-15 12:47:15 +00:00
|
|
|
|
[' ', {}]
|
2013-08-21 20:41:31 +00:00
|
|
|
|
]
|
2013-08-04 21:06:56 +00:00
|
|
|
|
])
|
|
|
|
|
end
|
2013-08-29 13:10:46 +00:00
|
|
|
|
|
2013-09-14 11:16:47 +00:00
|
|
|
|
describe 'utf-8 characters handling' do
|
|
|
|
|
let(:terminal) { Terminal.new(20, 1) }
|
|
|
|
|
|
|
|
|
|
context "when polish national characters given" do
|
|
|
|
|
let(:data) { ['żółć'] }
|
|
|
|
|
|
|
|
|
|
it 'returns proper utf-8 string' do
|
|
|
|
|
expect(first_line_text).to eq('żółć')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "when chinese national characters given" do
|
|
|
|
|
let(:data) { ['雞機基積'] }
|
|
|
|
|
|
|
|
|
|
it 'returns proper utf-8 string' do
|
|
|
|
|
expect(first_line_text).to eq('雞機基積')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2013-08-29 13:10:46 +00:00
|
|
|
|
context "when invalid utf-8 character is yielded by tsm_screen" do
|
2013-09-14 11:16:47 +00:00
|
|
|
|
let(:terminal) { Terminal.new(3, 1) }
|
|
|
|
|
let(:data) { ["A\xc3\xff\xaaZ"] }
|
|
|
|
|
|
|
|
|
|
it 'gets replaced with "<22>"' do
|
|
|
|
|
expect(first_line_text).to eq('A<>Z')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "when double quote character ...." do
|
|
|
|
|
let(:terminal) { Terminal.new(6, 1) }
|
|
|
|
|
let(:data) { ['"a"b"'] }
|
|
|
|
|
|
|
|
|
|
it 'works' do
|
|
|
|
|
expect(first_line_text).to eq('"a"b"')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "when backslash character..." do
|
|
|
|
|
let(:terminal) { Terminal.new(6, 1) }
|
|
|
|
|
let(:data) { ['a\\b'] }
|
|
|
|
|
|
|
|
|
|
it 'works' do
|
|
|
|
|
expect(first_line_text).to eq('a\\b')
|
2013-08-29 13:10:46 +00:00
|
|
|
|
end
|
2013-09-14 11:16:47 +00:00
|
|
|
|
end
|
2013-08-29 13:10:46 +00:00
|
|
|
|
|
2013-09-14 11:16:47 +00:00
|
|
|
|
describe 'with a 256-color mode foreground color' do
|
|
|
|
|
subject { terminal.snapshot.as_json.first.first.last[:fg] }
|
|
|
|
|
|
|
|
|
|
let(:data) { ["\x1b[38;5;#{color_code}mX"] }
|
|
|
|
|
|
|
|
|
|
(1..255).each do |n|
|
|
|
|
|
context "of value #{n}" do
|
|
|
|
|
let(:color_code) { n }
|
|
|
|
|
|
|
|
|
|
it { should eq(n) }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'with a 256-color mode background color' do
|
|
|
|
|
subject { terminal.snapshot.as_json.first.first.last[:bg] }
|
|
|
|
|
|
|
|
|
|
let(:data) { ["\x1b[48;5;#{color_code}mX"] }
|
|
|
|
|
|
|
|
|
|
(1..255).each do |n|
|
|
|
|
|
context "of value #{n}" do
|
|
|
|
|
let(:color_code) { n }
|
|
|
|
|
|
|
|
|
|
it { should eq(n) }
|
|
|
|
|
end
|
2013-08-29 13:10:46 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
2013-08-04 21:06:56 +00:00
|
|
|
|
end
|
|
|
|
|
|
2013-09-10 19:29:17 +00:00
|
|
|
|
describe '#cursor' do
|
|
|
|
|
subject { terminal.cursor }
|
|
|
|
|
|
2013-09-14 11:16:47 +00:00
|
|
|
|
let(:data) { ["foo\n\rba"] }
|
|
|
|
|
|
2013-09-10 19:29:17 +00:00
|
|
|
|
it 'gets its x position from the screen' do
|
2013-09-14 11:16:47 +00:00
|
|
|
|
expect(subject.x).to eq(2)
|
2013-09-10 19:29:17 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'gets its y position from the screen' do
|
2013-09-14 11:16:47 +00:00
|
|
|
|
expect(subject.y).to eq(1)
|
2013-09-10 19:29:17 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'gets its visibility from the screen' do
|
2013-09-14 11:16:47 +00:00
|
|
|
|
expect(subject.visible).to eq(true)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "when cursor was hidden" do
|
|
|
|
|
before do
|
|
|
|
|
terminal.feed("\e[?25l")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'gets its visibility from the screen' do
|
|
|
|
|
expect(subject.visible).to eq(false)
|
|
|
|
|
end
|
2013-09-10 19:29:17 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2013-08-04 21:06:56 +00:00
|
|
|
|
end
|