Sha256: fa738493c4fbec8f4ff9010c6f741242b036ede93f34e1bb3912d551c43d8527

Contents?: true

Size: 1.6 KB

Versions: 11

Compression:

Stored size: 1.6 KB

Contents

# encoding: utf-8

RSpec.describe Pastel::Color, '.strip' do

  subject(:color) { described_class.new(enabled: true) }

  it 'strips ansi color from string' do
    string = "This is a \e[1m\e[34mbold blue text\e[0m"
    expect(color.strip(string)).to eq('This is a bold blue text')
  end

  it "strips partial ansi color" do
    string = "foo\e[1mbar"
    expect(color.strip(string)).to eq('foobar')
  end

  it 'preserves movement characters' do
    # [176A - move cursor up n lines
    expect(color.strip("foo\e[176Abar")).to eq("foo\e[176Abar")
  end

  it 'strips reset/setfg/setbg/italics/strike/underline sequence' do
    string = "\x1b[0;33;49;3;9;4mfoo\x1b[0m"
    expect(color.strip(string)).to eq("foo")
  end

  it 'strips octal in encapsulating brackets' do
    string = "\[\033[01;32m\]u@h \[\033[01;34m\]W $ \[\033[00m\]"
    expect(color.strip(string)).to eq('[]u@h []W $ []')
  end

  it 'strips octal codes without brackets' do
    string = "\033[01;32mu@h \033[01;34mW $ \033[00m"
    expect(color.strip(string)).to eq('u@h W $ ')
  end

  it 'strips octal with multiple colors' do
    string = "\e[3;0;0;mfoo\e[8;50;0m"
    expect(color.strip(string)).to eq('foo')
  end

  it "strips multiple colors delimited by :" do
    string = "\e[31:44:4mfoo\e[0m"
    expect(color.strip(string)).to eq('foo')
  end

  it 'strips control codes' do
    string = "WARN. \x1b[1m&\x1b[0m ERR. \x1b[7m&\x1b[0m"
    expect(color.strip(string)).to eq('WARN. & ERR. &')
  end

  it 'strips escape bytes' do
    string = "This is a \e[1m\e[34mbold blue text\e[0m"
    expect(color.strip(string)).to eq("This is a bold blue text")
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
pokedex-terminal-0.2.8 vendor/bundle/ruby/2.7.0/gems/pastel-0.7.3/spec/unit/color/strip_spec.rb
pokedex-terminal-0.2.7 vendor/bundle/ruby/2.7.0/gems/pastel-0.7.3/spec/unit/color/strip_spec.rb
pokedex-terminal-0.2.6 vendor/bundle/ruby/2.7.0/gems/pastel-0.7.3/spec/unit/color/strip_spec.rb
pokedex-terminal-0.2.5 vendor/bundle/ruby/2.7.0/gems/pastel-0.7.3/spec/unit/color/strip_spec.rb
pokedex-terminal-0.2.4 vendor/bundle/ruby/2.7.0/gems/pastel-0.7.3/spec/unit/color/strip_spec.rb
pastel-0.7.3 spec/unit/color/strip_spec.rb
pastel-0.7.2 spec/unit/color/strip_spec.rb
pastel-0.7.1 spec/unit/color/strip_spec.rb
pastel-0.7.0 spec/unit/color/strip_spec.rb
pastel-0.6.1 spec/unit/color/strip_spec.rb
pastel-0.6.0 spec/unit/color/strip_spec.rb