Sha256: eaa71e95c71208f9a234d5d8fed92a228c8cd6faefd4651618873a66567cf5e3

Contents?: true

Size: 1.9 KB

Versions: 19

Compression:

Stored size: 1.9 KB

Contents

require 'spec_helper'
module Finitio
  describe Syntax, "relation_type" do

    subject{
      Syntax.parse(input, root: "relation_type")
    }

    describe "compilation result" do
      let(:compiled){
        subject.compile(type_factory)
      }

      context 'empty heading' do
        let(:input){ '{{ }}' }

        it 'compiles to a RelationType' do
          expect(compiled).to be_a(RelationType)
          expect(compiled.heading).to be_empty
        end
      end

      context '{{a: .Integer}}' do
        let(:input){ '{{a: .Integer}}' }

        it 'compiles to a RelationType' do
          expect(compiled).to be_a(RelationType)
          expect(compiled.heading.size).to eq(1)
        end
      end

      context '{{a: .Integer, b: .Float}}' do
        let(:input){ '{{a: .Integer, b: .Float}}' }

        it 'compiles to a RelationType' do
          expect(compiled).to be_a(RelationType)
          expect(compiled.heading.size).to eq(2)
        end
      end

      context '{{a: .Integer, b :? .Float}}' do
        let(:input){ '{{a: .Integer, b :? .Float}}' }

        it 'compiles to a MultiRelationType' do
          expect(compiled).to be_a(MultiRelationType)
          expect(compiled.heading.size).to eq(2)
        end
      end
    end

    describe "AST" do
      let(:ast){ subject.to_ast }

      context '{{a: .Integer}}' do
        let(:input){ '{{a: .Integer}}' }

        it{
          expect(ast).to eq([
            :relation_type,
            [
              :heading,
              [ :attribute, "a", [:builtin_type, "Integer" ]]
            ]
          ])
        }
      end

      context '{{a :? .Integer}}' do
        let(:input){ '{{a :? .Integer}}' }

        it{
          expect(ast).to eq([
            :multi_relation_type,
            [
              :heading,
              [ :attribute, "a", [:builtin_type, "Integer" ], false]
            ]
          ])
        }
      end
    end

  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
finitio-0.12.0 spec/syntax/nodes/test_relation_type.rb
finitio-0.11.4 spec/syntax/nodes/test_relation_type.rb
finitio-0.11.3 spec/syntax/nodes/test_relation_type.rb
finitio-0.11.2 spec/syntax/nodes/test_relation_type.rb
finitio-0.11.1 spec/syntax/nodes/test_relation_type.rb
finitio-0.10.0 spec/syntax/nodes/test_relation_type.rb
finitio-0.9.1 spec/syntax/nodes/test_relation_type.rb
finitio-0.9.0 spec/syntax/nodes/test_relation_type.rb
finitio-0.8.0 spec/syntax/nodes/test_relation_type.rb
finitio-0.7.0 spec/syntax/nodes/test_relation_type.rb
finitio-0.7.0.pre.rc4 spec/syntax/nodes/test_relation_type.rb
finitio-0.7.0.pre.rc3 spec/syntax/nodes/test_relation_type.rb
finitio-0.7.0.pre.rc2 spec/syntax/nodes/test_relation_type.rb
finitio-0.7.0.pre.rc1 spec/syntax/nodes/test_relation_type.rb
finitio-0.6.1 spec/syntax/nodes/test_relation_type.rb
finitio-0.6.0 spec/syntax/nodes/test_relation_type.rb
finitio-0.5.2 spec/syntax/nodes/test_relation_type.rb
finitio-0.5.1 spec/syntax/nodes/test_relation_type.rb
finitio-0.5.0 spec/syntax/nodes/test_relation_type.rb