Sha256: 9f4ad493f1387dc2ae683e27a457338c1163142e474a8b293c0b802bad4bb2bd

Contents?: true

Size: 788 Bytes

Versions: 1

Compression:

Stored size: 788 Bytes

Contents

require 'spec_helper'
module Qrb
  describe Syntax, "constraint_def" do

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

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

    let(:ast){
      subject.to_ast
    }

    context '(i | i >= 0)' do
      let(:input){ '(i | i >= 0)' }

      it 'compiles to an Hash' do
        compiled.should be_a(Hash)
      end

      it 'compiled to the correct proc' do
        compiled[:predicate].call(12).should be_true
        compiled[:predicate].call(-12).should be_false
      end

      it 'has the expected AST' do
        ast.should eq([
          [
            :constraint,
            "default",
            [:fn, [:parameters, "i"], [:source, "i >= 0"]]
          ]
        ])
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
qrb-0.3.0 spec/unit/syntax/nodes/test_constraint_def.rb