qrb 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/CHANGELOG.md +7 -0
  2. data/Gemfile.lock +1 -1
  3. data/README.md +30 -1
  4. data/lib/qrb.rb +6 -0
  5. data/lib/qrb/data_type.rb +7 -1
  6. data/lib/qrb/support/dress_helper.rb +1 -1
  7. data/lib/qrb/support/type_factory.rb +6 -0
  8. data/lib/qrb/syntax.rb +7 -0
  9. data/lib/qrb/syntax/ad_type.rb +7 -0
  10. data/lib/qrb/syntax/any_type.rb +16 -0
  11. data/lib/qrb/syntax/attribute.rb +4 -0
  12. data/lib/qrb/syntax/builtin_type.rb +4 -0
  13. data/lib/qrb/syntax/constraint_def.rb +6 -0
  14. data/lib/qrb/syntax/constraints.rb +4 -0
  15. data/lib/qrb/syntax/contract.rb +21 -9
  16. data/lib/qrb/syntax/definitions.rb +4 -0
  17. data/lib/qrb/syntax/external_pair.rb +17 -0
  18. data/lib/qrb/syntax/heading.rb +4 -0
  19. data/lib/qrb/syntax/inline_pair.rb +16 -0
  20. data/lib/qrb/syntax/lambda_expr.rb +4 -0
  21. data/lib/qrb/syntax/named_constraint.rb +6 -0
  22. data/lib/qrb/syntax/q.citrus +29 -4
  23. data/lib/qrb/syntax/q.sexp +114 -0
  24. data/lib/qrb/syntax/relation_type.rb +4 -0
  25. data/lib/qrb/syntax/seq_type.rb +4 -0
  26. data/lib/qrb/syntax/set_type.rb +4 -0
  27. data/lib/qrb/syntax/sub_type.rb +4 -0
  28. data/lib/qrb/syntax/system.rb +6 -0
  29. data/lib/qrb/syntax/tuple_type.rb +4 -0
  30. data/lib/qrb/syntax/type_def.rb +4 -0
  31. data/lib/qrb/syntax/type_ref.rb +4 -0
  32. data/lib/qrb/syntax/union_type.rb +4 -0
  33. data/lib/qrb/syntax/unnamed_constraint.rb +6 -0
  34. data/lib/qrb/type.rb +1 -0
  35. data/lib/qrb/type/ad_type.rb +8 -7
  36. data/lib/qrb/type/any_type.rb +47 -0
  37. data/lib/qrb/version.rb +1 -1
  38. data/spec/spec_helper.rb +11 -0
  39. data/spec/unit/qrb/test_ast.rb +43 -0
  40. data/spec/unit/syntax/nodes/test_ad_type.rb +72 -0
  41. data/spec/unit/syntax/nodes/test_any_type.rb +30 -0
  42. data/spec/unit/syntax/nodes/test_attribute.rb +23 -10
  43. data/spec/unit/syntax/nodes/test_builtin_type.rb +25 -13
  44. data/spec/unit/syntax/nodes/test_constraint_def.rb +14 -0
  45. data/spec/unit/syntax/nodes/test_constraints.rb +35 -0
  46. data/spec/unit/syntax/nodes/test_contract.rb +76 -4
  47. data/spec/unit/syntax/nodes/test_heading.rb +37 -20
  48. data/spec/unit/syntax/nodes/test_named_constraint.rb +12 -0
  49. data/spec/unit/syntax/nodes/test_relation_type.rb +38 -20
  50. data/spec/unit/syntax/nodes/test_seq_type.rb +23 -9
  51. data/spec/unit/syntax/nodes/test_set_type.rb +23 -9
  52. data/spec/unit/syntax/nodes/test_sub_type.rb +29 -0
  53. data/spec/unit/syntax/nodes/test_system.rb +48 -0
  54. data/spec/unit/syntax/nodes/test_tuple_type.rb +38 -20
  55. data/spec/unit/syntax/nodes/test_type_def.rb +33 -0
  56. data/spec/unit/syntax/nodes/test_type_ref.rb +37 -0
  57. data/spec/unit/syntax/nodes/test_union_type.rb +23 -8
  58. data/spec/unit/syntax/nodes/test_unnamed_constraint.rb +12 -0
  59. data/spec/unit/type/ad_type/test_default_name.rb +2 -2
  60. data/spec/unit/type/ad_type/test_dress.rb +3 -3
  61. data/spec/unit/type/ad_type/test_initialize.rb +2 -2
  62. data/spec/unit/type/any_type/test_default_name.rb +12 -0
  63. data/spec/unit/type/any_type/test_dress.rb +22 -0
  64. data/spec/unit/type/any_type/test_equality.rb +26 -0
  65. data/spec/unit/type/any_type/test_include.rb +22 -0
  66. data/spec/unit/type/any_type/test_initialize.rb +10 -0
  67. data/spec/unit/type/any_type/test_name.rb +24 -0
  68. data/spec/unit/type_factory/dsl/test_adt.rb +2 -2
  69. data/spec/unit/type_factory/dsl/test_any.rb +28 -0
  70. metadata +33 -4
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+ module Qrb
3
+ describe AnyType, "default_name" do
4
+
5
+ let(:type){ AnyType.new }
6
+
7
+ it 'uses Any' do
8
+ type.default_name.should eq("Any")
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ module Qrb
3
+ describe AnyType, "dress" do
4
+
5
+ let(:type){ AnyType.new }
6
+
7
+ subject{ type.dress(arg) }
8
+
9
+ context 'with nil' do
10
+ let(:arg){ nil }
11
+
12
+ it{ should be(arg) }
13
+ end
14
+
15
+ context 'with a Float' do
16
+ let(:arg){ 12.0 }
17
+
18
+ it{ should be(arg) }
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+ module Qrb
3
+ describe AnyType, "equality" do
4
+
5
+ let(:anyType) { AnyType.new }
6
+ let(:anyType2){ AnyType.new("foo") }
7
+ let(:fltType) { BuiltinType.new(Float) }
8
+
9
+ it 'should apply structural equality' do
10
+ (anyType == anyType2).should be_true
11
+ end
12
+
13
+ it 'should apply distinguish different types' do
14
+ (anyType == fltType).should be_false
15
+ end
16
+
17
+ it 'should be a total function, with nil for non types' do
18
+ (anyType == 12).should be_false
19
+ end
20
+
21
+ it 'should implement hash accordingly' do
22
+ (anyType.hash == anyType2.hash).should be_true
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ module Qrb
3
+ describe AnyType, "include?" do
4
+
5
+ let(:type){ AnyType.new }
6
+
7
+ subject{ type.include?(arg) }
8
+
9
+ context 'with nil' do
10
+ let(:arg){ nil }
11
+
12
+ it{ should be_true }
13
+ end
14
+
15
+ context 'when an Integer' do
16
+ let(:arg){ 12 }
17
+
18
+ it{ should be_true }
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ module Qrb
3
+ describe AnyType, "initialize" do
4
+
5
+ let(:type){ AnyType.new }
6
+
7
+ it{ should be_a(AnyType) }
8
+
9
+ end
10
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ module Qrb
3
+ describe AnyType, "name" do
4
+
5
+ subject{ type.name }
6
+
7
+ context 'when not provided' do
8
+ let(:type){ AnyType.new }
9
+
10
+ it 'uses the default name' do
11
+ subject.should eq("Any")
12
+ end
13
+ end
14
+
15
+ context 'when provided' do
16
+ let(:type){ AnyType.new("foo") }
17
+
18
+ it 'uses the specified name' do
19
+ subject.should eq("foo")
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -5,8 +5,8 @@ module Qrb
5
5
  let(:factory){ TypeFactory.new }
6
6
 
7
7
  let(:contracts){
8
- { rgb: [intType, Color.method(:rgb) ],
9
- hex: [floatType, Color.method(:hex) ]}
8
+ { rgb: [intType, Color.method(:rgb), Qrb::IDENTITY ],
9
+ hex: [floatType, Color.method(:hex), Qrb::IDENTITY ]}
10
10
  }
11
11
 
12
12
  shared_examples_for "The <Color> type" do
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ module Qrb
3
+ describe TypeFactory, "DSL#any" do
4
+
5
+ let(:factory){ TypeFactory.new }
6
+
7
+ context 'without a name' do
8
+ subject do
9
+ factory.any
10
+ end
11
+
12
+ it{ should be_a(AnyType) }
13
+ end
14
+
15
+ context 'with a name' do
16
+ subject do
17
+ factory.any("foo")
18
+ end
19
+
20
+ it{ should be_a(AnyType) }
21
+
22
+ it 'should have the name' do
23
+ subject.name.should eq('foo')
24
+ end
25
+ end
26
+
27
+ end
28
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-04 00:00:00.000000000 Z
12
+ date: 2014-03-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: citrus
@@ -50,6 +50,7 @@ files:
50
50
  - lib/qrb/support/type_factory.rb
51
51
  - lib/qrb/support.rb
52
52
  - lib/qrb/syntax/ad_type.rb
53
+ - lib/qrb/syntax/any_type.rb
53
54
  - lib/qrb/syntax/attribute.rb
54
55
  - lib/qrb/syntax/builtin_type.rb
55
56
  - lib/qrb/syntax/constraint_def.rb
@@ -57,10 +58,13 @@ files:
57
58
  - lib/qrb/syntax/contract.rb
58
59
  - lib/qrb/syntax/definitions.rb
59
60
  - lib/qrb/syntax/expression.rb
61
+ - lib/qrb/syntax/external_pair.rb
60
62
  - lib/qrb/syntax/heading.rb
63
+ - lib/qrb/syntax/inline_pair.rb
61
64
  - lib/qrb/syntax/lambda_expr.rb
62
65
  - lib/qrb/syntax/named_constraint.rb
63
66
  - lib/qrb/syntax/q.citrus
67
+ - lib/qrb/syntax/q.sexp
64
68
  - lib/qrb/syntax/relation_type.rb
65
69
  - lib/qrb/syntax/seq_type.rb
66
70
  - lib/qrb/syntax/set_type.rb
@@ -75,6 +79,7 @@ files:
75
79
  - lib/qrb/syntax.rb
76
80
  - lib/qrb/system.rb
77
81
  - lib/qrb/type/ad_type.rb
82
+ - lib/qrb/type/any_type.rb
78
83
  - lib/qrb/type/builtin_type.rb
79
84
  - lib/qrb/type/relation_type.rb
80
85
  - lib/qrb/type/seq_type.rb
@@ -104,8 +109,10 @@ files:
104
109
  - spec/unit/heading/test_initialize.rb
105
110
  - spec/unit/heading/test_size.rb
106
111
  - spec/unit/heading/test_to_name.rb
112
+ - spec/unit/qrb/test_ast.rb
107
113
  - spec/unit/qrb/test_parse.rb
108
114
  - spec/unit/syntax/nodes/test_ad_type.rb
115
+ - spec/unit/syntax/nodes/test_any_type.rb
109
116
  - spec/unit/syntax/nodes/test_attribute.rb
110
117
  - spec/unit/syntax/nodes/test_builtin_type.rb
111
118
  - spec/unit/syntax/nodes/test_comment.rb
@@ -120,7 +127,10 @@ files:
120
127
  - spec/unit/syntax/nodes/test_set_type.rb
121
128
  - spec/unit/syntax/nodes/test_spacing.rb
122
129
  - spec/unit/syntax/nodes/test_sub_type.rb
130
+ - spec/unit/syntax/nodes/test_system.rb
123
131
  - spec/unit/syntax/nodes/test_tuple_type.rb
132
+ - spec/unit/syntax/nodes/test_type_def.rb
133
+ - spec/unit/syntax/nodes/test_type_ref.rb
124
134
  - spec/unit/syntax/nodes/test_union_type.rb
125
135
  - spec/unit/syntax/nodes/test_unnamed_constraint.rb
126
136
  - spec/unit/syntax/test_compile_type.rb
@@ -136,6 +146,12 @@ files:
136
146
  - spec/unit/type/ad_type/test_include.rb
137
147
  - spec/unit/type/ad_type/test_initialize.rb
138
148
  - spec/unit/type/ad_type/test_name.rb
149
+ - spec/unit/type/any_type/test_default_name.rb
150
+ - spec/unit/type/any_type/test_dress.rb
151
+ - spec/unit/type/any_type/test_equality.rb
152
+ - spec/unit/type/any_type/test_include.rb
153
+ - spec/unit/type/any_type/test_initialize.rb
154
+ - spec/unit/type/any_type/test_name.rb
139
155
  - spec/unit/type/builtin_type/test_default_name.rb
140
156
  - spec/unit/type/builtin_type/test_dress.rb
141
157
  - spec/unit/type/builtin_type/test_equality.rb
@@ -179,6 +195,7 @@ files:
179
195
  - spec/unit/type/union_type/test_initialize.rb
180
196
  - spec/unit/type/union_type/test_name.rb
181
197
  - spec/unit/type_factory/dsl/test_adt.rb
198
+ - spec/unit/type_factory/dsl/test_any.rb
182
199
  - spec/unit/type_factory/dsl/test_attribute.rb
183
200
  - spec/unit/type_factory/dsl/test_attributes.rb
184
201
  - spec/unit/type_factory/dsl/test_builtin.rb
@@ -209,7 +226,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
209
226
  version: '0'
210
227
  segments:
211
228
  - 0
212
- hash: 2788335618468865925
229
+ hash: -992957242747860523
213
230
  required_rubygems_version: !ruby/object:Gem::Requirement
214
231
  none: false
215
232
  requirements:
@@ -218,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
218
235
  version: '0'
219
236
  segments:
220
237
  - 0
221
- hash: 2788335618468865925
238
+ hash: -992957242747860523
222
239
  requirements: []
223
240
  rubyforge_project:
224
241
  rubygems_version: 1.8.25
@@ -240,8 +257,10 @@ test_files:
240
257
  - spec/unit/heading/test_initialize.rb
241
258
  - spec/unit/heading/test_size.rb
242
259
  - spec/unit/heading/test_to_name.rb
260
+ - spec/unit/qrb/test_ast.rb
243
261
  - spec/unit/qrb/test_parse.rb
244
262
  - spec/unit/syntax/nodes/test_ad_type.rb
263
+ - spec/unit/syntax/nodes/test_any_type.rb
245
264
  - spec/unit/syntax/nodes/test_attribute.rb
246
265
  - spec/unit/syntax/nodes/test_builtin_type.rb
247
266
  - spec/unit/syntax/nodes/test_comment.rb
@@ -256,7 +275,10 @@ test_files:
256
275
  - spec/unit/syntax/nodes/test_set_type.rb
257
276
  - spec/unit/syntax/nodes/test_spacing.rb
258
277
  - spec/unit/syntax/nodes/test_sub_type.rb
278
+ - spec/unit/syntax/nodes/test_system.rb
259
279
  - spec/unit/syntax/nodes/test_tuple_type.rb
280
+ - spec/unit/syntax/nodes/test_type_def.rb
281
+ - spec/unit/syntax/nodes/test_type_ref.rb
260
282
  - spec/unit/syntax/nodes/test_union_type.rb
261
283
  - spec/unit/syntax/nodes/test_unnamed_constraint.rb
262
284
  - spec/unit/syntax/test_compile_type.rb
@@ -272,6 +294,12 @@ test_files:
272
294
  - spec/unit/type/ad_type/test_include.rb
273
295
  - spec/unit/type/ad_type/test_initialize.rb
274
296
  - spec/unit/type/ad_type/test_name.rb
297
+ - spec/unit/type/any_type/test_default_name.rb
298
+ - spec/unit/type/any_type/test_dress.rb
299
+ - spec/unit/type/any_type/test_equality.rb
300
+ - spec/unit/type/any_type/test_include.rb
301
+ - spec/unit/type/any_type/test_initialize.rb
302
+ - spec/unit/type/any_type/test_name.rb
275
303
  - spec/unit/type/builtin_type/test_default_name.rb
276
304
  - spec/unit/type/builtin_type/test_dress.rb
277
305
  - spec/unit/type/builtin_type/test_equality.rb
@@ -315,6 +343,7 @@ test_files:
315
343
  - spec/unit/type/union_type/test_initialize.rb
316
344
  - spec/unit/type/union_type/test_name.rb
317
345
  - spec/unit/type_factory/dsl/test_adt.rb
346
+ - spec/unit/type_factory/dsl/test_any.rb
318
347
  - spec/unit/type_factory/dsl/test_attribute.rb
319
348
  - spec/unit/type_factory/dsl/test_attributes.rb
320
349
  - spec/unit/type_factory/dsl/test_builtin.rb