Sha256: f9496d1fd29ae334ddc13a47ddbb8f9c2995aa965e42c49d25bfb1efaa4a79cf

Contents?: true

Size: 1.72 KB

Versions: 1

Compression:

Stored size: 1.72 KB

Contents

# -*- encoding: utf-8 -*-

require 'spec_helper'

describe TTY::Text::Truncation, '#truncate' do
  let(:instance) { described_class.new }
  let(:separator) { nil }
  let(:trailing) { '…' }
  let(:options) { { :length => length, :separator => separator, :trailing => trailing }  }

  subject { described_class.new(text, options).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 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

1 entries across 1 versions & 1 rubygems

Version Path
tty-0.0.7 spec/tty/text/truncation/truncate_spec.rb