Sha256: 1ea29a88ef6187008c456d2eb5b01a3e5c6c7852b36be57bee6031495458e1e4

Contents?: true

Size: 1.86 KB

Versions: 7

Compression:

Stored size: 1.86 KB

Contents

require_relative '../../../test_helper'

module Vedeu
  describe Colour do
    let(:described_class)    { Colour }
    let(:described_instance) { described_class.new }
    let(:pair)               { [] }

    it { described_instance.must_be_instance_of(Colour) }

    describe '.set' do
      let(:subject) { described_class.set(pair) }

      it { subject.must_be_instance_of(String) }

      context 'when the foreground and background are specified as symbols' do
        context 'when both the foreground and background is specified' do
          let(:pair) { [:red, :yellow] }

          it 'returns the code for red on yellow' do
            subject.must_equal("\e[38;5;31m\e[48;5;43m")
          end
        end

        context 'when a foreground is specified' do
          let(:pair) { [:blue] }

          it 'returns the code for blue on default' do
            subject.must_equal("\e[38;5;34m\e[48;5;49m")
          end
        end

        context 'when a background is specified' do
          let(:pair) { [nil, :cyan] }

          it 'returns the code for default with cyan background' do
            subject.must_equal("\e[38;5;39m\e[48;5;46m")
          end
        end

        context 'when an invalid foreground/background is specified' do
          let(:pair) { [:melon, :raspberry] }

          it 'returns the default code' do
            subject.must_equal("\e[38;5;39m\e[48;5;49m")
          end
        end

        context 'when no foreground/background is specified' do
          let(:pair) { [] }

          it 'return an empty string' do
            subject.must_equal('')
          end
        end
      end

      context 'when the foreground and background are specified as strings' do
        let(:pair) { ['#ff0000', '#0000ff'] }

        it 'returns the default code' do
          subject.must_equal("\e[38;5;196m\e[48;5;21m")
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
vedeu-0.0.14 test/lib/vedeu/output/colour_test.rb
vedeu-0.0.13 test/lib/vedeu/output/colour_test.rb
vedeu-0.0.12 test/lib/vedeu/output/colour_test.rb
vedeu-0.0.11 test/lib/vedeu/output/colour_test.rb
vedeu-0.0.10 test/lib/vedeu/output/colour_test.rb
vedeu-0.0.9 test/lib/vedeu/output/colour_test.rb
vedeu-0.0.8 test/lib/vedeu/output/colour_test.rb