Sha256: dc89bc0b91574b0517b0d184ec6c06a309b181b0264e659edfd70778ced91f07

Contents?: true

Size: 1.99 KB

Versions: 7

Compression:

Stored size: 1.99 KB

Contents

require 'spec_helper'
module Finitio
  describe Syntax, '.compile' do

    subject do
      Syntax.compile(source)
    end

    context 'with a single main type' do
      let(:source){
        <<-EOF.strip
        .Integer
        EOF
      }

      it{ should be_a(System) }

      it 'should have main type' do
        expect(subject.main).to be_a(BuiltinType)
        expect(subject['Main']).to be(subject.main)
      end
    end

    context 'with a single main alias type' do
      let(:source){
        <<-EOF.strip
        Int = .Integer
        Int
        EOF
      }

      it{ should be_a(System) }

      it 'should have main type' do
        expect(subject.main).to be_a(AliasType)
        expect(subject['Main']).to be(subject.main)
      end
    end

    context 'with lots of proxies to resolve' do
      let(:source){
        <<-EOF.strip
        Deep = .String
        Obj = { i: Deep }
        Objs = [Obj]
        EOF
      }

      it{ should be_a(System) }

      it 'should work fine' do
        expect {
          subject['Objs'].dress([{i: "hello"}])
        }.not_to raise_error
      end
    end

    context 'with a recursive def' do
      let(:source){
        <<-EOF.strip
        S = .String
        NodeLabel = S
        Tree = { label: NodeLabel, children: [Tree] }
        EOF
      }

      it{ should be_a(System) }

      it 'should work ine' do
        expect {
          subject['Tree'].dress({ label: "Root", children: [
            { label: "Child1", children: [] },
            { label: "Child2", children: [] }
          ]})
        }.not_to raise_error
      end
    end

    context 'with AD types' do
      let(:source){
        <<-EOF.strip
        Colors = [Color]
        Color = .Color <rgb> { r: Byte, g: Byte, b: Byte }
        Byte = Int(i | i>0)
        Int = .Integer
        EOF
      }

      it{ should be_a(System) }

      it 'should work ine' do
        got = subject['Colors'].dress([{ r: 10, g: 15, b: 20 }])
        expect(got.first).to be_a(Color)
      end
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
finitio-0.11.3 spec/syntax/test_compile.rb
finitio-0.11.2 spec/syntax/test_compile.rb
finitio-0.11.1 spec/syntax/test_compile.rb
finitio-0.10.0 spec/syntax/test_compile.rb
finitio-0.9.1 spec/syntax/test_compile.rb
finitio-0.9.0 spec/syntax/test_compile.rb
finitio-0.8.0 spec/syntax/test_compile.rb