Sha256: 066d48138a74d5ad50b2e0d341f66d6219335abae202c30bfac9b6602d913f8e

Contents?: true

Size: 1.53 KB

Versions: 19

Compression:

Stored size: 1.53 KB

Contents

require 'spec_helper'
require 'rainbow/string_utils'

module Rainbow
  describe StringUtils do
    describe '.wrap_with_sgr' do

      subject { described_class.wrap_with_sgr(string, codes) }

      let(:string) { 'hello' }
      let(:codes) { [1] }

      it "doesn't mutate original string" do
        string.freeze
        expect(subject).to eq("\e[1mhello\e[0m")
        expect(string).to eq('hello')
      end

      context "when subclass of String class given" do
        class Stringgg < ::String; end

        let(:string) { Stringgg.new('hello') }

        it { should eq("\e[1mhello\e[0m") }
      end

      context "when no codes given" do
        let(:codes) { [] }

        it "doesn't wrap the given string with any sgr sequence" do
          expect(subject).to eq("hello")
        end
      end

      context "when single code given" do
        let(:codes) { [1] }

        it "wraps the given string with sgr sequence for given codes" do
          expect(subject).to eq("\e[1mhello\e[0m")
        end
      end

      context "when multiple codes given" do
        let(:codes) { [1, 2] }

        it "wraps the given string with sgr sequence for given codes" do
          expect(subject).to eq("\e[1;2mhello\e[0m")
        end
      end

      context "when wrapping an already wrapped string" do
        let(:string) { "\e[1;2mhello\e[0m" }
        let(:codes) { [3, 4] }

        it "wraps the given string with sgr sequence for given codes" do
          expect(subject).to eq("\e[1;2m\e[3;4mhello\e[0m")
        end
      end

    end
  end
end

Version data entries

19 entries across 19 versions & 5 rubygems

Version Path
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/rainbow-2.2.2/spec/unit/string_utils_spec.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/rainbow-2.2.2/spec/unit/string_utils_spec.rb
pract6-0.1.0 .gem/ruby/2.3.0/gems/rainbow-2.2.2/spec/unit/string_utils_spec.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/rainbow-2.2.2/spec/unit/string_utils_spec.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/rainbow-2.2.2/spec/unit/string_utils_spec.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/rainbow-2.2.2/spec/unit/string_utils_spec.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/rainbow-2.2.2/spec/unit/string_utils_spec.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/rainbow-2.2.2/spec/unit/string_utils_spec.rb
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/rainbow-2.2.2/spec/unit/string_utils_spec.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/rainbow-2.2.2/spec/unit/string_utils_spec.rb
rainbow-2.2.2 spec/unit/string_utils_spec.rb
rainbow-2.2.1 spec/unit/string_utils_spec.rb
rainbow-2.1.0 spec/unit/string_utils_spec.rb
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rainbow-2.0.0/spec/unit/string_utils_spec.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rainbow-2.0.0/spec/unit/string_utils_spec.rb
rainbow-2.0.0 spec/unit/string_utils_spec.rb
rainbow-1.99.2 spec/unit/string_utils_spec.rb
rainbow-1.99.1 spec/unit/string_utils_spec.rb
rainbow-1.99.0 spec/unit/string_utils_spec.rb