activefacts 1.6.0 → 1.7.1
Sign up to get free protection for your applications and to get access to all the features.
- 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_cql_spec.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# ActiveFacts tests: Parse all CQL files and check the generated CQL.
|
3
|
-
# Copyright (c) 2008 Clifford Heath. Read the LICENSE file.
|
4
|
-
#
|
5
|
-
|
6
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
7
|
-
require 'stringio'
|
8
|
-
require 'activefacts/vocabulary'
|
9
|
-
require 'activefacts/support'
|
10
|
-
require 'activefacts/input/cql'
|
11
|
-
require 'activefacts/generate/cql'
|
12
|
-
|
13
|
-
describe "CQL Loader" do
|
14
|
-
cql_failures = {
|
15
|
-
"Airline" => "Contains queries, unsupported",
|
16
|
-
"CompanyQuery" => "Contains queries, unsupported",
|
17
|
-
#"MetamodelNext" => "Fails due to weak adjective/role matching",
|
18
|
-
#"ServiceDirector" => "Doesn't parse some constraints due to mis-matched adjectives",
|
19
|
-
#"OddIdentifier" => "The odd identifier is built correctly but cannot be found by the current implementation",
|
20
|
-
"units" => "Unit verbalisation into CQL is not implemented"
|
21
|
-
}
|
22
|
-
cql_cql_failures = {
|
23
|
-
# "Insurance" => "Misses a query in a subset constraint",
|
24
|
-
# "OddIdentifier" => "Doesn't support identification of object fact types using mixed external/internal roles",
|
25
|
-
}
|
26
|
-
# Generate and return the CQL for the given vocabulary
|
27
|
-
def cql(vocabulary)
|
28
|
-
output = StringIO.new
|
29
|
-
@dumper = ActiveFacts::Generate::CQL.new(vocabulary.constellation)
|
30
|
-
@dumper.generate(output)
|
31
|
-
output.rewind
|
32
|
-
output.read
|
33
|
-
end
|
34
|
-
|
35
|
-
pattern = ENV["AFTESTS"] || "*"
|
36
|
-
Dir["examples/CQL/#{pattern}.cql"].each do |cql_file|
|
37
|
-
actual_file = cql_file.sub(%r{examples/CQL/}, 'spec/actual/')
|
38
|
-
|
39
|
-
it "should load CQL and dump valid CQL for #{cql_file}" do
|
40
|
-
broken = cql_failures[File.basename(actual_file, ".cql")]
|
41
|
-
vocabulary = nil
|
42
|
-
if broken
|
43
|
-
pending(broken) {
|
44
|
-
vocabulary = ActiveFacts::Input::CQL.readfile(cql_file)
|
45
|
-
}
|
46
|
-
else
|
47
|
-
begin
|
48
|
-
vocabulary = ActiveFacts::Input::CQL.readfile(cql_file)
|
49
|
-
rescue => e
|
50
|
-
trace :exception, "#{e.message}\n" +
|
51
|
-
"\t#{e.backtrace*"\n\t"}"
|
52
|
-
raise
|
53
|
-
end
|
54
|
-
end
|
55
|
-
vocabulary.finalise
|
56
|
-
|
57
|
-
# Build and save the actual file:
|
58
|
-
cql_text = cql(vocabulary)
|
59
|
-
File.open(actual_file, "w") { |f| f.write cql_text }
|
60
|
-
expected_text = File.open(cql_file) {|f| f.read }
|
61
|
-
|
62
|
-
broken = cql_cql_failures[File.basename(actual_file, ".cql")]
|
63
|
-
if broken
|
64
|
-
pending(broken) {
|
65
|
-
cql_text.should_not differ_from(expected_text)
|
66
|
-
}
|
67
|
-
else
|
68
|
-
cql_text.should_not differ_from(expected_text)
|
69
|
-
File.delete(actual_file) # It succeeded, we don't need the file.
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
data/spec/cql_dm_spec.rb
DELETED
@@ -1,136 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# ActiveFacts tests: Parse all CQL files and check the generated DataMapper models
|
3
|
-
# Copyright (c) 2008 Clifford Heath. Read the LICENSE file.
|
4
|
-
#
|
5
|
-
# From IRC, on how to extract the SQL that DM creates for a set of models:
|
6
|
-
#
|
7
|
-
# I can tell you that ::DataObjects::Connection#log gets you the SQL
|
8
|
-
# after its run (not exactly what you asked for, but a place to start
|
9
|
-
# looking).
|
10
|
-
#
|
11
|
-
# your choices are intercepting
|
12
|
-
# ::DataMapper::Adapters::DataObjectsAdapter#{select,execute} for
|
13
|
-
# direct SQL calls, or at a lower level,
|
14
|
-
# ::DataObjects::Connection#create_command for all SQL.
|
15
|
-
#
|
16
|
-
# one trick I've been using is to selectively intercept the latter
|
17
|
-
# and not let it run (no-op it but log/inspect it), which can obviously
|
18
|
-
# screw up anything else back up the call stack but at least gives
|
19
|
-
# you the opportunity to catch it if you want.
|
20
|
-
#
|
21
|
-
# #create_command returns Command, which is subsequently called with
|
22
|
-
# #execute_reader(bind_values) or #execute_non_query(bind_values),
|
23
|
-
# so if the final query is what you're after, then you'll have to
|
24
|
-
# hook those both instead.
|
25
|
-
|
26
|
-
if false
|
27
|
-
|
28
|
-
require 'spec_helper'
|
29
|
-
require 'stringio'
|
30
|
-
require 'activefacts/vocabulary'
|
31
|
-
require 'activefacts/support'
|
32
|
-
require 'activefacts/input/cql'
|
33
|
-
require 'activefacts/generate/dm'
|
34
|
-
require 'dm-core'
|
35
|
-
require 'dm-core/spec/lib/spec_helper'
|
36
|
-
|
37
|
-
#def SecureRandom.uuid
|
38
|
-
# @@counter ||= 99999999999
|
39
|
-
# h = "%032X" % @@counter
|
40
|
-
# @@counter -= 1
|
41
|
-
# h.
|
42
|
-
# sub(
|
43
|
-
# @@format_pattern ||= /(........)(....)(....)(....)(............)/,
|
44
|
-
# @@format_string ||= '\1-\2-\3-\4-\5'
|
45
|
-
# )
|
46
|
-
#end
|
47
|
-
|
48
|
-
describe "CQL Loader with DataMapper output" do
|
49
|
-
cql_failures = { # These CQL files can't be compiled
|
50
|
-
}
|
51
|
-
mapping_failures = { # These models can't be mapped to DM
|
52
|
-
'OrienteeringER' => 'Invalid CQL results in unmappable model',
|
53
|
-
'Insurance' => 'Cannot handle models that contain classes like Vehicle Incident with external supertypes (Incident)',
|
54
|
-
'MultiInheritance' => 'Cannot handle models that contain classes like Australian Employee with external supertypes (Australian)',
|
55
|
-
'Metamodel' => 'cannot be used as a property name since it collides with an existing method',
|
56
|
-
'MetamodelNext' => 'Cannot map classes like Constraint with roles inherited from external supertypes (Concept)',
|
57
|
-
'SeparateSubtype' => 'Cannot handle models that contain classes like Vehicle Incident with external supertypes (Incident)',
|
58
|
-
'ServiceDirector' => 'Cannot handle models that contain classes like Client with external supertypes (Company)',
|
59
|
-
}
|
60
|
-
dm_failures = { # These mapped models don't work in DM
|
61
|
-
'RedundantDependency' => 'Cannot find the child_model Addres for StateOrProvince in address while finalizing StateOrProvince.address',
|
62
|
-
'Supervision' => 'Inflexion failure: Cannot find the parent_model Ceo for Company in ceo while finalizing Company.ceo',
|
63
|
-
}
|
64
|
-
|
65
|
-
# Generate and return the DataMapper models for the given vocabulary
|
66
|
-
def dm(vocabulary)
|
67
|
-
output = StringIO.new
|
68
|
-
@dumper = ActiveFacts::Generate::DM.new(vocabulary.constellation)
|
69
|
-
@dumper.generate(output)
|
70
|
-
output.rewind
|
71
|
-
output.read
|
72
|
-
end
|
73
|
-
|
74
|
-
pattern = ENV["AFTESTS"] || "*"
|
75
|
-
Dir["examples/CQL/#{pattern}.cql"].each do |cql_file|
|
76
|
-
expected_file = cql_file.sub(%r{/CQL/(.*).cql\Z}, '/datamapper/\1.dm.rb')
|
77
|
-
actual_file = cql_file.sub(%r{examples/CQL/(.*).cql\Z}, 'spec/actual/\1.dm.rb')
|
78
|
-
base = File.basename(cql_file, ".cql")
|
79
|
-
|
80
|
-
next unless ENV["AFTESTS"] || File.exists?(expected_file)
|
81
|
-
|
82
|
-
it "should load #{cql_file} and dump DataMapper models matching #{expected_file}" do
|
83
|
-
vocabulary = nil
|
84
|
-
broken = cql_failures[base]
|
85
|
-
if broken
|
86
|
-
pending(broken) {
|
87
|
-
vocabulary = ActiveFacts::Input::CQL.readfile(cql_file)
|
88
|
-
}
|
89
|
-
else
|
90
|
-
vocabulary = ActiveFacts::Input::CQL.readfile(cql_file)
|
91
|
-
end
|
92
|
-
vocabulary.finalise
|
93
|
-
|
94
|
-
# Build and save the actual file:
|
95
|
-
dm_text = ''
|
96
|
-
lambda do
|
97
|
-
begin
|
98
|
-
dm_text = dm(vocabulary)
|
99
|
-
Dir.mkdir "spec/actual" rescue nil
|
100
|
-
File.open(actual_file, "w") { |f| f.write dm_text }
|
101
|
-
rescue
|
102
|
-
raise unless mapping_failures[base]
|
103
|
-
end
|
104
|
-
end.should_not raise_error
|
105
|
-
|
106
|
-
if m = mapping_failures[base]
|
107
|
-
File.delete(actual_file) rescue nil
|
108
|
-
pending m
|
109
|
-
end
|
110
|
-
|
111
|
-
lambda do
|
112
|
-
begin
|
113
|
-
eval dm_text
|
114
|
-
DataMapper.finalize
|
115
|
-
rescue
|
116
|
-
raise unless dm_failures[base]
|
117
|
-
ensure
|
118
|
-
DataMapper::Spec.cleanup_models
|
119
|
-
end
|
120
|
-
end.should_not raise_error
|
121
|
-
if m = dm_failures[base]
|
122
|
-
File.delete(actual_file) rescue nil
|
123
|
-
pending m
|
124
|
-
end
|
125
|
-
|
126
|
-
pending("expected output file #{expected_file} not found") unless File.exists? expected_file
|
127
|
-
|
128
|
-
# Compare with the expected file:
|
129
|
-
expected_text = File.open(expected_file) {|f| f.read }
|
130
|
-
dm_text.should_not differ_from(expected_text)
|
131
|
-
File.delete(actual_file) # It succeeded, we don't need the file.
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
end # if false
|
data/spec/cql_mysql_spec.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# ActiveFacts tests: Parse all CQL files and check the generated SQL.
|
3
|
-
# Copyright (c) 2008 Clifford Heath. Read the LICENSE file.
|
4
|
-
#
|
5
|
-
|
6
|
-
require 'spec_helper'
|
7
|
-
require 'stringio'
|
8
|
-
require 'activefacts/vocabulary'
|
9
|
-
require 'activefacts/support'
|
10
|
-
require 'activefacts/input/cql'
|
11
|
-
require 'activefacts/generate/sql/mysql'
|
12
|
-
|
13
|
-
describe "CQL Loader with SQL output" do
|
14
|
-
cql_failures = {
|
15
|
-
"Airline" => "Contains queries, unsupported",
|
16
|
-
"CompanyQuery" => "Contains queries, unsupported",
|
17
|
-
}
|
18
|
-
cql_mysql_failures = {
|
19
|
-
"Metamodel" => "An index to enforce uniqueness on the nesting fact type isn't emitted",
|
20
|
-
}
|
21
|
-
|
22
|
-
# Generate and return the SQL for the given vocabulary
|
23
|
-
def sql(vocabulary)
|
24
|
-
output = StringIO.new
|
25
|
-
@dumper = ActiveFacts::Generate::SQL::MYSQL.new(vocabulary.constellation)
|
26
|
-
@dumper.generate(output)
|
27
|
-
output.rewind
|
28
|
-
output.read
|
29
|
-
end
|
30
|
-
|
31
|
-
pattern = ENV["AFTESTS"] || "*"
|
32
|
-
Dir["examples/CQL/#{pattern}.cql"].each do |cql_file|
|
33
|
-
actual_file = cql_file.sub(%r{examples/CQL/(.*).cql}, 'spec/actual/\1.my.sql')
|
34
|
-
expected_file = cql_file.sub(%r{examples/CQL/(.*).cql\Z}, 'examples/MySQL/\1.my.sql')
|
35
|
-
|
36
|
-
next unless ENV["AFTESTS"] || File.exists?(expected_file)
|
37
|
-
|
38
|
-
it "should load #{cql_file} and dump MySQL matching #{expected_file}" do
|
39
|
-
broken = cql_failures[File.basename(cql_file, ".cql")]
|
40
|
-
vocabulary = nil
|
41
|
-
if broken
|
42
|
-
pending(broken) {
|
43
|
-
lambda { vocabulary = ActiveFacts::Input::CQL.readfile(cql_file) }.should_not raise_error
|
44
|
-
}
|
45
|
-
else
|
46
|
-
lambda { vocabulary = ActiveFacts::Input::CQL.readfile(cql_file) }.should_not raise_error
|
47
|
-
end
|
48
|
-
vocabulary.finalise
|
49
|
-
|
50
|
-
# Build and save the actual file:
|
51
|
-
sql_text = sql(vocabulary)
|
52
|
-
Dir.mkdir "spec/actual" rescue nil
|
53
|
-
File.open(actual_file, "w") { |f| f.write sql_text }
|
54
|
-
|
55
|
-
pending("expected output file #{expected_file} not found") unless File.exists? expected_file
|
56
|
-
|
57
|
-
expected_text = File.open(expected_file) {|f| f.read }
|
58
|
-
broken = cql_mysql_failures[File.basename(actual_file, ".cql")]
|
59
|
-
if broken
|
60
|
-
pending(broken) {
|
61
|
-
sql_text.should_not differ_from(expected_text)
|
62
|
-
}
|
63
|
-
else
|
64
|
-
sql_text.should_not differ_from(expected_text)
|
65
|
-
File.delete(actual_file) # It succeeded, we don't need the file.
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
data/spec/cql_parse_spec.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# ActiveFacts tests: Parse all NORMA files and check the generated CQL.
|
3
|
-
# Copyright (c) 2008 Clifford Heath. Read the LICENSE file.
|
4
|
-
#
|
5
|
-
|
6
|
-
require 'stringio'
|
7
|
-
require 'activefacts/vocabulary'
|
8
|
-
require 'activefacts/support'
|
9
|
-
require 'activefacts/input/cql'
|
10
|
-
require 'activefacts/generate/cql'
|
11
|
-
|
12
|
-
describe "CQL Parser" do
|
13
|
-
cql_failures = {
|
14
|
-
"Airline" => "Contains queries, unsupported",
|
15
|
-
"CompanyQuery" => "Contains queries, unsupported",
|
16
|
-
}
|
17
|
-
|
18
|
-
pattern = ENV["AFTESTS"] || "*"
|
19
|
-
Dir["examples/CQL/#{pattern}.cql"].each do |cql_file|
|
20
|
-
it "should load CQL #{cql_file} without parse errors" do
|
21
|
-
broken = cql_failures[File.basename(cql_file, ".cql")]
|
22
|
-
|
23
|
-
vocabulary = nil
|
24
|
-
if broken
|
25
|
-
pending(broken) {
|
26
|
-
lambda { vocabulary = ActiveFacts::Input::CQL.readfile(cql_file) }.should_not raise_error
|
27
|
-
}
|
28
|
-
else
|
29
|
-
lambda { vocabulary = ActiveFacts::Input::CQL.readfile(cql_file) }.should_not raise_error
|
30
|
-
end
|
31
|
-
vocabulary.finalise
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
data/spec/cql_ruby_spec.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# ActiveFacts tests: Parse all CQL files and check the generated Ruby.
|
3
|
-
# Copyright (c) 2008 Clifford Heath. Read the LICENSE file.
|
4
|
-
#
|
5
|
-
|
6
|
-
require 'spec_helper'
|
7
|
-
require 'stringio'
|
8
|
-
require 'activefacts/vocabulary'
|
9
|
-
require 'activefacts/support'
|
10
|
-
require 'activefacts/input/cql'
|
11
|
-
require 'activefacts/generate/ruby'
|
12
|
-
|
13
|
-
class String
|
14
|
-
def strip_comments()
|
15
|
-
c_comment = %r{/\*((?!\*/).)*\*/}m
|
16
|
-
gsub(c_comment, '').gsub(%r{\n\n+},"\n")
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "CQL Loader with Ruby output" do
|
21
|
-
cql_failures = {
|
22
|
-
"Airline" => "Contains queries, not supported",
|
23
|
-
"CompanyQuery" => "Contains queries, not supported",
|
24
|
-
# "OrienteeringER" => "Invalid model, it just works differently in CQL"
|
25
|
-
}
|
26
|
-
|
27
|
-
# Generate and return the Ruby for the given vocabulary
|
28
|
-
def ruby(vocabulary)
|
29
|
-
output = StringIO.new
|
30
|
-
@dumper = ActiveFacts::Generate::RUBY.new(vocabulary.constellation)
|
31
|
-
@dumper.generate(output)
|
32
|
-
output.rewind
|
33
|
-
output.read
|
34
|
-
end
|
35
|
-
|
36
|
-
pattern = ENV["AFTESTS"] || "*"
|
37
|
-
Dir["examples/CQL/#{pattern}.cql"].each do |cql_file|
|
38
|
-
expected_file = cql_file.sub(%r{/CQL/(.*).cql\Z}, '/ruby/\1.rb')
|
39
|
-
actual_file = cql_file.sub(%r{examples/CQL/(.*).cql\Z}, 'spec/actual/\1.rb')
|
40
|
-
|
41
|
-
next unless ENV["AFTESTS"] || File.exists?(expected_file)
|
42
|
-
|
43
|
-
it "should load #{cql_file} and dump Ruby matching #{expected_file}" do
|
44
|
-
vocabulary = nil
|
45
|
-
broken = cql_failures[File.basename(cql_file, ".cql")]
|
46
|
-
if broken
|
47
|
-
pending(broken) {
|
48
|
-
vocabulary = ActiveFacts::Input::CQL.readfile(cql_file)
|
49
|
-
}
|
50
|
-
else
|
51
|
-
vocabulary = ActiveFacts::Input::CQL.readfile(cql_file)
|
52
|
-
end
|
53
|
-
vocabulary.finalise
|
54
|
-
|
55
|
-
# Build and save the actual file:
|
56
|
-
ruby_text = ruby(vocabulary)
|
57
|
-
Dir.mkdir "spec/actual" rescue nil
|
58
|
-
File.open(actual_file, "w") { |f| f.write ruby_text }
|
59
|
-
|
60
|
-
pending("expected output file #{expected_file} not found") unless File.exists? expected_file
|
61
|
-
|
62
|
-
expected_text = File.open(expected_file) {|f| f.read }
|
63
|
-
# if broken
|
64
|
-
# pending(broken) {
|
65
|
-
# ruby_text.should == File.open(expected_file) {|f| f.read }
|
66
|
-
# }
|
67
|
-
# else
|
68
|
-
ruby_text.should_not differ_from(expected_text)
|
69
|
-
File.delete(actual_file) # It succeeded, we don't need the file.
|
70
|
-
# end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
data/spec/cql_sql_spec.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# ActiveFacts tests: Parse all CQL files and check the generated SQL.
|
3
|
-
# Copyright (c) 2008 Clifford Heath. Read the LICENSE file.
|
4
|
-
#
|
5
|
-
|
6
|
-
require 'spec_helper'
|
7
|
-
require 'stringio'
|
8
|
-
require 'activefacts/vocabulary'
|
9
|
-
require 'activefacts/support'
|
10
|
-
require 'activefacts/input/cql'
|
11
|
-
require 'activefacts/generate/sql/server'
|
12
|
-
|
13
|
-
describe "CQL Loader with SQL output" do
|
14
|
-
cql_failures = {
|
15
|
-
"Airline" => "Contains unsupported queries",
|
16
|
-
"CompanyQuery" => "Contains unsupported queries",
|
17
|
-
}
|
18
|
-
cql_sql_failures = {
|
19
|
-
"OrienteeringER" => "Invalid model, it just works differently in CQL"
|
20
|
-
}
|
21
|
-
|
22
|
-
# Generate and return the SQL for the given vocabulary
|
23
|
-
def sql(vocabulary)
|
24
|
-
output = StringIO.new
|
25
|
-
@dumper = ActiveFacts::Generate::SQL::SERVER.new(vocabulary.constellation)
|
26
|
-
@dumper.generate(output)
|
27
|
-
output.rewind
|
28
|
-
output.read
|
29
|
-
end
|
30
|
-
|
31
|
-
pattern = ENV["AFTESTS"] || "*"
|
32
|
-
Dir["examples/CQL/#{pattern}.cql"].each do |cql_file|
|
33
|
-
actual_file = cql_file.sub(%r{examples/CQL/(.*).cql}, 'spec/actual/\1.sql')
|
34
|
-
expected_file = cql_file.sub(%r{examples/CQL/(.*).cql\Z}, 'examples/SQL/\1.sql')
|
35
|
-
|
36
|
-
next unless ENV["AFTESTS"] || File.exists?(expected_file)
|
37
|
-
|
38
|
-
it "should load #{cql_file} and dump SQL matching #{expected_file}" do
|
39
|
-
vocabulary = nil
|
40
|
-
broken = cql_failures[File.basename(cql_file, ".cql")]
|
41
|
-
if broken
|
42
|
-
pending(broken) {
|
43
|
-
vocabulary = ActiveFacts::Input::CQL.readfile(cql_file)
|
44
|
-
}
|
45
|
-
else
|
46
|
-
vocabulary = ActiveFacts::Input::CQL.readfile(cql_file)
|
47
|
-
end
|
48
|
-
vocabulary.finalise
|
49
|
-
|
50
|
-
# Build and save the actual file:
|
51
|
-
sql_text = sql(vocabulary)
|
52
|
-
Dir.mkdir "spec/actual" rescue nil
|
53
|
-
File.open(actual_file, "w") { |f| f.write sql_text }
|
54
|
-
|
55
|
-
pending("expected output file #{expected_file} not found") unless File.exists? expected_file
|
56
|
-
|
57
|
-
expected_text = File.open(expected_file) {|f| f.read }
|
58
|
-
broken = cql_sql_failures[File.basename(cql_file, ".cql")]
|
59
|
-
if broken
|
60
|
-
pending(broken) {
|
61
|
-
sql_text.should_not differ_from(expected_text)
|
62
|
-
}
|
63
|
-
else
|
64
|
-
# Discard index names:
|
65
|
-
sql_text.gsub!(/ INDEX (\[[^\]]*\]|`[^`]*`|[^ ]*) ON /, ' INDEX <Name is hidden> ON ')
|
66
|
-
expected_text.gsub!(/ INDEX (\[[^\]]*\]|`[^`]*`|[^ ]*) ON /, ' INDEX <Name is hidden> ON ')
|
67
|
-
sql_text.should_not differ_from(expected_text)
|
68
|
-
File.delete(actual_file) # It succeeded, we don't need the file.
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|