finitio 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (270) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +66 -0
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +34 -30
  5. data/finitio.gemspec +1 -1
  6. data/lib/finitio.rb +7 -39
  7. data/lib/finitio/errors.rb +14 -0
  8. data/lib/finitio/support.rb +4 -1
  9. data/lib/finitio/support/attribute.rb +13 -7
  10. data/lib/finitio/support/compilation.rb +55 -0
  11. data/lib/finitio/support/constraint.rb +46 -0
  12. data/lib/finitio/support/contract.rb +33 -0
  13. data/lib/finitio/support/dress_helper.rb +3 -2
  14. data/lib/finitio/support/heading.rb +57 -17
  15. data/lib/finitio/support/metadata.rb +20 -0
  16. data/lib/finitio/support/type_factory.rb +154 -41
  17. data/lib/finitio/syntax.rb +16 -31
  18. data/lib/finitio/syntax/expr.rb +56 -0
  19. data/lib/finitio/syntax/expr/arith_op.rb +22 -0
  20. data/lib/finitio/syntax/expr/comparison.rb +22 -0
  21. data/lib/finitio/syntax/expr/fn_call.rb +24 -0
  22. data/lib/finitio/syntax/expr/identifier.rb +18 -0
  23. data/lib/finitio/syntax/expr/literal.rb +19 -0
  24. data/lib/finitio/syntax/expr/logic_dyadic.rb +22 -0
  25. data/lib/finitio/syntax/expr/logic_not.rb +21 -0
  26. data/lib/finitio/syntax/expr/oo_call.rb +24 -0
  27. data/lib/finitio/syntax/expr/parenthesized.rb +20 -0
  28. data/lib/finitio/syntax/expr/unary_minus_op.rb +21 -0
  29. data/lib/finitio/syntax/expressions.citrus +129 -0
  30. data/lib/finitio/syntax/finitio.citrus +10 -208
  31. data/lib/finitio/syntax/finitio.sexp +5 -1
  32. data/lib/finitio/syntax/lexer.citrus +91 -0
  33. data/lib/finitio/syntax/literal.rb +16 -0
  34. data/lib/finitio/syntax/literal/boolean.rb +22 -0
  35. data/lib/finitio/syntax/literal/integer.rb +14 -0
  36. data/lib/finitio/syntax/literal/real.rb +14 -0
  37. data/lib/finitio/syntax/literal/string.rb +14 -0
  38. data/lib/finitio/syntax/literals.citrus +44 -0
  39. data/lib/finitio/syntax/node.rb +53 -0
  40. data/lib/finitio/syntax/type.rb +28 -0
  41. data/lib/finitio/syntax/type/ad_type.rb +29 -0
  42. data/lib/finitio/syntax/{any_type.rb → type/any_type.rb} +1 -1
  43. data/lib/finitio/syntax/type/attribute.rb +33 -0
  44. data/lib/finitio/syntax/{builtin_type.rb → type/builtin_type.rb} +3 -1
  45. data/lib/finitio/syntax/{constraint_def.rb → type/constraint_def.rb} +4 -3
  46. data/lib/finitio/syntax/type/constraints.rb +17 -0
  47. data/lib/finitio/syntax/{contract.rb → type/contract.rb} +9 -3
  48. data/lib/finitio/syntax/{definitions.rb → type/definitions.rb} +1 -0
  49. data/lib/finitio/syntax/{expression.rb → type/expression.rb} +2 -1
  50. data/lib/finitio/syntax/{external_pair.rb → type/external_pair.rb} +3 -1
  51. data/lib/finitio/syntax/type/heading.rb +30 -0
  52. data/lib/finitio/syntax/{inline_pair.rb → type/inline_pair.rb} +3 -1
  53. data/lib/finitio/syntax/{lambda_expr.rb → type/lambda_expr.rb} +3 -0
  54. data/lib/finitio/syntax/type/main_type.rb +18 -0
  55. data/lib/finitio/syntax/type/metadata.rb +18 -0
  56. data/lib/finitio/syntax/type/metadata_attr.rb +15 -0
  57. data/lib/finitio/syntax/{named_constraint.rb → type/named_constraint.rb} +10 -3
  58. data/lib/finitio/syntax/type/relation_type.rb +24 -0
  59. data/lib/finitio/syntax/{seq_type.rb → type/seq_type.rb} +3 -0
  60. data/lib/finitio/syntax/{set_type.rb → type/set_type.rb} +3 -0
  61. data/lib/finitio/syntax/type/struct_type.rb +17 -0
  62. data/lib/finitio/syntax/{sub_type.rb → type/sub_type.rb} +3 -0
  63. data/lib/finitio/syntax/{system.rb → type/system.rb} +5 -4
  64. data/lib/finitio/syntax/type/tuple_type.rb +24 -0
  65. data/lib/finitio/syntax/{type_def.rb → type/type_def.rb} +8 -3
  66. data/lib/finitio/syntax/{type_ref.rb → type/type_ref.rb} +4 -1
  67. data/lib/finitio/syntax/{union_type.rb → type/union_type.rb} +1 -0
  68. data/lib/finitio/syntax/{unnamed_constraint.rb → type/unnamed_constraint.rb} +7 -1
  69. data/lib/finitio/syntax/types.citrus +196 -0
  70. data/lib/finitio/system.rb +15 -15
  71. data/lib/finitio/type.rb +38 -6
  72. data/lib/finitio/type/ad_type.rb +41 -18
  73. data/lib/finitio/type/alias_type.rb +37 -0
  74. data/lib/finitio/type/any_type.rb +7 -3
  75. data/lib/finitio/type/builtin_type.rb +5 -4
  76. data/lib/finitio/{support → type}/collection_type.rb +3 -4
  77. data/lib/finitio/type/hash_based_type.rb +91 -0
  78. data/lib/finitio/type/heading_based_type.rb +28 -0
  79. data/lib/finitio/type/multi_relation_type.rb +34 -0
  80. data/lib/finitio/type/multi_tuple_type.rb +29 -0
  81. data/lib/finitio/type/proxy_type.rb +40 -0
  82. data/lib/finitio/type/rel_based_type.rb +42 -0
  83. data/lib/finitio/type/relation_type.rb +6 -47
  84. data/lib/finitio/type/seq_type.rb +4 -0
  85. data/lib/finitio/type/set_type.rb +4 -0
  86. data/lib/finitio/type/struct_type.rb +84 -0
  87. data/lib/finitio/type/sub_type.rb +25 -22
  88. data/lib/finitio/type/tuple_type.rb +6 -57
  89. data/lib/finitio/type/union_type.rb +12 -5
  90. data/lib/finitio/version.rb +2 -2
  91. data/spec/{unit/attribute → attribute}/test_equality.rb +8 -5
  92. data/spec/{unit/attribute → attribute}/test_fetch_on.rb +5 -5
  93. data/spec/attribute/test_initialize.rb +26 -0
  94. data/spec/attribute/test_optional.rb +18 -0
  95. data/spec/attribute/test_required.rb +18 -0
  96. data/spec/attribute/test_to_name.rb +20 -0
  97. data/spec/constraint/test_anonymous.rb +20 -0
  98. data/spec/constraint/test_equality.rb +39 -0
  99. data/spec/constraint/test_name.rb +20 -0
  100. data/spec/constraint/test_named.rb +20 -0
  101. data/spec/constraint/test_triple_equal.rb +13 -0
  102. data/spec/{unit/qrb/system.q → finitio/system.fio} +0 -0
  103. data/spec/{unit/qrb → finitio}/test_ast.rb +0 -0
  104. data/spec/finitio/test_parse.rb +23 -0
  105. data/spec/{unit/qrb/test_parse.rb → finitio/test_system.rb} +6 -6
  106. data/spec/heading/test_allow_extra.rb +24 -0
  107. data/spec/{unit/heading → heading}/test_each.rb +2 -2
  108. data/spec/heading/test_equality.rb +38 -0
  109. data/spec/heading/test_hash.rb +38 -0
  110. data/spec/heading/test_hash_get.rb +17 -0
  111. data/spec/{unit/heading → heading}/test_initialize.rb +2 -2
  112. data/spec/heading/test_multi.rb +57 -0
  113. data/spec/{unit/heading → heading}/test_size.rb +0 -0
  114. data/spec/heading/test_to_name.rb +58 -0
  115. data/spec/spec_helper.rb +17 -1
  116. data/spec/syntax/expr/test_free_variables.rb +46 -0
  117. data/spec/syntax/expr/test_to_proc_source.rb +43 -0
  118. data/spec/{unit/syntax → syntax}/nodes/test_ad_type.rb +26 -26
  119. data/spec/{unit/syntax → syntax}/nodes/test_any_type.rb +2 -2
  120. data/spec/syntax/nodes/test_attribute.rb +65 -0
  121. data/spec/{unit/syntax → syntax}/nodes/test_builtin_type.rb +5 -5
  122. data/spec/{unit/syntax → syntax}/nodes/test_comment.rb +1 -1
  123. data/spec/{unit/syntax → syntax}/nodes/test_constraint_def.rb +3 -8
  124. data/spec/{unit/syntax → syntax}/nodes/test_constraints.rb +21 -16
  125. data/spec/{unit/syntax → syntax}/nodes/test_contract.rb +28 -35
  126. data/spec/{unit/syntax → syntax}/nodes/test_expression.rb +13 -5
  127. data/spec/{unit/syntax → syntax}/nodes/test_heading.rb +25 -7
  128. data/spec/syntax/nodes/test_metadata.rb +28 -0
  129. data/spec/{unit/syntax → syntax}/nodes/test_named_constraint.rb +8 -8
  130. data/spec/syntax/nodes/test_relation_type.rb +84 -0
  131. data/spec/{unit/syntax → syntax}/nodes/test_seq_type.rb +4 -4
  132. data/spec/{unit/syntax → syntax}/nodes/test_set_type.rb +4 -4
  133. data/spec/{unit/syntax → syntax}/nodes/test_spacing.rb +1 -1
  134. data/spec/syntax/nodes/test_struct_type.rb +38 -0
  135. data/spec/{unit/syntax → syntax}/nodes/test_sub_type.rb +14 -14
  136. data/spec/{unit/syntax → syntax}/nodes/test_system.rb +3 -3
  137. data/spec/syntax/nodes/test_tuple_type.rb +94 -0
  138. data/spec/syntax/nodes/test_type_def.rb +57 -0
  139. data/spec/{unit/syntax → syntax}/nodes/test_type_ref.rb +3 -3
  140. data/spec/{unit/syntax → syntax}/nodes/test_union_type.rb +3 -3
  141. data/spec/{unit/syntax → syntax}/nodes/test_unnamed_constraint.rb +7 -7
  142. data/spec/syntax/test_compile.rb +41 -0
  143. data/spec/{unit/syntax → syntax}/test_compile_type.rb +1 -1
  144. data/spec/{unit/system → system}/test_add_type.rb +6 -6
  145. data/spec/{unit/system → system}/test_dsl.rb +2 -2
  146. data/spec/{unit/system → system}/test_dup.rb +4 -4
  147. data/spec/{unit/system → system}/test_fetch.rb +4 -4
  148. data/spec/{unit/system → system}/test_get_type.rb +2 -2
  149. data/spec/{unit/system → system}/test_initialize.rb +0 -0
  150. data/spec/test_finitio.rb +8 -0
  151. data/spec/{unit/type → type}/ad_type/test_default_name.rb +1 -2
  152. data/spec/{unit/type → type}/ad_type/test_dress.rb +19 -9
  153. data/spec/{unit/type → type}/ad_type/test_include.rb +3 -3
  154. data/spec/{unit/type → type}/ad_type/test_initialize.rb +15 -8
  155. data/spec/{unit/type → type}/ad_type/test_name.rb +2 -2
  156. data/spec/type/alias_type/test_default_name.rb +10 -0
  157. data/spec/type/alias_type/test_delegation.rb +29 -0
  158. data/spec/type/alias_type/test_name.rb +10 -0
  159. data/spec/{unit/type → type}/any_type/test_default_name.rb +1 -1
  160. data/spec/{unit/type → type}/any_type/test_dress.rb +0 -0
  161. data/spec/{unit/type → type}/any_type/test_equality.rb +4 -4
  162. data/spec/{unit/type → type}/any_type/test_include.rb +2 -2
  163. data/spec/{unit/type → type}/any_type/test_initialize.rb +0 -0
  164. data/spec/{unit/type → type}/any_type/test_name.rb +2 -2
  165. data/spec/{unit/type → type}/builtin_type/test_default_name.rb +1 -1
  166. data/spec/{unit/type → type}/builtin_type/test_dress.rb +3 -3
  167. data/spec/{unit/type → type}/builtin_type/test_equality.rb +4 -4
  168. data/spec/{unit/type → type}/builtin_type/test_include.rb +2 -2
  169. data/spec/{unit/type → type}/builtin_type/test_initialize.rb +1 -1
  170. data/spec/{unit/type → type}/builtin_type/test_name.rb +2 -2
  171. data/spec/type/multi_relation_type/test_default_name.rb +19 -0
  172. data/spec/type/multi_relation_type/test_dress.rb +206 -0
  173. data/spec/type/multi_relation_type/test_equality.rb +36 -0
  174. data/spec/type/multi_relation_type/test_include.rb +89 -0
  175. data/spec/type/multi_relation_type/test_initialize.rb +29 -0
  176. data/spec/type/multi_relation_type/test_name.rb +27 -0
  177. data/spec/type/multi_tuple_type/test_default_name.rb +17 -0
  178. data/spec/type/multi_tuple_type/test_dress.rb +146 -0
  179. data/spec/type/multi_tuple_type/test_equality.rb +32 -0
  180. data/spec/type/multi_tuple_type/test_include.rb +73 -0
  181. data/spec/type/multi_tuple_type/test_initialize.rb +30 -0
  182. data/spec/type/multi_tuple_type/test_name.rb +24 -0
  183. data/spec/type/proxy_type/test_delegation.rb +37 -0
  184. data/spec/type/proxy_type/test_resolve.rb +29 -0
  185. data/spec/{unit/type → type}/relation_type/test_default_name.rb +0 -0
  186. data/spec/{unit/type → type}/relation_type/test_dress.rb +24 -24
  187. data/spec/{unit/type → type}/relation_type/test_equality.rb +6 -6
  188. data/spec/{unit/type → type}/relation_type/test_include.rb +4 -4
  189. data/spec/{unit/type → type}/relation_type/test_initialize.rb +2 -2
  190. data/spec/{unit/type → type}/relation_type/test_name.rb +0 -0
  191. data/spec/{unit/type → type}/seq_type/test_default_name.rb +0 -0
  192. data/spec/{unit/type → type}/seq_type/test_dress.rb +5 -5
  193. data/spec/{unit/type → type}/seq_type/test_equality.rb +4 -4
  194. data/spec/{unit/type → type}/seq_type/test_include.rb +4 -4
  195. data/spec/{unit/type → type}/seq_type/test_initialize.rb +3 -3
  196. data/spec/{unit/type → type}/seq_type/test_name.rb +0 -0
  197. data/spec/{unit/type → type}/set_type/test_default_name.rb +0 -0
  198. data/spec/{unit/type → type}/set_type/test_dress.rb +8 -8
  199. data/spec/{unit/type → type}/set_type/test_equality.rb +4 -4
  200. data/spec/{unit/type → type}/set_type/test_include.rb +4 -4
  201. data/spec/{unit/type → type}/set_type/test_initialize.rb +3 -3
  202. data/spec/{unit/type → type}/set_type/test_name.rb +0 -0
  203. data/spec/type/struct_type/test_default_name.rb +10 -0
  204. data/spec/type/struct_type/test_dress.rb +105 -0
  205. data/spec/type/struct_type/test_equality.rb +28 -0
  206. data/spec/type/struct_type/test_include.rb +40 -0
  207. data/spec/type/struct_type/test_initialize.rb +22 -0
  208. data/spec/type/struct_type/test_name.rb +20 -0
  209. data/spec/{unit/type → type}/sub_type/test_default_name.rb +2 -2
  210. data/spec/{unit/type → type}/sub_type/test_dress.rb +14 -14
  211. data/spec/type/sub_type/test_equality.rb +46 -0
  212. data/spec/{unit/type → type}/sub_type/test_include.rb +6 -6
  213. data/spec/type/sub_type/test_initialize.rb +13 -0
  214. data/spec/{unit/type → type}/sub_type/test_name.rb +4 -4
  215. data/spec/{unit/type → type}/tuple_type/test_default_name.rb +0 -0
  216. data/spec/{unit/type → type}/tuple_type/test_dress.rb +18 -18
  217. data/spec/{unit/type → type}/tuple_type/test_equality.rb +6 -6
  218. data/spec/{unit/type → type}/tuple_type/test_include.rb +4 -4
  219. data/spec/{unit/type → type}/tuple_type/test_initialize.rb +4 -4
  220. data/spec/{unit/type → type}/tuple_type/test_name.rb +0 -0
  221. data/spec/{unit/type → type}/union_type/test_default_name.rb +0 -0
  222. data/spec/{unit/type → type}/union_type/test_dress.rb +7 -6
  223. data/spec/{unit/type → type}/union_type/test_equality.rb +7 -7
  224. data/spec/{unit/type → type}/union_type/test_include.rb +3 -3
  225. data/spec/{unit/type → type}/union_type/test_initialize.rb +3 -3
  226. data/spec/{unit/type → type}/union_type/test_name.rb +0 -0
  227. data/spec/{unit/type_factory → type_factory}/dsl/test_adt.rb +4 -4
  228. data/spec/{unit/type_factory → type_factory}/dsl/test_any.rb +1 -1
  229. data/spec/{unit/type_factory → type_factory}/dsl/test_attribute.rb +16 -2
  230. data/spec/{unit/type_factory → type_factory}/dsl/test_attributes.rb +1 -1
  231. data/spec/{unit/type_factory → type_factory}/dsl/test_builtin.rb +3 -3
  232. data/spec/type_factory/dsl/test_multi_relation.rb +39 -0
  233. data/spec/type_factory/dsl/test_multi_tuple.rb +37 -0
  234. data/spec/{unit/type_factory → type_factory}/dsl/test_relation.rb +6 -6
  235. data/spec/{unit/type_factory → type_factory}/dsl/test_seq.rb +4 -4
  236. data/spec/{unit/type_factory → type_factory}/dsl/test_set.rb +4 -4
  237. data/spec/type_factory/dsl/test_struct.rb +45 -0
  238. data/spec/{unit/type_factory → type_factory}/dsl/test_subtype.rb +10 -8
  239. data/spec/{unit/type_factory → type_factory}/dsl/test_tuple.rb +5 -5
  240. data/spec/{unit/type_factory → type_factory}/dsl/test_union.rb +6 -6
  241. data/spec/{unit/type_factory → type_factory}/factory/test_builtin.rb +1 -1
  242. data/spec/{unit/type_factory → type_factory}/factory/test_seq_type.rb +2 -2
  243. data/spec/{unit/type_factory → type_factory}/factory/test_set_type.rb +2 -2
  244. data/spec/type_factory/factory/test_struct_type.rb +18 -0
  245. data/spec/{unit/type_factory → type_factory}/factory/test_sub_type.rb +7 -7
  246. data/spec/{unit/type_factory → type_factory}/factory/test_tuple_type.rb +4 -4
  247. metadata +398 -286
  248. data/lib/finitio/data_type.rb +0 -29
  249. data/lib/finitio/syntax/ad_type.rb +0 -32
  250. data/lib/finitio/syntax/attribute.rb +0 -15
  251. data/lib/finitio/syntax/constraints.rb +0 -22
  252. data/lib/finitio/syntax/heading.rb +0 -19
  253. data/lib/finitio/syntax/relation_type.rb +0 -15
  254. data/lib/finitio/syntax/support.rb +0 -13
  255. data/lib/finitio/syntax/tuple_type.rb +0 -15
  256. data/spec/acceptance/Finitio/test_default.rb +0 -96
  257. data/spec/acceptance/Finitio/test_parsing.rb +0 -15
  258. data/spec/acceptance/ad_type/test_in_finitio.rb +0 -82
  259. data/spec/acceptance/ad_type/test_in_ruby.rb +0 -60
  260. data/spec/unit/attribute/test_initialize.rb +0 -13
  261. data/spec/unit/attribute/test_to_name.rb +0 -10
  262. data/spec/unit/heading/test_equality.rb +0 -28
  263. data/spec/unit/heading/test_to_name.rb +0 -32
  264. data/spec/unit/syntax/nodes/test_attribute.rb +0 -38
  265. data/spec/unit/syntax/nodes/test_relation_type.rb +0 -59
  266. data/spec/unit/syntax/nodes/test_tuple_type.rb +0 -59
  267. data/spec/unit/syntax/nodes/test_type_def.rb +0 -33
  268. data/spec/unit/test_finitio.rb +0 -15
  269. data/spec/unit/type/sub_type/test_equality.rb +0 -34
  270. data/spec/unit/type/sub_type/test_initialize.rb +0 -16
@@ -18,13 +18,13 @@ module Finitio
18
18
  let(:input){ '.Integer( i | i >= 0 )' }
19
19
 
20
20
  it 'compiles to a SubType' do
21
- compiled.should be_a(SubType)
22
- compiled.super_type.should be_a(BuiltinType)
23
- compiled.super_type.ruby_type.should be(Integer)
21
+ expect(compiled).to be_a(SubType)
22
+ expect(compiled.super_type).to be_a(BuiltinType)
23
+ expect(compiled.super_type.ruby_type).to be(Integer)
24
24
  end
25
25
 
26
26
  it 'has the expected AST' do
27
- ast.should eq([
27
+ expect(ast).to eq([
28
28
  :sub_type,
29
29
  [:builtin_type, "Integer"],
30
30
  [:constraint, "default", [:fn, [:parameters, "i"], [:source, "i >= 0"]]]
@@ -36,17 +36,17 @@ module Finitio
36
36
  let(:input){ '.Integer( i | positive: i >= 0 )' }
37
37
 
38
38
  it 'compiles to a SubType' do
39
- compiled.should be_a(SubType)
40
- compiled.super_type.should be_a(BuiltinType)
41
- compiled.super_type.ruby_type.should be(Integer)
39
+ expect(compiled).to be_a(SubType)
40
+ expect(compiled.super_type).to be_a(BuiltinType)
41
+ expect(compiled.super_type.ruby_type).to be(Integer)
42
42
  end
43
43
 
44
44
  it 'has the correct constraints' do
45
- compiled.constraints.keys.should eq([:positive])
45
+ expect(compiled.constraints.map(&:name)).to eq([:positive])
46
46
  end
47
47
 
48
48
  it 'has the expected AST' do
49
- ast.should eq([
49
+ expect(ast).to eq([
50
50
  :sub_type,
51
51
  [:builtin_type, "Integer"],
52
52
  [:constraint, "positive", [:fn, [:parameters, "i"], [:source, "i >= 0"]]]
@@ -58,17 +58,17 @@ module Finitio
58
58
  let(:input){ '.Integer( i | positive: i >= 0, small: i <= 255 )' }
59
59
 
60
60
  it 'compiles to a SubType' do
61
- compiled.should be_a(SubType)
62
- compiled.super_type.should be_a(BuiltinType)
63
- compiled.super_type.ruby_type.should be(Integer)
61
+ expect(compiled).to be_a(SubType)
62
+ expect(compiled.super_type).to be_a(BuiltinType)
63
+ expect(compiled.super_type.ruby_type).to be(Integer)
64
64
  end
65
65
 
66
66
  it 'has the correct constraints' do
67
- compiled.constraints.keys.should eq([:positive, :small])
67
+ expect(compiled.constraints.map(&:name)).to eq([:positive, :small])
68
68
  end
69
69
 
70
70
  it 'has the expected AST' do
71
- ast.should eq([
71
+ expect(ast).to eq([
72
72
  :sub_type,
73
73
  [:builtin_type, "Integer"],
74
74
  [:constraint, "positive", [:fn, [:parameters, "i"], [:source, "i >= 0"]]],
@@ -14,7 +14,7 @@ module Finitio
14
14
  let(:input){ "Int = .Integer\n{r: Int}" }
15
15
 
16
16
  it 'has the expected AST' do
17
- ast.should eq([
17
+ expect(ast).to eq([
18
18
  :system,
19
19
  [:type_def, "Int", [:builtin_type, "Integer"]],
20
20
  [:tuple_type, [:heading, [:attribute, "r", [:type_ref, "Int"]]]]
@@ -26,7 +26,7 @@ module Finitio
26
26
  let(:input){ "Int = .Integer" }
27
27
 
28
28
  it 'has the expected AST' do
29
- ast.should eq([
29
+ expect(ast).to eq([
30
30
  :system,
31
31
  [:type_def, "Int", [:builtin_type, "Integer"]]
32
32
  ])
@@ -37,7 +37,7 @@ module Finitio
37
37
  let(:input){ "{r: .Integer}" }
38
38
 
39
39
  it 'has the expected AST' do
40
- ast.should eq([
40
+ expect(ast).to eq([
41
41
  :system,
42
42
  [:tuple_type, [:heading, [:attribute, "r", [:builtin_type, "Integer"]]]]
43
43
  ])
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+ module Finitio
3
+ describe Syntax, "tuple_type" do
4
+
5
+ subject{
6
+ Syntax.parse(input, root: "tuple_type")
7
+ }
8
+
9
+ describe "compilation result" do
10
+ let(:compiled){
11
+ subject.compile(type_factory)
12
+ }
13
+
14
+ context 'empty heading' do
15
+ let(:input){ '{ }' }
16
+
17
+ it 'compiles to a TupleType' do
18
+ expect(compiled).to be_a(TupleType)
19
+ expect(compiled.heading).to be_empty
20
+ end
21
+ end
22
+
23
+ context '{a: .Integer}' do
24
+ let(:input){ '{a: .Integer}' }
25
+
26
+ it 'compiles to a TupleType' do
27
+ expect(compiled).to be_a(TupleType)
28
+ expect(compiled.heading.size).to eq(1)
29
+ end
30
+ end
31
+
32
+ context '{a: .Integer, b: .Float}' do
33
+ let(:input){ '{a: .Integer, b: .Float}' }
34
+
35
+ it 'compiles to a TupleType' do
36
+ expect(compiled).to be_a(TupleType)
37
+ expect(compiled.heading.size).to eq(2)
38
+ end
39
+ end
40
+
41
+ context '{a: .Integer, b :? .Float}' do
42
+ let(:input){ '{a: .Integer, b :? .Float}' }
43
+
44
+ it 'compiles to a MultiTupleType' do
45
+ expect(compiled).to be_a(MultiTupleType)
46
+ expect(compiled.heading.size).to eq(2)
47
+ end
48
+ end
49
+
50
+ context '{a: .Integer, ...}' do
51
+ let(:input){ '{a: .Integer, ...}' }
52
+
53
+ it 'compiles to a MultiTupleType' do
54
+ expect(compiled).to be_a(MultiTupleType)
55
+ expect(compiled.heading.size).to eq(1)
56
+ expect(compiled.heading).to be_allow_extra
57
+ end
58
+ end
59
+ end
60
+
61
+ describe "AST" do
62
+ let(:ast){ subject.to_ast }
63
+
64
+ context '{a: .Integer}' do
65
+ let(:input){ '{a: .Integer}' }
66
+
67
+ it{
68
+ expect(ast).to eq([
69
+ :tuple_type,
70
+ [
71
+ :heading,
72
+ [ :attribute, "a", [:builtin_type, "Integer" ]]
73
+ ]
74
+ ])
75
+ }
76
+ end
77
+
78
+ context '{a :? .Integer}' do
79
+ let(:input){ '{a :? .Integer}' }
80
+
81
+ it{
82
+ expect(ast).to eq([
83
+ :multi_tuple_type,
84
+ [
85
+ :heading,
86
+ [ :attribute, "a", [:builtin_type, "Integer" ], false]
87
+ ]
88
+ ])
89
+ }
90
+ end
91
+ end
92
+
93
+ end
94
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+ module Finitio
3
+ describe Syntax, "type_def" do
4
+
5
+ subject{
6
+ Syntax.parse(input, root: "type_def")
7
+ }
8
+
9
+ let(:sys){
10
+ system
11
+ }
12
+
13
+ let(:compiled){
14
+ subject.compile(sys)
15
+ }
16
+
17
+ let(:ast){
18
+ subject.to_ast
19
+ }
20
+
21
+ context 'when referening an anonymous type' do
22
+ let(:input){ 'Int = .Integer' }
23
+
24
+ it 'add the type to the system' do
25
+ compiled
26
+ expect(sys["Int"]).to be_a(BuiltinType)
27
+ end
28
+
29
+ it 'has the expected AST' do
30
+ expect(ast).to eq([:type_def, "Int", [:builtin_type, "Integer"]])
31
+ end
32
+ end
33
+
34
+ context 'when making an alias' do
35
+ let(:legacy) {
36
+ BuiltinType.new(Integer, "Int")
37
+ }
38
+
39
+ let(:input){ 'Alias = Int' }
40
+
41
+ before do
42
+ sys.add_type(legacy)
43
+ end
44
+
45
+ it 'add the type to the system' do
46
+ compiled
47
+ expect(sys["Alias"]).to be_a(AliasType)
48
+ expect(sys["Alias"]).to eq(legacy)
49
+ end
50
+
51
+ it 'has the expected AST' do
52
+ expect(ast).to eq([:type_def, "Alias", [:type_ref, "Int"]])
53
+ end
54
+ end
55
+
56
+ end
57
+ end
@@ -25,12 +25,12 @@ module Finitio
25
25
  let(:input){ 'Int' }
26
26
 
27
27
  it 'compiles to a the BuiltinType' do
28
- compiled.should be_a(BuiltinType)
29
- compiled.name.should eq("Int")
28
+ expect(compiled).to be_a(BuiltinType)
29
+ expect(compiled.name).to eq("Int")
30
30
  end
31
31
 
32
32
  it 'has the expected AST' do
33
- ast.should eq([:type_ref, "Int"])
33
+ expect(ast).to eq([:type_ref, "Int"])
34
34
  end
35
35
 
36
36
  end
@@ -15,8 +15,8 @@ module Finitio
15
15
  let(:input){ '.Integer|.Float' }
16
16
 
17
17
  it 'compiles to a UnionType' do
18
- compiled.should be_a(UnionType)
19
- compiled.should eq(UnionType.new([intType, floatType]))
18
+ expect(compiled).to be_a(UnionType)
19
+ expect(compiled).to eq(UnionType.new([intType, floatType]))
20
20
  end
21
21
  end
22
22
  end
@@ -26,7 +26,7 @@ module Finitio
26
26
 
27
27
  let(:ast){ subject.to_ast }
28
28
 
29
- it{ ast.should eq([
29
+ it{ expect(ast).to eq([
30
30
  :union_type,
31
31
  [:builtin_type, "Integer"],
32
32
  [:builtin_type, "Float"]
@@ -17,21 +17,21 @@ module Finitio
17
17
  context 'a >= 10' do
18
18
  let(:input){ 'a >= 10' }
19
19
 
20
- it 'compiles to an Hash' do
21
- compiled.should be_a(Hash)
20
+ it 'compiles to an Constraint' do
21
+ expect(compiled).to be_a(Constraint)
22
22
  end
23
23
 
24
- it 'has expected keys' do
25
- compiled.keys.should eq([:predicate])
24
+ it 'is anonymous' do
25
+ expect(compiled).to be_anonymous
26
26
  end
27
27
 
28
28
  it 'should be the correct Proc' do
29
- compiled[:predicate].call(12).should be_true
30
- compiled[:predicate].call(9).should be_false
29
+ expect(compiled.===(12)).to eq(true)
30
+ expect(compiled.===(9)).to eq(false)
31
31
  end
32
32
 
33
33
  it 'has the expected AST' do
34
- ast.should eq([
34
+ expect(ast).to eq([
35
35
  :constraint,
36
36
  "default",
37
37
  [:fn, [:parameters, "a"], [:source, "a >= 10"]]
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+ module Finitio
3
+ describe Syntax, '.compile' do
4
+
5
+ subject do
6
+ Syntax.compile(source)
7
+ end
8
+
9
+ context 'with a single main type' do
10
+ let(:source){
11
+ <<-EOF.strip
12
+ .Integer
13
+ EOF
14
+ }
15
+
16
+ it{ should be_a(System) }
17
+
18
+ it 'should have main type' do
19
+ expect(subject.main).to be_a(BuiltinType)
20
+ expect(subject['Main']).to be(subject.main)
21
+ end
22
+ end
23
+
24
+ context 'with a single main alias type' do
25
+ let(:source){
26
+ <<-EOF.strip
27
+ Int = .Integer
28
+ Int
29
+ EOF
30
+ }
31
+
32
+ it{ should be_a(System) }
33
+
34
+ it 'should have main type' do
35
+ expect(subject.main).to be_a(AliasType)
36
+ expect(subject['Main']).to be(subject.main)
37
+ end
38
+ end
39
+
40
+ end
41
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
  module Finitio
3
- describe Syntax, '.compile' do
3
+ describe Syntax, '.compile_type' do
4
4
 
5
5
  let(:source){
6
6
  <<-EOF.strip
@@ -10,12 +10,12 @@ module Finitio
10
10
  let(:type){ intType }
11
11
 
12
12
  it 'should return the created type' do
13
- subject.should be(type)
13
+ expect(subject).to be(type)
14
14
  end
15
15
 
16
16
  it 'should add the type' do
17
17
  subject
18
- system[type.name].should be(type)
18
+ expect(system[type.name]).to be(type)
19
19
  end
20
20
  end
21
21
 
@@ -23,9 +23,9 @@ module Finitio
23
23
  let(:type){ "foo" }
24
24
 
25
25
  it 'should raise an error' do
26
- ->{
26
+ expect{
27
27
  subject
28
- }.should raise_error(ArgumentError, "Finitio::Type expected, got `foo`")
28
+ }.to raise_error(ArgumentError, "Unable to factor a Finitio::Type from `foo`")
29
29
  end
30
30
  end
31
31
 
@@ -37,9 +37,9 @@ module Finitio
37
37
  end
38
38
 
39
39
  it 'should raise an error' do
40
- ->{
40
+ expect{
41
41
  subject
42
- }.should raise_error(Finitio::Error, "Duplicate type name `intType`")
42
+ }.to raise_error(Finitio::Error, "Duplicate type name `intType`")
43
43
  end
44
44
  end
45
45
 
@@ -20,9 +20,9 @@ module Finitio
20
20
  it{ should be_a(SubType) }
21
21
 
22
22
  it 'should apply the constraint' do
23
- ->{
23
+ expect{
24
24
  subject.dress(-9)
25
- }.should raise_error(TypeError)
25
+ }.to raise_error(TypeError)
26
26
  end
27
27
  end
28
28
 
@@ -13,17 +13,17 @@ module Finitio
13
13
  it{ should be_a(System) }
14
14
 
15
15
  it 'should not be the same object' do
16
- subject.should_not be(system)
16
+ expect(subject).not_to be(system)
17
17
  end
18
18
 
19
19
  it 'should have intType' do
20
- subject['intType'].should eq(intType)
20
+ expect(subject['intType']).to eq(intType)
21
21
  end
22
22
 
23
23
  it 'should not share internals with the original' do
24
24
  subject.add_type(floatType)
25
- subject['floatType'].should_not be_nil
26
- system['floatType'].should be_nil
25
+ expect(subject['floatType']).not_to be_nil
26
+ expect(system['floatType']).to be_nil
27
27
  end
28
28
 
29
29
  end
@@ -14,7 +14,7 @@ module Finitio
14
14
  let(:name){ "intType" }
15
15
 
16
16
  it 'should return the type' do
17
- subject.should eq(intType)
17
+ expect(subject).to eq(intType)
18
18
  end
19
19
  end
20
20
 
@@ -22,9 +22,9 @@ module Finitio
22
22
  let(:name){ "noSuchOne" }
23
23
 
24
24
  it 'should raise an error' do
25
- ->{
25
+ expect{
26
26
  subject
27
- }.should raise_error(KeyError, /noSuchOne/)
27
+ }.to raise_error(KeyError, /noSuchOne/)
28
28
  end
29
29
  end
30
30
 
@@ -34,7 +34,7 @@ module Finitio
34
34
  }
35
35
 
36
36
  it 'should yield the block' do
37
- subject.should eq("bar")
37
+ expect(subject).to eq("bar")
38
38
  end
39
39
  end
40
40