Sha256: 1b19f48d6b84c58ab946f221e5fcb861d1e971b2c33bafd1c383759b5b14237d

Contents?: true

Size: 1.82 KB

Versions: 1

Compression:

Stored size: 1.82 KB

Contents

#
# ActiveFacts CQL Join Expressions
# Copyright (c) 2009 Clifford Heath. Read the LICENSE file.
#

require 'rspec/expectations'

require 'activefacts/support'
require 'activefacts/api/support'
require 'activefacts/cql/compiler'
require 'spec/helpers/compile_helpers'

require 'ruby-debug'; Debugger.start

describe "When compiling expressions" do
  before :each do
    extend CompileHelpers

    prefix = %q{
      vocabulary Tests;
      Name is written as String;
      year/years converts to 365.25 day;
      Age is written as Integer year;
      Person is identified by its Name;
      Person is of Age;

      // Company is identified by its Name;
      // Directorship is where Person directs Company;
    }
    @compiler = ActiveFacts::CQL::Compiler.new('Test')
    @compiler.compile(prefix)
    @constellation = @compiler.vocabulary.constellation

    baseline
  end

  describe "expressions" do

    it "should create appropriate fact types" do
      compile %q{Person is of Age >= 3*(9+11)? }

      new_fact_types = fact_types
      # new_fact_types.each { |ft| puts "new fact type: #{ft.default_reading}" }
      new_fact_types.size.should == 3
  end

  it "should create derived fact type and project the roles" do
      compile %q{Person is old where Person is of Age >= 3*(9+11); }

      new_fact_types = fact_types
      # new_fact_types.each { |ft| puts "new fact type: #{ft.default_reading}" }
      new_fact_types.size.should == 4

      is_old_ft = new_fact_types.detect{|ft| ft.all_reading.detect{|r| r.text =~ /is old/} }
      (is_old_ft.all_reading.map{ |r| r.expand }*', ').should == "Person is old"

      comparison_ft = (new_fact_types - [is_old_ft])[0]
      (comparison_ft.all_reading.map{ |r| r.expand }*', ').should == "Age >= product(Integer, sum(Integer, Integer))"

      # one_join_with_value 60, 'year'
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activefacts-0.8.10 spec/cql/expressions_spec.rb