Sha256: e180fb80ce230acfc9368c3487e1250af6ea607dacbb0e715438335b1160c47f

Contents?: true

Size: 1.43 KB

Versions: 8

Compression:

Stored size: 1.43 KB

Contents

require_relative "../lib/fancy_irb"
require_relative 'fixtures'

describe FancyIrb::SizeDetector do
  include FancyIrb::SizeDetector

  before do
    FancyIrb.instance_variable_set(:@options, { unicode_display_width: true })
  end

  describe ".width_of" do
    it "returns 0 when no data given" do
      expect( width_of(nil) ).to eq 0
    end

    it "returns string length for 'normal' data" do
      expect( width_of("string") ).to eq 6
    end

    it "removes ansi escape chars" do
      expect( width_of("\e[31mstring\e[0m") ).to eq 6
    end

    it "respects double-width chars by default" do
      expect( width_of('一') ).to eq 2
    end

    context "unicode_display_width? false" do
      before do
        FancyIrb.instance_variable_set(:@options, { unicode_display_width: false })
      end

      it "does not respect double-width chars" do
        expect( width_of('一') ).to eq 1
      end
    end
  end

  describe ".height_of" do
    EXAMPLE_HEIGHT_DATA.each{ |data, terminal_cols, expected|
      example "#{data[0...20]}#{'...' if data[20]}".inspect.ljust(28) +
              "with terminal width #{terminal_cols} is #{expected}" do
        expect( height_of(data, terminal_cols) ).to eq expected
      end
    }

    it "can be accumulated" do
      data_head = "head"
      data_tail = "tail"
      expect(
        height_of(data_head, 80) + height_of(data_tail, 80)
      ).to eq height_of(data_head + data_tail, 80)
    end
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fancy_irb-1.4.3 spec/size_detector_spec.rb
fancy_irb-1.4.2 spec/size_detector_spec.rb
fancy_irb-1.4.1 spec/size_detector_spec.rb
fancy_irb-1.4.0 spec/size_detector_spec.rb
fancy_irb-1.3.0 spec/size_detector_spec.rb
fancy_irb-1.2.1 spec/size_detector_spec.rb
fancy_irb-1.2.0 spec/size_detector_spec.rb
fancy_irb-1.1.0 spec/size_detector_spec.rb