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.
Files changed (169) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +14 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +4 -0
  5. data/Gemfile +14 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +60 -0
  8. data/Rakefile +3 -80
  9. data/activefacts.gemspec +36 -0
  10. data/bin/afgen +4 -2
  11. data/bin/cql +5 -1
  12. data/lib/activefacts.rb +3 -12
  13. data/lib/activefacts/{vocabulary/query_evaluator.rb → query/evaluator.rb} +0 -0
  14. data/lib/activefacts/version.rb +2 -2
  15. metadata +48 -296
  16. data/History.txt +0 -4
  17. data/LICENSE +0 -19
  18. data/Manifest.txt +0 -165
  19. data/README.rdoc +0 -81
  20. data/css/offline.css +0 -3
  21. data/css/orm2.css +0 -124
  22. data/css/print.css +0 -8
  23. data/css/style-print.css +0 -357
  24. data/css/style.css +0 -387
  25. data/download.html +0 -110
  26. data/examples/CQL/Address.cql +0 -44
  27. data/examples/CQL/Blog.cql +0 -54
  28. data/examples/CQL/CompanyDirectorEmployee.cql +0 -56
  29. data/examples/CQL/Death.cql +0 -17
  30. data/examples/CQL/Diplomacy.cql +0 -48
  31. data/examples/CQL/Genealogy.cql +0 -98
  32. data/examples/CQL/Insurance.cql +0 -320
  33. data/examples/CQL/Marriage.cql +0 -18
  34. data/examples/CQL/Metamodel.cql +0 -493
  35. data/examples/CQL/Monogamy.cql +0 -24
  36. data/examples/CQL/MultiInheritance.cql +0 -22
  37. data/examples/CQL/NonRoleId.cql +0 -14
  38. data/examples/CQL/OddIdentifier.cql +0 -18
  39. data/examples/CQL/OilSupply.cql +0 -53
  40. data/examples/CQL/OneToOnes.cql +0 -17
  41. data/examples/CQL/Orienteering.cql +0 -111
  42. data/examples/CQL/PersonPlaysGame.cql +0 -18
  43. data/examples/CQL/RedundantDependency.cql +0 -34
  44. data/examples/CQL/SchoolActivities.cql +0 -33
  45. data/examples/CQL/SeparateSubtype.cql +0 -30
  46. data/examples/CQL/ServiceDirector.cql +0 -276
  47. data/examples/CQL/SimplestUnary.cql +0 -12
  48. data/examples/CQL/Supervision.cql +0 -34
  49. data/examples/CQL/WaiterTips.cql +0 -33
  50. data/examples/CQL/Warehousing.cql +0 -101
  51. data/examples/CQL/WindowInRoomInBldg.cql +0 -28
  52. data/examples/CQL/unit.cql +0 -474
  53. data/examples/index.html +0 -420
  54. data/examples/intro.html +0 -327
  55. data/examples/local.css +0 -24
  56. data/index.html +0 -111
  57. data/lib/activefacts/cql.rb +0 -35
  58. data/lib/activefacts/cql/CQLParser.treetop +0 -158
  59. data/lib/activefacts/cql/Context.treetop +0 -48
  60. data/lib/activefacts/cql/Expressions.treetop +0 -67
  61. data/lib/activefacts/cql/FactTypes.treetop +0 -358
  62. data/lib/activefacts/cql/Language/English.treetop +0 -315
  63. data/lib/activefacts/cql/LexicalRules.treetop +0 -253
  64. data/lib/activefacts/cql/ObjectTypes.treetop +0 -210
  65. data/lib/activefacts/cql/Rakefile +0 -14
  66. data/lib/activefacts/cql/Terms.treetop +0 -183
  67. data/lib/activefacts/cql/ValueTypes.treetop +0 -202
  68. data/lib/activefacts/cql/compiler.rb +0 -156
  69. data/lib/activefacts/cql/compiler/clause.rb +0 -1137
  70. data/lib/activefacts/cql/compiler/constraint.rb +0 -581
  71. data/lib/activefacts/cql/compiler/entity_type.rb +0 -457
  72. data/lib/activefacts/cql/compiler/expression.rb +0 -443
  73. data/lib/activefacts/cql/compiler/fact.rb +0 -390
  74. data/lib/activefacts/cql/compiler/fact_type.rb +0 -421
  75. data/lib/activefacts/cql/compiler/query.rb +0 -106
  76. data/lib/activefacts/cql/compiler/shared.rb +0 -161
  77. data/lib/activefacts/cql/compiler/value_type.rb +0 -174
  78. data/lib/activefacts/cql/nodes.rb +0 -49
  79. data/lib/activefacts/cql/parser.rb +0 -241
  80. data/lib/activefacts/dependency_analyser.rb +0 -182
  81. data/lib/activefacts/generate/absorption.rb +0 -70
  82. data/lib/activefacts/generate/composition.rb +0 -118
  83. data/lib/activefacts/generate/cql.rb +0 -714
  84. data/lib/activefacts/generate/dm.rb +0 -279
  85. data/lib/activefacts/generate/help.rb +0 -64
  86. data/lib/activefacts/generate/helpers/inject.rb +0 -16
  87. data/lib/activefacts/generate/helpers/oo.rb +0 -162
  88. data/lib/activefacts/generate/helpers/ordered.rb +0 -605
  89. data/lib/activefacts/generate/helpers/rails.rb +0 -57
  90. data/lib/activefacts/generate/html/glossary.rb +0 -461
  91. data/lib/activefacts/generate/json.rb +0 -337
  92. data/lib/activefacts/generate/null.rb +0 -32
  93. data/lib/activefacts/generate/rails/models.rb +0 -246
  94. data/lib/activefacts/generate/rails/schema.rb +0 -216
  95. data/lib/activefacts/generate/records.rb +0 -46
  96. data/lib/activefacts/generate/ruby.rb +0 -133
  97. data/lib/activefacts/generate/sql/mysql.rb +0 -280
  98. data/lib/activefacts/generate/sql/server.rb +0 -273
  99. data/lib/activefacts/generate/stats.rb +0 -69
  100. data/lib/activefacts/generate/text.rb +0 -27
  101. data/lib/activefacts/generate/topics.rb +0 -265
  102. data/lib/activefacts/generate/traits/datavault.rb +0 -241
  103. data/lib/activefacts/generate/traits/oo.rb +0 -73
  104. data/lib/activefacts/generate/traits/ordered.rb +0 -33
  105. data/lib/activefacts/generate/traits/ruby.rb +0 -210
  106. data/lib/activefacts/generate/transform/datavault.rb +0 -266
  107. data/lib/activefacts/generate/transform/surrogate.rb +0 -214
  108. data/lib/activefacts/generate/version.rb +0 -26
  109. data/lib/activefacts/input/cql.rb +0 -43
  110. data/lib/activefacts/input/orm.rb +0 -1636
  111. data/lib/activefacts/mapping/rails.rb +0 -132
  112. data/lib/activefacts/persistence.rb +0 -15
  113. data/lib/activefacts/persistence/columns.rb +0 -446
  114. data/lib/activefacts/persistence/foreignkey.rb +0 -187
  115. data/lib/activefacts/persistence/index.rb +0 -240
  116. data/lib/activefacts/persistence/object_type.rb +0 -198
  117. data/lib/activefacts/persistence/reference.rb +0 -434
  118. data/lib/activefacts/persistence/tables.rb +0 -380
  119. data/lib/activefacts/registry.rb +0 -11
  120. data/lib/activefacts/support.rb +0 -132
  121. data/lib/activefacts/vocabulary.rb +0 -9
  122. data/lib/activefacts/vocabulary/extensions.rb +0 -1348
  123. data/lib/activefacts/vocabulary/metamodel.rb +0 -570
  124. data/lib/activefacts/vocabulary/verbaliser.rb +0 -804
  125. data/script/txt2html +0 -71
  126. data/spec/absorption_spec.rb +0 -95
  127. data/spec/cql/comparison_spec.rb +0 -89
  128. data/spec/cql/context_spec.rb +0 -94
  129. data/spec/cql/contractions_spec.rb +0 -224
  130. data/spec/cql/deontic_spec.rb +0 -88
  131. data/spec/cql/entity_type_spec.rb +0 -320
  132. data/spec/cql/expressions_spec.rb +0 -66
  133. data/spec/cql/fact_type_matching_spec.rb +0 -338
  134. data/spec/cql/french_spec.rb +0 -21
  135. data/spec/cql/parser/bad_literals_spec.rb +0 -86
  136. data/spec/cql/parser/constraints_spec.rb +0 -19
  137. data/spec/cql/parser/entity_types_spec.rb +0 -106
  138. data/spec/cql/parser/expressions_spec.rb +0 -199
  139. data/spec/cql/parser/fact_types_spec.rb +0 -44
  140. data/spec/cql/parser/literals_spec.rb +0 -312
  141. data/spec/cql/parser/pragmas_spec.rb +0 -89
  142. data/spec/cql/parser/value_types_spec.rb +0 -42
  143. data/spec/cql/role_matching_spec.rb +0 -148
  144. data/spec/cql/samples_spec.rb +0 -244
  145. data/spec/cql_cql_spec.rb +0 -73
  146. data/spec/cql_dm_spec.rb +0 -136
  147. data/spec/cql_mysql_spec.rb +0 -69
  148. data/spec/cql_parse_spec.rb +0 -34
  149. data/spec/cql_ruby_spec.rb +0 -73
  150. data/spec/cql_sql_spec.rb +0 -72
  151. data/spec/cql_symbol_tables_spec.rb +0 -261
  152. data/spec/cqldump_spec.rb +0 -170
  153. data/spec/helpers/array_matcher.rb +0 -23
  154. data/spec/helpers/ctrl_c_support.rb +0 -52
  155. data/spec/helpers/diff_matcher.rb +0 -39
  156. data/spec/helpers/file_matcher.rb +0 -34
  157. data/spec/helpers/parse_to_ast_matcher.rb +0 -80
  158. data/spec/helpers/string_matcher.rb +0 -30
  159. data/spec/helpers/test_parser.rb +0 -15
  160. data/spec/norma_cql_spec.rb +0 -66
  161. data/spec/norma_ruby_spec.rb +0 -62
  162. data/spec/norma_ruby_sql_spec.rb +0 -107
  163. data/spec/norma_sql_spec.rb +0 -57
  164. data/spec/norma_tables_spec.rb +0 -95
  165. data/spec/ruby_api_spec.rb +0 -23
  166. data/spec/spec_helper.rb +0 -35
  167. data/spec/transform_surrogate_spec.rb +0 -59
  168. data/status.html +0 -138
  169. data/why.html +0 -60
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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