Sha256: 5cddd8ee5772c13ce67c5373577d6602239dc2b33d6b249d2a09875008cd15a1
Contents?: true
Size: 1.78 KB
Versions: 2
Compression:
Stored size: 1.78 KB
Contents
require 'spec_helper' module Finitio describe Syntax, "constraints" do subject{ Syntax.parse(input, root: "constraints") } let(:compiled){ subject.compile("a") } let(:ast){ subject.to_ast('a') } context 'a >= 10' do let(:input){ 'a >= 10' } it 'compiles to an Hash' do compiled.should be_a(Hash) compiled.keys.should eq([:predicate]) end it 'has the expected AST' do ast.should eq([ :constraint, "default", [:fn, [:parameters, "a"], [:source, "a >= 10"]] ]) end end context 'foo: a >= 10' do let(:input){ 'foo: a >= 10' } it 'compiles to an Hash' do compiled.should be_a(Hash) compiled.keys.should eq([:foo]) end it 'has the expected AST' do ast.should eq([[ :constraint, "foo", [:fn, [:parameters, "a"], [:source, "a >= 10"]] ]]) end end context 'foo: a >= 10, bar: a <= 255' do let(:input){ 'foo: a >= 10, bar: a <= 255' } it 'compiles to an Hash' do compiled.should be_a(Hash) compiled.keys.should eq([:foo, :bar]) end it 'has the expected AST' do ast.should eq([ [ :constraint, "foo", [:fn, [:parameters, "a"], [:source, "a >= 10"]] ], [ :constraint, "bar", [:fn, [:parameters, "a"], [:source, "a <= 255"]] ] ]) end end context 'foo: a >= 10, foo: a <= 255' do let(:input){ 'foo: a >= 10, foo: a <= 255' } it 'compiles to an Hash' do ->{ compiled }.should raise_error("Duplicate constraint name `foo`") end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
finitio-0.4.1 | spec/unit/syntax/nodes/test_constraints.rb |
finitio-0.4.0 | spec/unit/syntax/nodes/test_constraints.rb |