Sha256: 62f32473f3e1ceecf015af374652b3fb45bfdafcebbebb89bdde26b9d7cc0b16

Contents?: true

Size: 1.66 KB

Versions: 11

Compression:

Stored size: 1.66 KB

Contents

require 'test_helper'

module Vedeu

  module Renderers

    describe JSON do

      let(:described) { Vedeu::Renderers::JSON }
      let(:instance)  { described.new(output, options) }
      let(:output)    {}
      let(:options)   { {} }

      describe '#initialize' do
        it { instance.must_be_instance_of(described) }
        it { instance.instance_variable_get('@output').must_equal(output) }
        it { instance.instance_variable_get('@options').must_equal(options) }
      end

      describe '.render' do
        subject { described.render(output, options) }

        it { subject.must_be_instance_of(String) }

        context 'when the output is empty' do
          it { subject.must_equal('') }
        end

        context 'when the output is not empty' do
          let(:colour) {
            Vedeu::Colour.new(foreground: '#ff0000', background: '#ffffff')
          }
          let(:output) {
            [
              [
                Vedeu::Char.new(value: 'a',
                                colour: colour,
                                position: Vedeu::Position[5, 3])
              ]
            ]
          }
          let(:expected) {
            <<-eos
[
  {
    \"border\": \"\",
    \"colour\": {
      \"background\": \"\\u001b[48;2;255;255;255m\",
      \"foreground\": \"\\u001b[38;2;255;0;0m\"
    },
    \"parent\": {
      \"background\": \"\",
      \"foreground\": \"\",
      \"style\": \"\"
    },
    \"position\": {
      \"y\": 5,
      \"x\": 3
    },
    \"style\": \"\",
    \"value\": \"a\"
  }
]
            eos
          }

          it { subject.must_equal(expected.chomp) }
        end
      end

    end # JSON

  end # Renderers

end # Vedeu

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
vedeu-0.4.50 test/lib/vedeu/output/renderers/json_test.rb
vedeu-0.4.49 test/lib/vedeu/output/renderers/json_test.rb
vedeu-0.4.48 test/lib/vedeu/output/renderers/json_test.rb
vedeu-0.4.47 test/lib/vedeu/output/renderers/json_test.rb
vedeu-0.4.46 test/lib/vedeu/output/renderers/json_test.rb
vedeu-0.4.45 test/lib/vedeu/output/renderers/json_test.rb
vedeu-0.4.44 test/lib/vedeu/output/renderers/json_test.rb
vedeu-0.4.43 test/lib/vedeu/output/renderers/json_test.rb
vedeu-0.4.42 test/lib/vedeu/output/renderers/json_test.rb
vedeu-0.4.41 test/lib/vedeu/output/renderers/json_test.rb
vedeu-0.4.40 test/lib/vedeu/output/renderers/json_test.rb