Sha256: 3de188a11f2210a5c45d40c090c2fe5f8789a0f8fa1381b30d7544c298069504

Contents?: true

Size: 915 Bytes

Versions: 9

Compression:

Stored size: 915 Bytes

Contents

# coding: utf-8

require 'spec_helper'

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

  it "calculates length for empty string" do
    field = described_class.new('')
    expect(field.length).to eq(0)
  end

  it "calculates maximum length for multiline string" do
    field = described_class.new("Multi\nLine\nContent")
    expect(field.length).to eq(7)
  end

  it "calculates length for unicode string" do
    field = described_class.new('こんにちは')
    expect(field.length).to eq(10)
  end

  it "calculates length for escaped string" do
    field = described_class.new("Multi\\nLine")
    expect(field.length).to eq(11)
  end

  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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
tty-table-0.10.0 spec/unit/field/length_spec.rb
tty-table-0.9.0 spec/unit/field/length_spec.rb
tty-table-0.8.0 spec/unit/field/length_spec.rb
tty-table-0.7.0 spec/unit/field/length_spec.rb
tty-table-0.6.0 spec/unit/field/length_spec.rb
tty-table-0.5.0 spec/unit/field/length_spec.rb
tty-table-0.4.0 spec/unit/field/length_spec.rb
tty-table-0.3.0 spec/unit/field/length_spec.rb
tty-table-0.2.0 spec/unit/field/length_spec.rb