spec/unit/field/length_spec.rb in tty-table-0.1.0 vs spec/unit/field/length_spec.rb in tty-table-0.2.0

- old
+ new

@@ -1,21 +1,35 @@ # coding: utf-8 require 'spec_helper' -RSpec.describe TTY::Table::Field, '#length' do - let(:object) { described_class.new value } +RSpec.describe TTY::Table::Field, '.length' do + it "calculates length for nil string" do + field = described_class.new(nil) + expect(field.length).to eq(0) + end - subject { object.length } + it "calculates length for empty string" do + field = described_class.new('') + expect(field.length).to eq(0) + end - context 'with escaped value' do - let(:value) { "Multi\nLine" } + it "calculates maximum length for multiline string" do + field = described_class.new("Multi\nLine\nContent") + expect(field.length).to eq(7) + end - it { is_expected.to eql(5) } + it "calculates length for unicode string" do + field = described_class.new('こんにちは') + expect(field.length).to eq(10) end - context 'with unescaped value' do - let(:value) { "Multi\\nLine" } + it "calculates length for escaped string" do + field = described_class.new("Multi\\nLine") + expect(field.length).to eq(11) + end - it { is_expected.to eql(11) } + it "calculates length for colored string" do + field = described_class.new("\e[32;41mgreen on red\e[0m") + expect(field.length).to eq(12) end end