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,106 +0,0 @@
1
- #
2
- # ActiveFacts tests: Test the CQL parser by looking at its parse trees.
3
- # Copyright (c) 2008 Clifford Heath. Read the LICENSE file.
4
- #
5
-
6
- require 'activefacts/cql'
7
- require 'activefacts/support'
8
- require 'activefacts/api/support'
9
- require 'helpers/test_parser'
10
-
11
- describe "Entity Types" do
12
- EntityTypes_RefMode = [
13
- [ "a is identified by its id;", # Entity type declaration with reference mode
14
- ["EntityType: a identified by its id;"]
15
- ],
16
- [ "a is identified by its number(12);", # Entity type declaration with reference mode
17
- ["EntityType: a identified by its number(12);"]
18
- ],
19
- [ "a is identified by its id where c;", # Entity type declaration with reference mode and fact type(s)
20
- ["EntityType: a identified by its id where [{c}];"]
21
- ],
22
- [ "a is identified by its id where c;", # Entity type declaration with reference mode and where
23
- ["EntityType: a identified by its id where [{c}];"]
24
- ],
25
- ]
26
-
27
- EntityTypes_Simple = [
28
- [ "a is identified by b where c;", # Entity type declaration
29
- ["EntityType: a [{b}] where [{c}];"]
30
- ],
31
- [ "a is identified by b where c;", # Entity type declaration with where
32
- ["EntityType: a [{b}] where [{c}];"]
33
- ],
34
- [ "a is identified by b and c where d;", # Entity type declaration with two-part identifier
35
- ["EntityType: a [{b}, {c}] where [\"d\"];"]
36
- ],
37
- [ "a is identified by b, c where d;", # Entity type declaration with two-part identifier
38
- ["EntityType: a [{b}, {c}] where [\"d\"];"]
39
- ],
40
- [ "aa is written as b(); e is identified by aa where d;",
41
- ["ValueType: aa is written as b;", "EntityType: e [{aa}] where [\"d\"];"]
42
- ],
43
- [ " aa is written as b ( ) ; e is identified by aa where d ; ",
44
- ["ValueType: aa is written as b;", "EntityType: e [{aa}] where [\"d\"];"]
45
- ],
46
- [ "e is written as b; aa is identified by e where maybe d;",
47
- ["ValueType: e is written as b;", "EntityType: aa [{e}] where [maybe \"d\"];"]
48
- ],
49
- ]
50
-
51
- EntityTypes_Objectified = [
52
- [ "Director is where b directs c, c is directed by b;",
53
- ["FactType: [{b} \"directs\" {c}, {c} \"is directed by\" {b}]"]
54
- ],
55
- ]
56
-
57
- EntityTypes_Subtypes = [
58
- [ "Employee is a kind of Person;",
59
- ["EntityType: Employee < Person nil;"]
60
- ],
61
- [ "Employee is a subtype of Person;",
62
- ["EntityType: Employee < Person nil;"]
63
- ],
64
- [ "AustralianEmployee is a subtype of Employee, Australian;",
65
- ["EntityType: AustralianEmployee < Employee,Australian nil;"]
66
- ],
67
- [ "Employee is a kind of Person identified by EmployeeNumber;",
68
- ["EntityType: Employee < Person [{EmployeeNumber}];"]
69
- ],
70
- [ "Employee is a subtype of Person identified by EmployeeNumber;",
71
- ["EntityType: Employee < Person [{EmployeeNumber}];"]
72
- ],
73
- [ "AustralianEmployee is a subtype of Employee, Australian identified by TaxFileNumber;",
74
- ["EntityType: AustralianEmployee < Employee,Australian [{TaxFileNumber}];"]
75
- ],
76
- ]
77
-
78
- EntityTypes =
79
- EntityTypes_RefMode +
80
- EntityTypes_Simple +
81
- EntityTypes_Objectified +
82
- EntityTypes_Subtypes
83
-
84
- before :each do
85
- @parser = TestParser.new
86
- @parser.parse_all("c is written as b;", :definition)
87
- end
88
-
89
- EntityTypes.each do |c|
90
- source, ast = *c
91
- it "should parse #{source.inspect}" do
92
- result = @parser.parse_all(source, :definition)
93
-
94
- puts @parser.failure_reason unless result
95
- result.should_not be_nil
96
-
97
- canonical_form = result.map{|d| d.ast.to_s}
98
- if ast
99
- canonical_form.should == ast
100
- else
101
- puts "#{source.inspect} should compile to"
102
- puts "\t#{canonical_form}"
103
- end
104
- end
105
- end
106
- end
@@ -1,199 +0,0 @@
1
- #
2
- # ActiveFacts tests: Test the CQL parser by looking at its parse trees.
3
- # Copyright (c) 2008 Clifford Heath. Read the LICENSE file.
4
- #
5
-
6
- require 'activefacts/cql'
7
- require 'activefacts/support'
8
- require 'activefacts/api/support'
9
- require 'spec_helper'
10
- require 'helpers/test_parser'
11
-
12
- describe "ASTs from Derived Fact Types with expressions" do
13
- it "should parse a simple comparison clause" do
14
- # Director is old: Company is directed by Person who is of Age > 60;
15
- %q{
16
- Director is old: Person directs Company, Person is of Age, Age > 60;
17
- }.should parse_to_ast \
18
- %q{
19
- FactType: Query: where {Person} "directs" {Company} ,
20
- {Person} "is of" {Age} ,
21
- COMPARE>({Age} WITH 60)
22
- [{Director} "is old"]
23
- }
24
- end
25
-
26
- it "should parse a comparison clause with subscripts" do
27
- %q{
28
- Director is old: Person directs Company, Person has Salary(2), Person is of Age(1), Age(1) > Salary(2);
29
- }.should parse_to_ast \
30
- %q{
31
- FactType: Query: where {Person} "directs" {Company} ,
32
- {Person} "has" {Salary(2)} ,
33
- {Person} "is of" {Age(1)} ,
34
- COMPARE>({Age(1)} WITH {Salary(2)})
35
- [{Director} "is old"]
36
- }
37
- end
38
-
39
- it "should parse simple comparison clause having an unmarked adjective" do
40
- %q{
41
- Person is independent: Person has taxable- Income and taxable Income >= 20000 dollars or Person has sugar-Daddy;
42
- }.should parse_to_ast \
43
- %q{
44
- FactType: Query: where {Person} "has" {taxable- Income} and
45
- COMPARE>=({taxable- Income} WITH (20000 in dollars)) or
46
- {Person} "has" {sugar- Daddy}
47
- [{Person} "is independent"]
48
- }
49
- end
50
-
51
- it "should parse a reading with a contracted comparison expression" do
52
- %q{
53
- Director is old: Person directs company, Person is of Age > 20+2*20;
54
- }.should parse_to_ast \
55
- %q{
56
- FactType: Query: where {Person} "directs company" ,
57
- {Person} "is of" {Age} > COMPARE>({Age} WITH SUM(20 PLUS PRODUCT(2 TIMES 20)))
58
- [{Director} "is old"]
59
- }
60
- end
61
-
62
- it "should parse a right-contracted comparison clause after a right-contracted clause" do
63
- %q{
64
- Director is old: Company is directed by Person who is of Age > 60;
65
- }.should parse_to_ast \
66
- %q{FactType: Query: where {Company} "is directed by" {Person} who {Person} "is of" {Age} > COMPARE>({Age} WITH 60) [{Director} "is old"]}
67
- end
68
-
69
- it "should parse a simple reading with qualifiers" do
70
- %q{
71
- Person(1) is ancestor of Person(2): maybe Person(1) is parent of Person(2) [transitive];
72
- }.should parse_to_ast \
73
- %q{FactType: Query: where ["transitive"] maybe {Person(1)} "is parent of" {Person(2)} [{Person(1)} "is ancestor of" {Person(2)}]}
74
- end
75
-
76
- it "should parse a contracted reading with qualifiers" do
77
- %q{
78
- Person(1) provides lineage of Person(2): maybe Person(2) is child of Person(1) [transitive] who is male;
79
- }.should parse_to_ast \
80
- %q{FactType: Query: where ["transitive"] maybe {Person(2)} "is child of" {Person(1)} who {Person(1)} "is male" [{Person(1)} "provides lineage of" {Person(2)}]}
81
- end
82
-
83
- it "should parse a contracted readings and comparisons with qualifiers" do
84
- %q{
85
- Person(1) is ancestor of adult Person(2):
86
- maybe Person(1) is parent of Person(2) [transitive]
87
- who maybe is of Age [static]
88
- definitely >= 21;
89
- }.should parse_to_ast \
90
- %q{
91
- FactType: Query: where ["transitive"] maybe {Person(1)} "is parent of" {Person(2)} who
92
- ["static"] maybe {Person(2)} "is of" {Age} >=
93
- COMPARE>=({Age} WITH 21)
94
- [{Person(1)} "is ancestor of adult" {Person(2)}]
95
- }
96
- end
97
-
98
- it "should parse a comparison expression with a contracted reading" do
99
- %q{
100
- Director is old: Person directs company, 3*30 >= Age that is of Person;
101
- }.should parse_to_ast \
102
- %q{
103
- FactType: Query: where {Person} "directs company" ,
104
- COMPARE>=(PRODUCT(3 TIMES 30) WITH {Age}) that
105
- {Age} "is of" {Person}
106
- [{Director} "is old"]
107
- }
108
- end
109
-
110
- it "should parse a comparison expression with a contracted comparison" do
111
- %q{
112
- Director is old: Person directs company, Person is of Age, maybe 20 <= Age definitely < 60;
113
- }.should parse_to_ast \
114
- %q{
115
- FactType: Query: where {Person} "directs company" ,
116
- {Person} "is of" {Age} ,
117
- COMPARE<=(maybe 20 WITH {Age}) <
118
- COMPARE<({Age} WITH 60)
119
- [{Director} "is old"]
120
- }
121
- end
122
-
123
- it "should parse a comparison expression with right-contracted then left-contracted comparisons"
124
- # Director is probably adult: Person directs company, Person is of Age maybe >= 21 and definitely < 60;
125
- # end
126
-
127
- it "should fail to parse a contracted comparison that doesn't follow a role" do
128
- %q{
129
- Director is old: Person directs company, Person is of Age considerable > 3*20;
130
- }.should fail_to_parse /Expected (.|\n)* after (.|\n)* Age considerable > 3\*20;\n *$/
131
- end
132
-
133
- it "should parse pre and post-qualifiers and leading and trailing adjectives with contracted comparisons" do
134
- %q{
135
- A is a farce: maybe A has completely- B [transitive, acyclic] < 5, B -c = 2;
136
- }.should parse_to_ast \
137
- %q{
138
- FactType: Query: where ["acyclic", "transitive"] maybe {A} "has" {completely- B} <
139
- COMPARE<({completely- B} WITH 5) ,
140
- COMPARE=({B -c} WITH 2)
141
- [{A} "is a farce"]
142
- }
143
- end
144
-
145
- it "should parse multiple leading and trailing adjectives with contracted comparisons" do
146
- %q{
147
- A is a farce: maybe A has completely- green B [transitive, acyclic] < 9, B c -d = 2;
148
- }.should parse_to_ast \
149
- %q{
150
- FactType: Query: where ["acyclic", "transitive"] maybe {A} "has" {completely- green B} <
151
- COMPARE<({completely- green B} WITH 9) ,
152
- COMPARE=({B c -d} WITH 2)
153
- [{A} "is a farce"]
154
- }
155
- end
156
-
157
- it "should parse a comparison clause containing units" do
158
- %q{
159
- 254 mm converts to foot/feet;
160
- Width is written as Integer in mm;
161
- Window requires toughening where
162
- Window has Width,
163
- Window has Height,
164
- Width * Height >= 10 feet^2;
165
- }.should parse_to_ast \
166
- %q{Unit(foot/feet) is 254/1+0 mm^1},
167
- %q{ValueType: Width is written as Integer in [["mm", 1]];},
168
- %q{FactType: Query: where {Window} "has" {Width} ,
169
- {Window} "has" {Height} ,
170
- COMPARE>=(PRODUCT({Width} TIMES {Height}) WITH (10 in feet^2))
171
- [{Window} "requires toughening"]
172
- }
173
- end
174
-
175
- it "should parse nested expressions" do
176
- %q{
177
- A is written as B;
178
- A > B+3*(4+5)?
179
- }.should parse_to_ast \
180
- %q{ValueType: A is written as B;},
181
- %q{FactType: Query: where COMPARE>({A} WITH SUM({B} PLUS PRODUCT(3 TIMES SUM(4 PLUS 5)))) []}
182
- end
183
-
184
- it "should parse a fact type containing an expression with subscripts"
185
-
186
- it "should parse a fact type containing objectification steps and contractions" do
187
- %q{
188
- Driving was negligent where
189
- Driving (where maybe Driver drove in Incident [acyclic] that definitely is of Claim [intransitive]) followed Intoxication [static];
190
- }.should parse_to_ast \
191
- %q{
192
- FactType: Query: where ["static"] {Driving} (in which where
193
- ["acyclic"] maybe {Driver} "drove in" {Incident}
194
- that ["intransitive"] {Incident} "is of" {Claim}) "followed" {Intoxication}
195
- [{Driving} "was negligent"]
196
- }
197
- end
198
-
199
- end
@@ -1,44 +0,0 @@
1
- #
2
- # ActiveFacts tests: Test the CQL parser by looking at its parse trees.
3
- # Copyright (c) 2008 Clifford Heath. Read the LICENSE file.
4
- #
5
-
6
- require 'activefacts/cql'
7
- require 'activefacts/support'
8
- require 'activefacts/api/support'
9
- require 'spec_helper'
10
- require 'helpers/test_parser'
11
-
12
- describe "Fact Types" do
13
- FactTypes = [
14
- [ "Foo has at most one Bar, Bar is of one Foo restricted to {1..10};",
15
- ["FactType: [{Foo} \"has\" {[..1] Bar}, {Bar} \"is of\" {[1..1] Foo ValueConstraint to ([1..10])}]"]
16
- ],
17
- [ "Bar(1) is related to Bar(2), primary-Bar(1) has secondary-Bar(2);",
18
- ["FactType: [{Bar(1)} \"is related to\" {Bar(2)}, {primary- Bar(1)} \"has\" {secondary- Bar(2)}]"]
19
- ],
20
- # REVISIT: Test all quantifiers
21
- # REVISIT: Test all post-qualifiers
22
- # [ "AnnualIncome is where Person has total- Income in Year: Person has total- Income.sum(), Income was earned in current- Time.Year() (as Year);",
23
- # [%q{FactType: AnnualIncome [{Person} "has" {total- Income} "in" {Year}] where {Person} "has" {total- Income}.sum() , {Income} "was earned in" {current- Time (as Year)}.Year()}]
24
- # ],
25
- [ "A is interesting : b- C has F -g;",
26
- [%q{FactType: Query: where {b- C} "has" {F -g} [{A} "is interesting"]}]
27
- ],
28
- [ "A has one pre-- bound B;",
29
- [%q{FactType: [{A} "has" {[1..1] pre-bound- B}]}]
30
- ]
31
- # REVISIT: Test all quantifiers
32
- ]
33
-
34
- before :each do
35
- @parser = TestParser.new
36
- end
37
-
38
- FactTypes.each do |c|
39
- source, ast, definition = *c
40
- it "should parse #{source.inspect}" do
41
- source.should parse_to_ast *ast
42
- end
43
- end
44
- end
@@ -1,312 +0,0 @@
1
- #
2
- # ActiveFacts tests: Test the CQL parser by looking at its parse trees.
3
- # Copyright (c) 2008 Clifford Heath. Read the LICENSE file.
4
- #
5
-
6
- require 'activefacts/cql'
7
- require 'activefacts/support'
8
- require 'activefacts/api/support'
9
- require 'helpers/test_parser'
10
-
11
- describe "Valid Numbers, Strings and Ranges" do
12
- ValidNumbersEtc = [
13
- [ "a is written as b;", # Value type declaration, no params, minimal whitespace
14
- ['ValueType: a is written as b;']
15
- ],
16
- [ "a is written as B;", # Value type declaration, no params, minimal whitespace
17
- ['ValueType: a is written as B;']
18
- ],
19
- [ "a is written as b();", # Value type declaration, minimal whitespace
20
- ['ValueType: a is written as b;']
21
- ],
22
- [ "a is written as b ;", # Value type declaration, no params, trailing whitespace
23
- ['ValueType: a is written as b;']
24
- ],
25
- [ "a is written as b ( ) ; ", # Value type declaration, maximal whitespace
26
- ['ValueType: a is written as b;']
27
- ],
28
-
29
- # Comments and newlines, etc as whitespace
30
- [ "\na\nis written as \nb\n(\n)\n;\n", # Basic value type declaration, newlines for whitespace
31
- ['ValueType: a is written as b;']
32
- ],
33
- [ "\ra\ris written as\rb\r(\r)\r;\r", # Basic value type declaration, returns for whitespace
34
- ['ValueType: a is written as b;']
35
- ],
36
- [ "\ta\tis written as\tb\t(\t)\t;\t", # Basic value type declaration, tabs for whitespace
37
- ['ValueType: a is written as b;']
38
- ],
39
- [ " /* Plugh */ a /* Plugh */ is written as\n b /* *Plugh* / */ ( /* *Plugh* / */ ) /* *Plugh* / */ ; /* *Plugh* / */ ",
40
- ['ValueType: a is written as b;']
41
- ],
42
- [ "//Plugh\na // Plugh\n is written as // Plugh\n b // Plugh\n ( // Plugh\n ) // Plugh\n ; // Plugh\n ",
43
- ['ValueType: a is written as b;']
44
- ],
45
-
46
- # Integers
47
- [ "a is written as b(0);", # Integer zero
48
- ['ValueType: a is written as b(0);']
49
- ],
50
- [ "a is written as b( 0 ) ; ", # Integer zero, maximal whitespace
51
- ['ValueType: a is written as b(0);']
52
- ],
53
- [ "a is written as b(1);", # Integer one
54
- ['ValueType: a is written as b(1);']
55
- ],
56
- [ "a is written as b(-1);", # Integer negative one
57
- ['ValueType: a is written as b(-1);']
58
- ],
59
- [ "a is written as b(+1);", # Positive integer
60
- ['ValueType: a is written as b(1);']
61
- ],
62
- [ "a is written as b(1e4);", # Integer with exponent
63
- ['ValueType: a is written as b(10000.0);']
64
- ],
65
- [ "a is written as b(1e-4);", # Integer with negative exponent
66
- ['ValueType: a is written as b(0.0001);']
67
- ],
68
- [ "a is written as b(-1e-4);", # Negative integer with negative exponent
69
- ['ValueType: a is written as b(-0.0001);']
70
- ],
71
- [ "a is written as b(077);", # Octal integer
72
- ['ValueType: a is written as b(63);']
73
- ],
74
- [ "a is written as b(0xFace8);", # Hexadecimal integer
75
- ['ValueType: a is written as b(1027304);']
76
- ],
77
- [ "a is written as b(0,1);", # Two parameters
78
- ['ValueType: a is written as b(0, 1);']
79
- ],
80
- [ "a is written as b( 0 , 1 );",
81
- ['ValueType: a is written as b(0, 1);']
82
- ],
83
- [ "a is written as b(0,1,2) ;", # Three parameters now allowed
84
- ['ValueType: a is written as b(0, 1, 2);']
85
- ],
86
-
87
- # Reals
88
- [ "a is written as b(1.0);",
89
- ['ValueType: a is written as b(1.0);']
90
- ],
91
- [ "a is written as b(-1.0);",
92
- ['ValueType: a is written as b(-1.0);']
93
- ],
94
- [ "a is written as b(+1.0);",
95
- ['ValueType: a is written as b(1.0);']
96
- ],
97
- [ "a is written as b(0.1);",
98
- ['ValueType: a is written as b(0.1);']
99
- ],
100
- [ "a is written as b(-0.1);",
101
- ['ValueType: a is written as b(-0.1);']
102
- ],
103
- [ "a is written as b(+0.1);",
104
- ['ValueType: a is written as b(0.1);']
105
- ],
106
- [ "a is written as b(0.0);",
107
- ['ValueType: a is written as b(0.0);']
108
- ],
109
- [ "a is written as b(-0.0);",
110
- ['ValueType: a is written as b(-0.0);']
111
- ],
112
- [ "a is written as b(+0.0);",
113
- ['ValueType: a is written as b(0.0);']
114
- ],
115
-
116
- # Value types with units
117
- [ "a is written as b in inch;", # Value type declaration with unit
118
- ['ValueType: a is written as b in [["inch", 1]];']
119
- ],
120
- [ "a is written as b() in inch ; ", # Value type declaration with unit and whitespace
121
- ['ValueType: a is written as b in [["inch", 1]];']
122
- ],
123
- [ "a is written as b() in inch;", # Value type declaration with unit
124
- ['ValueType: a is written as b in [["inch", 1]];']
125
- ],
126
- [ "a is written as b in inch^2;", # Value type declaration with unit and exponent
127
- ['ValueType: a is written as b in [["inch", 2]];']
128
- ],
129
- [ "a is written as b() in inch^2 ; ", # Value type declaration with unit and exponent with maximum whitespace
130
- ['ValueType: a is written as b in [["inch", 2]];']
131
- ],
132
- [ "a is written as b in second^-1;", # Value type declaration with unit and negative exponent
133
- ['ValueType: a is written as b in [["second", -1]];']
134
- ],
135
- [ "a is written as b in inch inch;", # Value type declaration with repeated unit
136
- ['ValueType: a is written as b in [["inch", 1], ["inch", 1]];']
137
- ],
138
- [ "a is written as b in inch^2/minute^-1;", # Value type declaration with unit and divided unit with exponents
139
- ['ValueType: a is written as b in [["inch", 2], ["minute", 1]];']
140
- ],
141
- [ "a is written as b() in second^-1/mm^-1 mm^-1;", # Value type declaration with repeated divided unit
142
- ['ValueType: a is written as b in [["second", -1], ["mm", 1], ["mm", 1]];']
143
- ],
144
-
145
- # Integer value constraints
146
- [ "a is written as b()restricted to{1};", # Integer, minimal whitespace
147
- ['ValueType: a is written as b ValueConstraint to ([1]);']
148
- ],
149
- [ "a is written as b() restricted to { 1 } ;", # Integer, maximal whitespace
150
- ['ValueType: a is written as b ValueConstraint to ([1]);']
151
- ],
152
- [ "a is written as b() restricted to {1..2};", # Integer range, minimal whitespace
153
- ['ValueType: a is written as b ValueConstraint to ([1..2]);']
154
- ],
155
- [ "a is written as b() restricted to { 1 .. 2 };", # Integer range, maximal whitespace
156
- ['ValueType: a is written as b ValueConstraint to ([1..2]);']
157
- ],
158
- [ "a is written as b() restricted to {..2};", # Integer range with open start, minimal whitespace
159
- ['ValueType: a is written as b ValueConstraint to ([-Infinity..2]);']
160
- ],
161
- [ "a is written as b() restricted to { .. 2 };", # Integer range with open start, maximal whitespace
162
- ['ValueType: a is written as b ValueConstraint to ([-Infinity..2]);']
163
- ],
164
- [ "a is written as b() restricted to { ..2,3};", # Range followed by integer, minimal whitespace
165
- ['ValueType: a is written as b ValueConstraint to ([-Infinity..2, 3]);']
166
- ],
167
- [ "a is written as b() restricted to { 1,..2,3};", # Integer, open-start range, integer, minimal whitespace
168
- ['ValueType: a is written as b ValueConstraint to ([1, -Infinity..2, 3]);']
169
- ],
170
- [ "a is written as b() restricted to { .. 2 , 3 };", # Range followed by integer, maximal whitespace
171
- ['ValueType: a is written as b ValueConstraint to ([-Infinity..2, 3]);']
172
- ],
173
- [ "a is written as b() restricted to { ..2 , 3..4 };",# Range followed by range
174
- ['ValueType: a is written as b ValueConstraint to ([-Infinity..2, 3..4]);']
175
- ],
176
- [ "a is written as b() restricted to { ..2, 3..};", # Range followed by range with open end, minimal whitespace
177
- ['ValueType: a is written as b ValueConstraint to ([-Infinity..2, 3..Infinity]);']
178
- ],
179
- [ "a is written as b() restricted to { ..2, 3 .. };", # Range followed by range with open end, maximal whitespace
180
- ['ValueType: a is written as b ValueConstraint to ([-Infinity..2, 3..Infinity]);']
181
- ],
182
- [ "a is written as b() restricted to { 1e4 } ;", # Integer with exponent
183
- ['ValueType: a is written as b ValueConstraint to ([10000.0]);']
184
- ],
185
- [ "a is written as b() restricted to { -1e4 } ;", # Negative integer with exponent
186
- ['ValueType: a is written as b ValueConstraint to ([-10000.0]);']
187
- ],
188
- [ "a is written as b() restricted to { 1e-4 } ;", # Integer with negative exponent
189
- ['ValueType: a is written as b ValueConstraint to ([0.0001]);']
190
- ],
191
- [ "a is written as b() restricted to { -1e-4 } ;", # Negative integer with negative exponent
192
- ['ValueType: a is written as b ValueConstraint to ([-0.0001]);']
193
- ],
194
-
195
- # Real value constraints
196
- [ "a is written as b() restricted to {1.0};", # Real, minimal whitespace
197
- ['ValueType: a is written as b ValueConstraint to ([1.0]);']
198
- ],
199
- [ "a is written as b() restricted to { 1.0 } ;", # Real, maximal whitespace
200
- ['ValueType: a is written as b ValueConstraint to ([1.0]);']
201
- ],
202
- [ "a is written as b() restricted to { 1.0e4 } ;", # Real with exponent
203
- ['ValueType: a is written as b ValueConstraint to ([10000.0]);']
204
- ],
205
- [ "a is written as b() restricted to { 1.0e-4 } ;", # Real with negative exponent
206
- ['ValueType: a is written as b ValueConstraint to ([0.0001]);']
207
- ],
208
- [ "a is written as b() restricted to { -1.0e-4 } ;", # Negative real with negative exponent
209
- ['ValueType: a is written as b ValueConstraint to ([-0.0001]);']
210
- ],
211
- [ "a is written as b() restricted to { 1.1 .. 2.2 } ;", # Real range, maximal whitespace
212
- ['ValueType: a is written as b ValueConstraint to ([1.1..2.2]);']
213
- ],
214
- [ "a is written as b() restricted to { -1.1 .. 2.2 } ;", # Real range, maximal whitespace
215
- ['ValueType: a is written as b ValueConstraint to ([-1.1..2.2]);']
216
- ],
217
- [ "a is written as b() restricted to { 1.1..2.2};", # Real range, minimal whitespace
218
- ['ValueType: a is written as b ValueConstraint to ([1.1..2.2]);']
219
- ],
220
- [ "a is written as b() restricted to { 1.1..2 } ;", # Real-integer range
221
- ['ValueType: a is written as b ValueConstraint to ([1.1..2]);']
222
- ],
223
- [ "a is written as b() restricted to { 1..2.2 } ;", # Integer-real range
224
- ['ValueType: a is written as b ValueConstraint to ([1..2.2]);']
225
- ],
226
- [ "a is written as b() restricted to { ..2.2};", # Real range with open start
227
- ['ValueType: a is written as b ValueConstraint to ([-Infinity..2.2]);']
228
- ],
229
- [ "a is written as b() restricted to { 1.1.. };", # Real range with open end
230
- ['ValueType: a is written as b ValueConstraint to ([1.1..Infinity]);']
231
- ],
232
- [ "a is written as b() restricted to { 1.1.., 2 };", # Real range with open end and following integer
233
- ['ValueType: a is written as b ValueConstraint to ([1.1..Infinity, 2]);']
234
- ],
235
-
236
- # Strings and string value constraints
237
- [ "a is written as b() restricted to {''};", # String, empty, minimal whitespace
238
- ['ValueType: a is written as b ValueConstraint to (["\'\'"]);']
239
- ],
240
- [ "a is written as b() restricted to {'A'};", # String, minimal whitespace
241
- ['ValueType: a is written as b ValueConstraint to (["\'A\'"]);']
242
- ],
243
- [ "a is written as b() restricted to { 'A' };", # String, maximal whitespace
244
- ['ValueType: a is written as b ValueConstraint to (["\'A\'"]);']
245
- ],
246
- [ "a is written as b() restricted to { '\\b\\t\\f\\n\\r\\e\\\\' };", # String with special escapes
247
- ["ValueType: a is written as b ValueConstraint to ([\"'\\\\b\\\\t\\\\f\\\\n\\\\r\\\\e\\\\\\\\'\"]);"]
248
- ],
249
- [ "a is written as b() restricted to { ' ' };", # String with space
250
- ['ValueType: a is written as b ValueConstraint to (["\' \'"]);']
251
- ],
252
- [ "a is written as b() restricted to { '\t' };", # String with literal tab
253
- ['ValueType: a is written as b ValueConstraint to (["\'\t\'"]);']
254
- ],
255
- [ "a is written as b() restricted to { '\\0' };", # String with nul character
256
- ["ValueType: a is written as b ValueConstraint to ([\"'\\\\0'\"]);"]
257
- ],
258
- [ "a is written as b() restricted to { '\\077' };", # String with octal escape
259
- ["ValueType: a is written as b ValueConstraint to ([\"'\\\\077'\"]);"]
260
- ],
261
- [ "a is written as b() restricted to { '\\0xA9' };", # String with hexadecimal escape
262
- ["ValueType: a is written as b ValueConstraint to ([\"'\\\\0xA9'\"]);"]
263
- ],
264
- [ "a is written as b() restricted to { '\\0uBabe' };",# String with unicode escape
265
- ["ValueType: a is written as b ValueConstraint to ([\"'\\\\0uBabe'\"]);"]
266
- ],
267
- [ "a is written as b() restricted to {'A'..'F'};", # String range, minimal whitespace
268
- ['ValueType: a is written as b ValueConstraint to (["\'A\'".."\'F\'"]);']
269
- ],
270
- [ "a is written as b() restricted to { 'A' .. 'F' };",# String range, maximal whitespace
271
- ['ValueType: a is written as b ValueConstraint to (["\'A\'".."\'F\'"]);']
272
- ],
273
- [ "a is written as b() restricted to { ..'F' };", # String range, open start
274
- ['ValueType: a is written as b ValueConstraint to (["MIN".."F"]);']
275
- ],
276
- [ "a is written as b() restricted to { 'A'.. };", # String range, open end
277
- ['ValueType: a is written as b ValueConstraint to (["\'A\'".."MAX"]);']
278
- ],
279
-
280
- # Value constraints with units
281
- [ "a is written as b() restricted to {1} inches^2/second;", # constraint with units and exponent
282
- ['ValueType: a is written as b ValueConstraint to ([1]) in [["inches", 2], ["second", -1]];']
283
- ],
284
- [ "a is written as b() in second^-1/mm^-1 mm^-1 restricted to {1} inches^2/second;", # type with unit and constraint with units and exponent
285
- #['a is written as b ValueConstraint to ([1]) in [["inches", 2], ["second", -1]];']
286
- ["ValueType: a is written as b in [[\"second\", -1], [\"mm\", 1], [\"mm\", 1]] ValueConstraint to ([1]) in [[\"inches\", 2], [\"second\", -1]];"]
287
- ],
288
- ]
289
-
290
- before :each do
291
- @parser = TestParser.new
292
- end
293
-
294
- ValidNumbersEtc.each do |c|
295
- source, ast = *c
296
- it "should parse #{source.inspect}" do
297
- result = @parser.parse_all(source, :definition)
298
-
299
- puts @parser.failure_reason unless result
300
- result.should_not be_nil
301
-
302
- canonical_form = result.map{|d| d.ast.to_s}
303
- if ast
304
- canonical_form.should == ast
305
- else
306
- puts "#{source.inspect} should compile to"
307
- puts "\t#{canonical_form}"
308
- end
309
- end
310
- end
311
- end
312
-