activefacts 1.6.0 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +21 -0
- data/README.md +60 -0
- data/Rakefile +3 -80
- data/activefacts.gemspec +36 -0
- data/bin/afgen +4 -2
- data/bin/cql +5 -1
- data/lib/activefacts.rb +3 -12
- data/lib/activefacts/{vocabulary/query_evaluator.rb → query/evaluator.rb} +0 -0
- data/lib/activefacts/version.rb +2 -2
- metadata +48 -296
- data/History.txt +0 -4
- data/LICENSE +0 -19
- data/Manifest.txt +0 -165
- data/README.rdoc +0 -81
- data/css/offline.css +0 -3
- data/css/orm2.css +0 -124
- data/css/print.css +0 -8
- data/css/style-print.css +0 -357
- data/css/style.css +0 -387
- data/download.html +0 -110
- data/examples/CQL/Address.cql +0 -44
- data/examples/CQL/Blog.cql +0 -54
- data/examples/CQL/CompanyDirectorEmployee.cql +0 -56
- data/examples/CQL/Death.cql +0 -17
- data/examples/CQL/Diplomacy.cql +0 -48
- data/examples/CQL/Genealogy.cql +0 -98
- data/examples/CQL/Insurance.cql +0 -320
- data/examples/CQL/Marriage.cql +0 -18
- data/examples/CQL/Metamodel.cql +0 -493
- data/examples/CQL/Monogamy.cql +0 -24
- data/examples/CQL/MultiInheritance.cql +0 -22
- data/examples/CQL/NonRoleId.cql +0 -14
- data/examples/CQL/OddIdentifier.cql +0 -18
- data/examples/CQL/OilSupply.cql +0 -53
- data/examples/CQL/OneToOnes.cql +0 -17
- data/examples/CQL/Orienteering.cql +0 -111
- data/examples/CQL/PersonPlaysGame.cql +0 -18
- data/examples/CQL/RedundantDependency.cql +0 -34
- data/examples/CQL/SchoolActivities.cql +0 -33
- data/examples/CQL/SeparateSubtype.cql +0 -30
- data/examples/CQL/ServiceDirector.cql +0 -276
- data/examples/CQL/SimplestUnary.cql +0 -12
- data/examples/CQL/Supervision.cql +0 -34
- data/examples/CQL/WaiterTips.cql +0 -33
- data/examples/CQL/Warehousing.cql +0 -101
- data/examples/CQL/WindowInRoomInBldg.cql +0 -28
- data/examples/CQL/unit.cql +0 -474
- data/examples/index.html +0 -420
- data/examples/intro.html +0 -327
- data/examples/local.css +0 -24
- data/index.html +0 -111
- data/lib/activefacts/cql.rb +0 -35
- data/lib/activefacts/cql/CQLParser.treetop +0 -158
- data/lib/activefacts/cql/Context.treetop +0 -48
- data/lib/activefacts/cql/Expressions.treetop +0 -67
- data/lib/activefacts/cql/FactTypes.treetop +0 -358
- data/lib/activefacts/cql/Language/English.treetop +0 -315
- data/lib/activefacts/cql/LexicalRules.treetop +0 -253
- data/lib/activefacts/cql/ObjectTypes.treetop +0 -210
- data/lib/activefacts/cql/Rakefile +0 -14
- data/lib/activefacts/cql/Terms.treetop +0 -183
- data/lib/activefacts/cql/ValueTypes.treetop +0 -202
- data/lib/activefacts/cql/compiler.rb +0 -156
- data/lib/activefacts/cql/compiler/clause.rb +0 -1137
- data/lib/activefacts/cql/compiler/constraint.rb +0 -581
- data/lib/activefacts/cql/compiler/entity_type.rb +0 -457
- data/lib/activefacts/cql/compiler/expression.rb +0 -443
- data/lib/activefacts/cql/compiler/fact.rb +0 -390
- data/lib/activefacts/cql/compiler/fact_type.rb +0 -421
- data/lib/activefacts/cql/compiler/query.rb +0 -106
- data/lib/activefacts/cql/compiler/shared.rb +0 -161
- data/lib/activefacts/cql/compiler/value_type.rb +0 -174
- data/lib/activefacts/cql/nodes.rb +0 -49
- data/lib/activefacts/cql/parser.rb +0 -241
- data/lib/activefacts/dependency_analyser.rb +0 -182
- data/lib/activefacts/generate/absorption.rb +0 -70
- data/lib/activefacts/generate/composition.rb +0 -118
- data/lib/activefacts/generate/cql.rb +0 -714
- data/lib/activefacts/generate/dm.rb +0 -279
- data/lib/activefacts/generate/help.rb +0 -64
- data/lib/activefacts/generate/helpers/inject.rb +0 -16
- data/lib/activefacts/generate/helpers/oo.rb +0 -162
- data/lib/activefacts/generate/helpers/ordered.rb +0 -605
- data/lib/activefacts/generate/helpers/rails.rb +0 -57
- data/lib/activefacts/generate/html/glossary.rb +0 -461
- data/lib/activefacts/generate/json.rb +0 -337
- data/lib/activefacts/generate/null.rb +0 -32
- data/lib/activefacts/generate/rails/models.rb +0 -246
- data/lib/activefacts/generate/rails/schema.rb +0 -216
- data/lib/activefacts/generate/records.rb +0 -46
- data/lib/activefacts/generate/ruby.rb +0 -133
- data/lib/activefacts/generate/sql/mysql.rb +0 -280
- data/lib/activefacts/generate/sql/server.rb +0 -273
- data/lib/activefacts/generate/stats.rb +0 -69
- data/lib/activefacts/generate/text.rb +0 -27
- data/lib/activefacts/generate/topics.rb +0 -265
- data/lib/activefacts/generate/traits/datavault.rb +0 -241
- data/lib/activefacts/generate/traits/oo.rb +0 -73
- data/lib/activefacts/generate/traits/ordered.rb +0 -33
- data/lib/activefacts/generate/traits/ruby.rb +0 -210
- data/lib/activefacts/generate/transform/datavault.rb +0 -266
- data/lib/activefacts/generate/transform/surrogate.rb +0 -214
- data/lib/activefacts/generate/version.rb +0 -26
- data/lib/activefacts/input/cql.rb +0 -43
- data/lib/activefacts/input/orm.rb +0 -1636
- data/lib/activefacts/mapping/rails.rb +0 -132
- data/lib/activefacts/persistence.rb +0 -15
- data/lib/activefacts/persistence/columns.rb +0 -446
- data/lib/activefacts/persistence/foreignkey.rb +0 -187
- data/lib/activefacts/persistence/index.rb +0 -240
- data/lib/activefacts/persistence/object_type.rb +0 -198
- data/lib/activefacts/persistence/reference.rb +0 -434
- data/lib/activefacts/persistence/tables.rb +0 -380
- data/lib/activefacts/registry.rb +0 -11
- data/lib/activefacts/support.rb +0 -132
- data/lib/activefacts/vocabulary.rb +0 -9
- data/lib/activefacts/vocabulary/extensions.rb +0 -1348
- data/lib/activefacts/vocabulary/metamodel.rb +0 -570
- data/lib/activefacts/vocabulary/verbaliser.rb +0 -804
- data/script/txt2html +0 -71
- data/spec/absorption_spec.rb +0 -95
- data/spec/cql/comparison_spec.rb +0 -89
- data/spec/cql/context_spec.rb +0 -94
- data/spec/cql/contractions_spec.rb +0 -224
- data/spec/cql/deontic_spec.rb +0 -88
- data/spec/cql/entity_type_spec.rb +0 -320
- data/spec/cql/expressions_spec.rb +0 -66
- data/spec/cql/fact_type_matching_spec.rb +0 -338
- data/spec/cql/french_spec.rb +0 -21
- data/spec/cql/parser/bad_literals_spec.rb +0 -86
- data/spec/cql/parser/constraints_spec.rb +0 -19
- data/spec/cql/parser/entity_types_spec.rb +0 -106
- data/spec/cql/parser/expressions_spec.rb +0 -199
- data/spec/cql/parser/fact_types_spec.rb +0 -44
- data/spec/cql/parser/literals_spec.rb +0 -312
- data/spec/cql/parser/pragmas_spec.rb +0 -89
- data/spec/cql/parser/value_types_spec.rb +0 -42
- data/spec/cql/role_matching_spec.rb +0 -148
- data/spec/cql/samples_spec.rb +0 -244
- data/spec/cql_cql_spec.rb +0 -73
- data/spec/cql_dm_spec.rb +0 -136
- data/spec/cql_mysql_spec.rb +0 -69
- data/spec/cql_parse_spec.rb +0 -34
- data/spec/cql_ruby_spec.rb +0 -73
- data/spec/cql_sql_spec.rb +0 -72
- data/spec/cql_symbol_tables_spec.rb +0 -261
- data/spec/cqldump_spec.rb +0 -170
- data/spec/helpers/array_matcher.rb +0 -23
- data/spec/helpers/ctrl_c_support.rb +0 -52
- data/spec/helpers/diff_matcher.rb +0 -39
- data/spec/helpers/file_matcher.rb +0 -34
- data/spec/helpers/parse_to_ast_matcher.rb +0 -80
- data/spec/helpers/string_matcher.rb +0 -30
- data/spec/helpers/test_parser.rb +0 -15
- data/spec/norma_cql_spec.rb +0 -66
- data/spec/norma_ruby_spec.rb +0 -62
- data/spec/norma_ruby_sql_spec.rb +0 -107
- data/spec/norma_sql_spec.rb +0 -57
- data/spec/norma_tables_spec.rb +0 -95
- data/spec/ruby_api_spec.rb +0 -23
- data/spec/spec_helper.rb +0 -35
- data/spec/transform_surrogate_spec.rb +0 -59
- data/status.html +0 -138
- data/why.html +0 -60
data/spec/cql/deontic_spec.rb
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
# ActiveFacts CQL Deontic Constraints tests
|
|
3
|
-
# Copyright (c) 2009 Clifford Heath. Read the LICENSE file.
|
|
4
|
-
#
|
|
5
|
-
|
|
6
|
-
require 'activefacts/support'
|
|
7
|
-
require 'activefacts/api/support'
|
|
8
|
-
require 'activefacts/cql/compiler'
|
|
9
|
-
|
|
10
|
-
describe "Deontic Constraints" do
|
|
11
|
-
DeonticPrefix = %q{
|
|
12
|
-
vocabulary Test;
|
|
13
|
-
Person is written as Person;
|
|
14
|
-
Person is employed;
|
|
15
|
-
Person is unemployed;
|
|
16
|
-
Person has borrowed cash;
|
|
17
|
-
Person is a bad credit risk;
|
|
18
|
-
Nr is written as Nr;
|
|
19
|
-
Person is good credit risk;
|
|
20
|
-
Bar is written as Bar;
|
|
21
|
-
Baz is written as Baz;
|
|
22
|
-
}
|
|
23
|
-
Cases = [
|
|
24
|
-
# Constraints:
|
|
25
|
-
[ 'each Person occurs one time (otherwise alert fraud dept) in Person is employed, Person is unemployed;',
|
|
26
|
-
'alert', 'fraud dept'
|
|
27
|
-
],
|
|
28
|
-
[ 'for each Person at most one of these holds ( otherwise email auditors ) : Person has borrowed cash, Person is a bad credit risk;',
|
|
29
|
-
'email', 'auditors'
|
|
30
|
-
],
|
|
31
|
-
[ 'either Person has borrowed cash or Person is a bad credit risk ( otherwise email auditors );',
|
|
32
|
-
'email', 'auditors'
|
|
33
|
-
],
|
|
34
|
-
[ 'either Person has borrowed cash or Person is a bad credit risk but not both ( otherwise email auditors );',
|
|
35
|
-
'email', 'auditors'
|
|
36
|
-
],
|
|
37
|
-
[ 'Person is good credit risk only if Person is employed (otherwise consider foreclosure);',
|
|
38
|
-
'consider', 'foreclosure'
|
|
39
|
-
],
|
|
40
|
-
[ 'Person is good credit risk if and only if Person is employed (otherwise log event);',
|
|
41
|
-
'log', 'event'
|
|
42
|
-
],
|
|
43
|
-
[ 'Foo is written as Nr restricted to {1..10} (otherwise log);',
|
|
44
|
-
'log', ''
|
|
45
|
-
],
|
|
46
|
-
[ 'Foo is identified by its Nr restricted to {1..10} (otherwise log);',
|
|
47
|
-
'log', ''
|
|
48
|
-
],
|
|
49
|
-
[ 'Baz has at most one (otherwise notify security) Bar, Bar is of one Baz restricted to {1..10};',
|
|
50
|
-
'notify', 'security'
|
|
51
|
-
],
|
|
52
|
-
[ 'Baz has at most one Bar, Bar is of one Baz restricted to {1..10} (otherwise log exception);',
|
|
53
|
-
'log', 'exception'
|
|
54
|
-
],
|
|
55
|
-
]
|
|
56
|
-
|
|
57
|
-
before :each do
|
|
58
|
-
@compiler = ActiveFacts::CQL::Compiler.new('Test')
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
Cases.each do |c|
|
|
62
|
-
source, action, agent = *c
|
|
63
|
-
it "should parse #{source.inspect}" do
|
|
64
|
-
result = @compiler.compile(DeonticPrefix+source)
|
|
65
|
-
puts @compiler.failure_reason unless result
|
|
66
|
-
result.should_not be_nil
|
|
67
|
-
constellation = @compiler.vocabulary.constellation
|
|
68
|
-
|
|
69
|
-
enforcements =
|
|
70
|
-
constellation.Constraint.values.map do |c|
|
|
71
|
-
c.enforcement
|
|
72
|
-
end.compact
|
|
73
|
-
enforcements.size.should == 1
|
|
74
|
-
enforcements[0].enforcement_code.should == action if action
|
|
75
|
-
if agent
|
|
76
|
-
if agent != ''
|
|
77
|
-
enforcements[0].agent.agent_name.should == agent
|
|
78
|
-
else
|
|
79
|
-
enforcements[0].agent.should be_nil
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
#result.map{|d| d.value}.should == ast if ast
|
|
84
|
-
# Uncomment this to see what should replace "nil" in the cases above:
|
|
85
|
-
#puts result.map{|d| d.value}.inspect unless ast
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
end
|
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
# ActiveFacts CQL Fact Type matching tests
|
|
3
|
-
# Copyright (c) 2009 Clifford Heath. Read the LICENSE file.
|
|
4
|
-
#
|
|
5
|
-
|
|
6
|
-
require 'rspec/expectations'
|
|
7
|
-
|
|
8
|
-
require 'activefacts/support'
|
|
9
|
-
require 'activefacts/api/support'
|
|
10
|
-
require 'activefacts/cql/compiler'
|
|
11
|
-
# require File.dirname(__FILE__) + '/../helpers/compiler_helper' # Can't see how to include/extend these methods correctly
|
|
12
|
-
|
|
13
|
-
describe "When compiling an entity type, " do
|
|
14
|
-
MatchingPrefix = %q{
|
|
15
|
-
vocabulary Tests;
|
|
16
|
-
Boy is written as String;
|
|
17
|
-
Girl is written as Integer;
|
|
18
|
-
}
|
|
19
|
-
BaseObjectTypes = 4 # Integer, String, Boy, Girl
|
|
20
|
-
|
|
21
|
-
def self.SingleFact &b
|
|
22
|
-
lambda {|c|
|
|
23
|
-
real_fact_types = c.FactType.values-c.LinkFactType.values
|
|
24
|
-
real_fact_types.size.should == 1
|
|
25
|
-
@fact_type = real_fact_types[0]
|
|
26
|
-
b.call(@fact_type) if b
|
|
27
|
-
@fact_type
|
|
28
|
-
}
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def self.FactHavingPlayers(*a, &b)
|
|
32
|
-
lambda {|c|
|
|
33
|
-
@fact_type = c.FactType.detect do |key, ft|
|
|
34
|
-
ft.all_role.map{|r| r.object_type.name}.sort == a.sort
|
|
35
|
-
end
|
|
36
|
-
b.call(@fact_type) if b
|
|
37
|
-
@fact_type
|
|
38
|
-
}
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def self.PresenceConstraints fact_type, &b
|
|
42
|
-
@presence_constraints =
|
|
43
|
-
fact_type.all_role.map{|r|
|
|
44
|
-
r.all_role_ref.map{|rr|
|
|
45
|
-
rr.role_sequence.all_presence_constraint.to_a
|
|
46
|
-
}
|
|
47
|
-
}.flatten.uniq
|
|
48
|
-
b.call(@presence_constraints) if b
|
|
49
|
-
@presence_constraints
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def self.Readings fact_type, &b
|
|
53
|
-
@readings = fact_type.all_reading.sort_by{|r| r.ordinal}
|
|
54
|
-
b.call(@readings) if b
|
|
55
|
-
@readings
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def self.ReadingCount n
|
|
59
|
-
lambda {|c|
|
|
60
|
-
unless @fact_type.all_reading.size == n
|
|
61
|
-
puts "SPEC FAILED, wrong number of readings (should be #{n}):\n\t#{
|
|
62
|
-
@fact_type.all_reading.map{ |r| r.expand}*"\n\t"
|
|
63
|
-
}"
|
|
64
|
-
end
|
|
65
|
-
@fact_type.all_reading.size.should == n
|
|
66
|
-
}
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def self.PresenceConstraintCount n
|
|
70
|
-
lambda{ |c|
|
|
71
|
-
@fact_type.all_role.map{|r|
|
|
72
|
-
r.all_role_ref.map{|rr|
|
|
73
|
-
rr.role_sequence.all_presence_constraint.to_a
|
|
74
|
-
}
|
|
75
|
-
}.flatten.uniq.size.should == n
|
|
76
|
-
}
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def self.ObjectTypeCount n
|
|
80
|
-
lambda {|c|
|
|
81
|
-
@constellation = c
|
|
82
|
-
c.ObjectType.values.size.should == n
|
|
83
|
-
}
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def self.ObjectType name, &b
|
|
87
|
-
lambda {|c|
|
|
88
|
-
@object_type = c.ObjectType[[["Tests"], name]]
|
|
89
|
-
@object_type.should_not == nil
|
|
90
|
-
b.call(@object_type) if b
|
|
91
|
-
@object_type
|
|
92
|
-
}
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def self.WrittenAs name
|
|
96
|
-
lambda {|c|
|
|
97
|
-
@base_type = c.ObjectType[[["Tests"], name]]
|
|
98
|
-
@base_type.class.should == ActiveFacts::Metamodel::ValueType
|
|
99
|
-
@object_type.class.should == ActiveFacts::Metamodel::ValueType
|
|
100
|
-
@object_type.supertype.should == @base_type
|
|
101
|
-
}
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
def self.PreferredIdentifier num_roles
|
|
105
|
-
lambda {|c|
|
|
106
|
-
@preferred_identifier = @object_type.preferred_identifier
|
|
107
|
-
@preferred_identifier.should_not == nil
|
|
108
|
-
@preferred_identifier.role_sequence.all_role_ref.size.should == num_roles
|
|
109
|
-
#@preferred_identifier.min_frequency.should == 1
|
|
110
|
-
@preferred_identifier.max_frequency.should == 1
|
|
111
|
-
@preferred_identifier.is_preferred_identifier.should == true
|
|
112
|
-
}
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def self.PreferredIdentifierRolePlayedBy name, num = 0
|
|
116
|
-
lambda {|c|
|
|
117
|
-
@preferred_identifier.role_sequence.all_role_ref.sort_by{|rr| rr.ordinal}[num].role.object_type.name.should == name
|
|
118
|
-
}
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
class BlackHole
|
|
122
|
-
def method_missing(m,*a,&b)
|
|
123
|
-
self
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
class PendingSilencer
|
|
127
|
-
def STDOUT; BlackHole.new; end
|
|
128
|
-
def puts; BlackHole.new; end
|
|
129
|
-
def p; BlackHole.new; end
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
def self.pending(msg = "TODO", &b)
|
|
133
|
-
lambda {|*c|
|
|
134
|
-
raised = nil
|
|
135
|
-
begin
|
|
136
|
-
example = b.call
|
|
137
|
-
eval(lambda { example.call(*c) }, BlackHole.new)
|
|
138
|
-
rescue => raised
|
|
139
|
-
end
|
|
140
|
-
raise RSpec::Core::Pending::PendingExampleFixedError.new(msg) unless raised
|
|
141
|
-
throw :pending_declared_in_example, msg
|
|
142
|
-
}
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
def self.ReadingContainsHyphenatedWord reading_num
|
|
146
|
-
lambda {|c|
|
|
147
|
-
hyphenated_reading =
|
|
148
|
-
c.FactType.values[0].all_reading.select {|reading|
|
|
149
|
-
reading.ordinal == reading_num
|
|
150
|
-
}[0]
|
|
151
|
-
hyphenated_reading.should_not == nil
|
|
152
|
-
(hyphenated_reading.text =~ /[a-z]-[a-z]/).should_not == nil
|
|
153
|
-
}
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
EntityIdentificationTests = [
|
|
157
|
-
[
|
|
158
|
-
# REVISIT: At present, this doesn't add the minimum frequency constraint that a preferred identifier requires.
|
|
159
|
-
%q{Thong is written as String;},
|
|
160
|
-
%q{Thing is identified by Thong where Thing has one Thong;},
|
|
161
|
-
SingleFact() do |fact_type|
|
|
162
|
-
Readings(fact_type).size.should == 1
|
|
163
|
-
PresenceConstraints(fact_type).size.should == 2
|
|
164
|
-
end,
|
|
165
|
-
ObjectType('Thong') do |object_type|
|
|
166
|
-
object_type.class.should == ActiveFacts::Metamodel::ValueType
|
|
167
|
-
# REVISIT: Figure out how WrittenAs can access the constellation.
|
|
168
|
-
WrittenAs('String')
|
|
169
|
-
end,
|
|
170
|
-
ObjectTypeCount(2+BaseObjectTypes),
|
|
171
|
-
ObjectType('Thing'),
|
|
172
|
-
PreferredIdentifier(1),
|
|
173
|
-
PreferredIdentifierRolePlayedBy('Thong'),
|
|
174
|
-
],
|
|
175
|
-
|
|
176
|
-
[ # Auto-create Id and Thing Id:
|
|
177
|
-
%q{Thing is identified by its Id;},
|
|
178
|
-
SingleFact() do |fact_type|
|
|
179
|
-
Readings(fact_type).size.should == 2
|
|
180
|
-
PresenceConstraints(fact_type).size.should == 2
|
|
181
|
-
end,
|
|
182
|
-
ObjectTypeCount(3+BaseObjectTypes),
|
|
183
|
-
ObjectType('Thing'),
|
|
184
|
-
PreferredIdentifier(1),
|
|
185
|
-
PreferredIdentifierRolePlayedBy('Thing Id'),
|
|
186
|
-
],
|
|
187
|
-
|
|
188
|
-
[ # Auto-create Thing Id:
|
|
189
|
-
%q{Id is written as String;},
|
|
190
|
-
%q{Thing is identified by its Id;},
|
|
191
|
-
SingleFact() do |fact_type|
|
|
192
|
-
Readings(fact_type).size.should == 2
|
|
193
|
-
PresenceConstraints(fact_type).size.should == 2
|
|
194
|
-
end,
|
|
195
|
-
ObjectTypeCount(3+BaseObjectTypes),
|
|
196
|
-
ObjectType('Thing'),
|
|
197
|
-
PreferredIdentifier(1),
|
|
198
|
-
PreferredIdentifierRolePlayedBy('Thing Id'),
|
|
199
|
-
],
|
|
200
|
-
|
|
201
|
-
[ # Auto-create nothing (identifying value type exists already)
|
|
202
|
-
%q{Thing Id is written as String;},
|
|
203
|
-
%q{Thing is identified by its Id;},
|
|
204
|
-
SingleFact() do |fact_type|
|
|
205
|
-
Readings(fact_type).size.should == 2
|
|
206
|
-
PresenceConstraints(fact_type).size.should == 2
|
|
207
|
-
end,
|
|
208
|
-
ObjectTypeCount(2+BaseObjectTypes),
|
|
209
|
-
ObjectType('Thing'),
|
|
210
|
-
PreferredIdentifier(1),
|
|
211
|
-
PreferredIdentifierRolePlayedBy('Thing Id'),
|
|
212
|
-
],
|
|
213
|
-
|
|
214
|
-
[ # Auto-create nothing (identifying entity type exists already so don't create a VT)
|
|
215
|
-
%q{Id is written as Id;},
|
|
216
|
-
%q{Thing Id is identified by Id where Thing Id has one Id, Id is of one Thing Id;},
|
|
217
|
-
%q{Thing is identified by its Id;},
|
|
218
|
-
FactHavingPlayers("Thing", "Thing Id") do |fact_type|
|
|
219
|
-
Readings(fact_type).size.should == 2
|
|
220
|
-
PresenceConstraints(fact_type).size.should == 2
|
|
221
|
-
end,
|
|
222
|
-
ObjectTypeCount(3+BaseObjectTypes),
|
|
223
|
-
ObjectType('Thing'),
|
|
224
|
-
PreferredIdentifier(1),
|
|
225
|
-
PreferredIdentifierRolePlayedBy('Thing Id'),
|
|
226
|
-
],
|
|
227
|
-
|
|
228
|
-
[
|
|
229
|
-
%q{Thong is written as String;},
|
|
230
|
-
%q{Thing is identified by Thong where Thing has one Thong, Thong is of one Thing;},
|
|
231
|
-
SingleFact() do |fact_type|
|
|
232
|
-
Readings(fact_type).size.should == 2
|
|
233
|
-
PresenceConstraints(fact_type).size.should == 2
|
|
234
|
-
end,
|
|
235
|
-
ObjectTypeCount(2+BaseObjectTypes),
|
|
236
|
-
ObjectType('Thing'),
|
|
237
|
-
PreferredIdentifier(1),
|
|
238
|
-
PreferredIdentifierRolePlayedBy('Thong'),
|
|
239
|
-
],
|
|
240
|
-
|
|
241
|
-
[ # Objectified fact type with internal identification
|
|
242
|
-
%q{Relationship is where Boy relates to Girl;},
|
|
243
|
-
SingleFact() do |fact_type|
|
|
244
|
-
Readings(fact_type).size.should == 1
|
|
245
|
-
PresenceConstraints(fact_type).size.should == 1
|
|
246
|
-
end,
|
|
247
|
-
ObjectTypeCount(1+BaseObjectTypes),
|
|
248
|
-
ObjectType('Relationship'),
|
|
249
|
-
PreferredIdentifier(2),
|
|
250
|
-
# PreferredIdentifierRolePlayedBy('Thong'),
|
|
251
|
-
],
|
|
252
|
-
|
|
253
|
-
[ # Objectified fact type with external identification
|
|
254
|
-
%q{Relationship is identified by its Id where Boy relates to Girl;},
|
|
255
|
-
ObjectTypeCount(3+BaseObjectTypes),
|
|
256
|
-
ObjectType('Relationship'),
|
|
257
|
-
PreferredIdentifier(1), # 1 role in PI
|
|
258
|
-
PreferredIdentifierRolePlayedBy('Relationship Id'),
|
|
259
|
-
FactHavingPlayers('Relationship', 'Relationship Id') do |fact_type|
|
|
260
|
-
Readings(fact_type).size.should == 2
|
|
261
|
-
PresenceConstraints(fact_type).size.should == 2
|
|
262
|
-
fact_type.all_reading.detect{|r| r.text == '{0} has {1}'}.should_not == nil
|
|
263
|
-
fact_type.all_reading.detect{|r| r.text == '{0} is of {1}'}.should_not == nil
|
|
264
|
-
end,
|
|
265
|
-
FactHavingPlayers('Boy', 'Girl') do |fact_type|
|
|
266
|
-
fact_type.entity_type.should == @object_type
|
|
267
|
-
end,
|
|
268
|
-
],
|
|
269
|
-
|
|
270
|
-
[ # Objectified fact type with external identification and explicit reading
|
|
271
|
-
%q{Relationship is identified by its Id where Boy relates to Girl, Relationship is known by Relationship Id;},
|
|
272
|
-
ObjectTypeCount(3+BaseObjectTypes),
|
|
273
|
-
ObjectType('Relationship'),
|
|
274
|
-
PreferredIdentifier(1),
|
|
275
|
-
PreferredIdentifierRolePlayedBy('Relationship Id'),
|
|
276
|
-
FactHavingPlayers('Relationship', 'Relationship Id') do |fact_type|
|
|
277
|
-
Readings(fact_type).size.should == 2
|
|
278
|
-
PresenceConstraints(fact_type).size.should == 2
|
|
279
|
-
fact_type.all_reading.detect{|r| r.text == '{0} is known by {1}'}.should_not == nil
|
|
280
|
-
fact_type.all_reading.detect{|r| r.text == '{0} is of {1}'}.should_not == nil
|
|
281
|
-
end,
|
|
282
|
-
FactHavingPlayers('Boy', 'Girl') do |fact_type|
|
|
283
|
-
fact_type.entity_type.should == @object_type
|
|
284
|
-
end,
|
|
285
|
-
],
|
|
286
|
-
|
|
287
|
-
]
|
|
288
|
-
|
|
289
|
-
AllTests =
|
|
290
|
-
EntityIdentificationTests
|
|
291
|
-
|
|
292
|
-
before :each do
|
|
293
|
-
@compiler = ActiveFacts::CQL::Compiler.new('Test')
|
|
294
|
-
end
|
|
295
|
-
|
|
296
|
-
AllTests.each do |tests|
|
|
297
|
-
it "should process '#{(tests.select{|t| t.is_a?(String)}*' ').gsub(/\s+/m,' ')}' correctly" do
|
|
298
|
-
tests.each do |test|
|
|
299
|
-
case test
|
|
300
|
-
when String
|
|
301
|
-
result = @compiler.compile(MatchingPrefix+test)
|
|
302
|
-
puts @compiler.failure_reason unless result
|
|
303
|
-
result.should_not be_nil
|
|
304
|
-
@compiler.vocabulary.finalise
|
|
305
|
-
when Proc
|
|
306
|
-
begin
|
|
307
|
-
test.call(@compiler.vocabulary.constellation)
|
|
308
|
-
rescue RSpec::Expectations::ExpectationNotMetError
|
|
309
|
-
raise
|
|
310
|
-
rescue RSpec::Core::Pending::PendingDeclaredInExample
|
|
311
|
-
raise
|
|
312
|
-
rescue => e
|
|
313
|
-
puts "Failed on\n\t"+tests.select{|t| t.is_a?(String)}*" "
|
|
314
|
-
raise
|
|
315
|
-
end
|
|
316
|
-
end
|
|
317
|
-
end
|
|
318
|
-
end
|
|
319
|
-
end
|
|
320
|
-
end
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
# ActiveFacts CQL Expressions
|
|
3
|
-
# Copyright (c) 2009 Clifford Heath. Read the LICENSE file.
|
|
4
|
-
#
|
|
5
|
-
|
|
6
|
-
require 'rspec/expectations'
|
|
7
|
-
|
|
8
|
-
require 'activefacts/support'
|
|
9
|
-
require 'activefacts/api/support'
|
|
10
|
-
require 'activefacts/cql/compiler'
|
|
11
|
-
require File.dirname(__FILE__) + '/../helpers/compile_helpers'
|
|
12
|
-
|
|
13
|
-
describe "When compiling expressions" do
|
|
14
|
-
before :each do
|
|
15
|
-
extend CompileHelpers
|
|
16
|
-
|
|
17
|
-
prefix = %q{
|
|
18
|
-
vocabulary Tests;
|
|
19
|
-
Name is written as String;
|
|
20
|
-
year/years converts to 365.25 day;
|
|
21
|
-
Age is written as Integer year;
|
|
22
|
-
Person is identified by its Name;
|
|
23
|
-
Person is of Age;
|
|
24
|
-
|
|
25
|
-
// Company is identified by its Name;
|
|
26
|
-
// Directorship is where Person directs Company;
|
|
27
|
-
}
|
|
28
|
-
@compiler = ActiveFacts::CQL::Compiler.new('Test')
|
|
29
|
-
@compiler.compile(prefix)
|
|
30
|
-
@constellation = @compiler.vocabulary.constellation
|
|
31
|
-
|
|
32
|
-
baseline
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
describe "expressions" do
|
|
36
|
-
|
|
37
|
-
it "should create appropriate fact types" do
|
|
38
|
-
compile %q{Person is of Age >= 3*(9+11)? }
|
|
39
|
-
|
|
40
|
-
new_fact_types = fact_types
|
|
41
|
-
# new_fact_types.each { |ft| puts "new fact type: #{ft.default_reading}" }
|
|
42
|
-
new_fact_types.size.should == 3
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it "should create derived fact types and project the roles" do
|
|
46
|
-
compile %q{Person is old where Person is of Age >= 3*(9+11); }
|
|
47
|
-
|
|
48
|
-
new_fact_types = fact_types
|
|
49
|
-
# new_fact_types.each { |ft| puts "new fact type: #{ft.default_reading}" }
|
|
50
|
-
new_fact_types.size.should == 4
|
|
51
|
-
|
|
52
|
-
is_old_ft = new_fact_types.detect{|ft| ft.all_reading.detect{|r| r.text =~ /is old/} }
|
|
53
|
-
(is_old_ft.all_reading.map{ |r| r.expand }*', ').should == "Person is old"
|
|
54
|
-
|
|
55
|
-
new_readings = new_fact_types.
|
|
56
|
-
reject{|ft| ft == is_old_ft}.
|
|
57
|
-
map{|ft| ft.all_reading.map{|r| r.expand}*", "}
|
|
58
|
-
|
|
59
|
-
new_readings.should include("Boolean = Age >= PRODUCT_OF<Integer SUM_OF<Integer, Integer>>")
|
|
60
|
-
new_readings.should include("PRODUCT_OF<Integer SUM_OF<Integer, Integer>> = Integer * SUM_OF<Integer, Integer>")
|
|
61
|
-
new_readings.should include("SUM_OF<Integer, Integer> = Integer + Integer")
|
|
62
|
-
|
|
63
|
-
# one_query_with_value 60, 'year'
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
end
|