Sha256: 05aed80661863a9fd02612d5a32701d8f9ebee5f194526ee3a0cd5b070a77bf0

Contents?: true

Size: 1.07 KB

Versions: 19

Compression:

Stored size: 1.07 KB

Contents

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

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

    let(:sys){
      system
    }

    let(:compiled){
      subject.compile(sys)
    }

    let(:ast){
      subject.to_ast
    }

    context 'when referening an anonymous type' do
      let(:input){ 'Int = .Integer' }

      it 'add the type to the system' do
        compiled
        expect(sys["Int"]).to be_a(BuiltinType)
      end

      it 'has the expected AST' do
        expect(ast).to eq([:type_def, "Int", [:builtin_type, "Integer"]])
      end
    end

    context 'when making an alias' do
      let(:legacy) {
        BuiltinType.new(Integer, "Int")
      }

      let(:input){ 'Alias = Int' }

      before do
        sys.add_type(legacy)
      end

      it 'add the type to the system' do
        compiled
        expect(sys["Alias"]).to be_a(AliasType)
        expect(sys["Alias"]).to eq(legacy)
      end

      it 'has the expected AST' do
        expect(ast).to eq([:type_def, "Alias", [:type_ref, "Int"]])
      end
    end

  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

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