Sha256: df3decdf32138996f8c5ce2a95657451fdc92430c095a3e685a68f29fafa2f0c
Contents?: true
Size: 1.96 KB
Versions: 5
Compression:
Stored size: 1.96 KB
Contents
require 'spec_helper' module Finitio describe Syntax, "attribute" do subject{ Syntax.parse(input, root: "attribute") } describe 'compilation result' do let(:compiled){ subject.compile(type_factory) } context 'a: .Integer' do let(:input){ 'a: .Integer' } it 'compiles to an mandatory Attribute' do expect(compiled).to be_a(Attribute) expect(compiled.name).to eq(:a) expect(compiled.type).to be_a(BuiltinType) expect(compiled.type.ruby_type).to be(Integer) expect(compiled).to be_required end end context 'a :? .Integer' do let(:input){ 'a :? .Integer' } it 'compiles to an optional Attribute' do expect(compiled).to be_a(Attribute) expect(compiled.name).to eq(:a) expect(compiled.type).to be_a(BuiltinType) expect(compiled.type.ruby_type).to be(Integer) expect(compiled).not_to be_required end end context 'when using dashes in attribute name' do let(:input){ 'created-at : .Integer' } it 'works' do expect(compiled).to be_a(Attribute) expect(compiled.name).to eq(:"created-at") expect(compiled.type).to be_a(BuiltinType) expect(compiled.type.ruby_type).to be(Integer) expect(compiled).to be_required end end end describe 'AST' do let(:ast){ subject.to_ast } context 'a: .Integer' do let(:input){ 'a: .Integer' } it{ expect(ast).to eq([:attribute, "a", [:builtin_type, "Integer"]]) } end context 'a :? .Integer' do let(:input){ 'a :? .Integer' } it{ expect(ast).to eq([:attribute, "a", [:builtin_type, "Integer"], false]) } end context '_ : .Integer' do let(:input){ '_ : .Integer' } it{ expect(ast).to eq([:attribute, "_", [:builtin_type, "Integer"]]) } end end end end
Version data entries
5 entries across 5 versions & 1 rubygems