Sha256: d18adf733347e7bff91ef3dc8c5106fd124996a0907d4ddc5dbbd126db98155e
Contents?: true
Size: 1.81 KB
Versions: 2
Compression:
Stored size: 1.81 KB
Contents
# -*- encoding: utf-8 -*- require 'spec_helper' describe TTY::Text::Truncation, '#truncate' do let(:object) { described_class.new(text, options) } let(:separator) { nil } let(:trailing) { '…' } let(:options) { { :length => length, :separator => separator, :trailing => trailing } } subject { object.truncate } context 'unicode support' do let(:text) { 'ラドクリフ、マラソン五輪代表に1万m出場にも含み' } context 'with zero length' do let(:length) { 0 } it { should == text } end context 'with nil length' do let(:length) { nil } it { should == text } end context 'with equal length' do let(:length) { text.length } it { should == text } end context 'with truncation' do let(:length) { 12 } it { should == "ラドクリフ、マラソン五#{trailing}" } end context 'without truncation' do let(:length) { 100 } it { should == text } end context 'with separator' do let(:length) { 12 } let(:separator) { ' ' } it { should == "ラドクリフ、マラソン五#{trailing}" } end end context 'with custom trailing' do let(:text) { 'ラドクリフ、マラソン五輪代表に1万m出場にも含み' } let(:length) { 20 } let(:trailing) { '... (see more)' } it { should == "ラドクリフ、#{trailing}" } end context 'with separator' do let(:length) { 25 } let(:text) { "Immense as whales, the motion of whose vast bodies can in a peaceful calm trouble the ocean til it boil." } context 'blank' do let(:separator) { '' } it { should == "Immense as whales, the m#{trailing}"} end context 'space' do let(:separator) { ' ' } it { should == "Immense as whales, the…" } end end end # truncate
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
tty-0.0.10 | spec/tty/text/truncation/truncate_spec.rb |
tty-0.0.9 | spec/tty/text/truncation/truncate_spec.rb |