File: block_spec.rb

package info (click to toggle)
ruby-morpher 0.2.6-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 520 kB
  • sloc: ruby: 2,366; makefile: 4
file content (92 lines) | stat: -rw-r--r-- 2,009 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
describe Morpher::Evaluator::Transformer::Block do

  let(:ast) do
    s(:block, body_a, body_b)
  end

  let(:object) do
    Morpher.compile(ast)
  end

  let(:evaluator_a) do
    Morpher.compile(body_a)
  end

  let(:evaluator_b) do
    Morpher.compile(body_b)
  end

  context 'transitive' do

    let(:body_a) do
      s(:guard, s(:primitive, String))
    end

    let(:body_b) do
      s(:guard, s(:primitive, String))
    end

    let(:valid_input)     { 'foo' }
    let(:expected_output) { 'foo' }
    let(:invalid_input)   { :foo  }

    let(:expected_exception) do
      Morpher::Evaluator::Transformer::TransformError.new(object.body.first, invalid_input)
    end

    include_examples 'transitive evaluator'

    context 'with invalid input' do
      specify '#evaluation' do
        evaluation = object.evaluation(invalid_input)
        expect(evaluation.evaluations.length).to eql(1)
      end
    end
  end

  context 'intransitive' do

    let(:valid_input)     { { 'foo' => 'bar' } }
    let(:invalid_input)   { {}                 }
    let(:expected_output) { true               }

    let(:body_a) do
      s(:key_fetch, 'foo')
    end

    let(:body_b) do
      s(:primitive, String)
    end

    let(:expected_exception) do
      Morpher::Evaluator::Transformer::TransformError.new(object.body.first, invalid_input)
    end

    include_examples 'intransitive evaluator'

    context '#evaluation' do
      subject { object.evaluation(valid_input) }

      let(:evaluations) do
        [
          evaluator_a.evaluation(valid_input),
          evaluator_b.evaluation('bar')
        ]
      end

      context 'with valid input' do
        it 'returns evaluation' do
          should eql(
            Morpher::Evaluation::Nary.new(
              input:       valid_input,
              evaluator:   object,
              evaluations: evaluations,
              output:      expected_output,
              success:     true
            )
          )
        end
      end
    end
  end
end