qrb 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +58 -0
- data/LICENCE.md +22 -0
- data/Manifest.txt +11 -0
- data/README.md +118 -0
- data/Rakefile +11 -0
- data/lib/qrb/Q/default.q +29 -0
- data/lib/qrb/data_type.rb +23 -0
- data/lib/qrb/errors.rb +23 -0
- data/lib/qrb/support/attribute.rb +53 -0
- data/lib/qrb/support/collection_type.rb +25 -0
- data/lib/qrb/support/dress_helper.rb +68 -0
- data/lib/qrb/support/heading.rb +57 -0
- data/lib/qrb/support/type_factory.rb +178 -0
- data/lib/qrb/support.rb +5 -0
- data/lib/qrb/syntax/ad_type.rb +25 -0
- data/lib/qrb/syntax/attribute.rb +11 -0
- data/lib/qrb/syntax/builtin_type.rb +13 -0
- data/lib/qrb/syntax/constraint_def.rb +11 -0
- data/lib/qrb/syntax/constraints.rb +18 -0
- data/lib/qrb/syntax/contract.rb +25 -0
- data/lib/qrb/syntax/definitions.rb +14 -0
- data/lib/qrb/syntax/expression.rb +12 -0
- data/lib/qrb/syntax/heading.rb +15 -0
- data/lib/qrb/syntax/lambda_expr.rb +11 -0
- data/lib/qrb/syntax/named_constraint.rb +11 -0
- data/lib/qrb/syntax/q.citrus +195 -0
- data/lib/qrb/syntax/relation_type.rb +11 -0
- data/lib/qrb/syntax/seq_type.rb +12 -0
- data/lib/qrb/syntax/set_type.rb +12 -0
- data/lib/qrb/syntax/sub_type.rb +13 -0
- data/lib/qrb/syntax/support.rb +13 -0
- data/lib/qrb/syntax/system.rb +15 -0
- data/lib/qrb/syntax/tuple_type.rb +11 -0
- data/lib/qrb/syntax/type_def.rb +14 -0
- data/lib/qrb/syntax/type_ref.rb +13 -0
- data/lib/qrb/syntax/union_type.rb +12 -0
- data/lib/qrb/syntax/unnamed_constraint.rb +11 -0
- data/lib/qrb/syntax.rb +42 -0
- data/lib/qrb/system.rb +63 -0
- data/lib/qrb/type/ad_type.rb +111 -0
- data/lib/qrb/type/builtin_type.rb +56 -0
- data/lib/qrb/type/relation_type.rb +81 -0
- data/lib/qrb/type/seq_type.rb +51 -0
- data/lib/qrb/type/set_type.rb +52 -0
- data/lib/qrb/type/sub_type.rb +94 -0
- data/lib/qrb/type/tuple_type.rb +99 -0
- data/lib/qrb/type/union_type.rb +78 -0
- data/lib/qrb/type.rb +63 -0
- data/lib/qrb/version.rb +14 -0
- data/lib/qrb.rb +63 -0
- data/qrb.gemspec +186 -0
- data/spec/acceptance/Q/test_default.rb +96 -0
- data/spec/acceptance/Q/test_parsing.rb +15 -0
- data/spec/acceptance/ad_type/test_in_q.rb +82 -0
- data/spec/acceptance/ad_type/test_in_ruby.rb +60 -0
- data/spec/spec_helper.rb +68 -0
- data/spec/unit/attribute/test_equality.rb +26 -0
- data/spec/unit/attribute/test_fetch_on.rb +50 -0
- data/spec/unit/attribute/test_initialize.rb +13 -0
- data/spec/unit/attribute/test_to_name.rb +10 -0
- data/spec/unit/heading/test_each.rb +28 -0
- data/spec/unit/heading/test_equality.rb +28 -0
- data/spec/unit/heading/test_initialize.rb +36 -0
- data/spec/unit/heading/test_size.rb +30 -0
- data/spec/unit/heading/test_to_name.rb +32 -0
- data/spec/unit/qrb/test_parse.rb +18 -0
- data/spec/unit/syntax/nodes/test_ad_type.rb +94 -0
- data/spec/unit/syntax/nodes/test_attribute.rb +25 -0
- data/spec/unit/syntax/nodes/test_builtin_type.rb +32 -0
- data/spec/unit/syntax/nodes/test_comment.rb +26 -0
- data/spec/unit/syntax/nodes/test_constraint_def.rb +27 -0
- data/spec/unit/syntax/nodes/test_constraints.rb +51 -0
- data/spec/unit/syntax/nodes/test_contract.rb +62 -0
- data/spec/unit/syntax/nodes/test_expression.rb +43 -0
- data/spec/unit/syntax/nodes/test_heading.rb +41 -0
- data/spec/unit/syntax/nodes/test_named_constraint.rb +31 -0
- data/spec/unit/syntax/nodes/test_relation_type.rb +41 -0
- data/spec/unit/syntax/nodes/test_seq_type.rb +24 -0
- data/spec/unit/syntax/nodes/test_set_type.rb +24 -0
- data/spec/unit/syntax/nodes/test_spacing.rb +25 -0
- data/spec/unit/syntax/nodes/test_sub_type.rb +52 -0
- data/spec/unit/syntax/nodes/test_tuple_type.rb +41 -0
- data/spec/unit/syntax/nodes/test_union_type.rb +23 -0
- data/spec/unit/syntax/nodes/test_unnamed_constraint.rb +31 -0
- data/spec/unit/syntax/test_compile_type.rb +22 -0
- data/spec/unit/system/test_add_type.rb +47 -0
- data/spec/unit/system/test_dsl.rb +30 -0
- data/spec/unit/system/test_dup.rb +30 -0
- data/spec/unit/system/test_fetch.rb +42 -0
- data/spec/unit/system/test_get_type.rb +30 -0
- data/spec/unit/system/test_initialize.rb +10 -0
- data/spec/unit/test_qrb.rb +15 -0
- data/spec/unit/type/ad_type/test_default_name.rb +15 -0
- data/spec/unit/type/ad_type/test_dress.rb +55 -0
- data/spec/unit/type/ad_type/test_include.rb +22 -0
- data/spec/unit/type/ad_type/test_initialize.rb +40 -0
- data/spec/unit/type/ad_type/test_name.rb +20 -0
- data/spec/unit/type/builtin_type/test_default_name.rb +12 -0
- data/spec/unit/type/builtin_type/test_dress.rb +33 -0
- data/spec/unit/type/builtin_type/test_equality.rb +26 -0
- data/spec/unit/type/builtin_type/test_include.rb +22 -0
- data/spec/unit/type/builtin_type/test_initialize.rb +12 -0
- data/spec/unit/type/builtin_type/test_name.rb +24 -0
- data/spec/unit/type/relation_type/test_default_name.rb +16 -0
- data/spec/unit/type/relation_type/test_dress.rb +164 -0
- data/spec/unit/type/relation_type/test_equality.rb +32 -0
- data/spec/unit/type/relation_type/test_include.rb +46 -0
- data/spec/unit/type/relation_type/test_initialize.rb +26 -0
- data/spec/unit/type/relation_type/test_name.rb +24 -0
- data/spec/unit/type/seq_type/test_default_name.rb +14 -0
- data/spec/unit/type/seq_type/test_dress.rb +49 -0
- data/spec/unit/type/seq_type/test_equality.rb +26 -0
- data/spec/unit/type/seq_type/test_include.rb +43 -0
- data/spec/unit/type/seq_type/test_initialize.rb +28 -0
- data/spec/unit/type/seq_type/test_name.rb +24 -0
- data/spec/unit/type/set_type/test_default_name.rb +14 -0
- data/spec/unit/type/set_type/test_dress.rb +66 -0
- data/spec/unit/type/set_type/test_equality.rb +26 -0
- data/spec/unit/type/set_type/test_include.rb +43 -0
- data/spec/unit/type/set_type/test_initialize.rb +28 -0
- data/spec/unit/type/set_type/test_name.rb +24 -0
- data/spec/unit/type/sub_type/test_default_name.rb +14 -0
- data/spec/unit/type/sub_type/test_dress.rb +75 -0
- data/spec/unit/type/sub_type/test_equality.rb +34 -0
- data/spec/unit/type/sub_type/test_include.rb +34 -0
- data/spec/unit/type/sub_type/test_initialize.rb +16 -0
- data/spec/unit/type/sub_type/test_name.rb +24 -0
- data/spec/unit/type/tuple_type/test_default_name.rb +14 -0
- data/spec/unit/type/tuple_type/test_dress.rb +112 -0
- data/spec/unit/type/tuple_type/test_equality.rb +32 -0
- data/spec/unit/type/tuple_type/test_include.rb +38 -0
- data/spec/unit/type/tuple_type/test_initialize.rb +30 -0
- data/spec/unit/type/tuple_type/test_name.rb +24 -0
- data/spec/unit/type/union_type/test_default_name.rb +12 -0
- data/spec/unit/type/union_type/test_dress.rb +43 -0
- data/spec/unit/type/union_type/test_equality.rb +30 -0
- data/spec/unit/type/union_type/test_include.rb +28 -0
- data/spec/unit/type/union_type/test_initialize.rb +24 -0
- data/spec/unit/type/union_type/test_name.rb +20 -0
- data/spec/unit/type_factory/dsl/test_adt.rb +54 -0
- data/spec/unit/type_factory/dsl/test_attribute.rb +37 -0
- data/spec/unit/type_factory/dsl/test_attributes.rb +41 -0
- data/spec/unit/type_factory/dsl/test_builtin.rb +45 -0
- data/spec/unit/type_factory/dsl/test_relation.rb +85 -0
- data/spec/unit/type_factory/dsl/test_seq.rb +57 -0
- data/spec/unit/type_factory/dsl/test_set.rb +57 -0
- data/spec/unit/type_factory/dsl/test_subtype.rb +91 -0
- data/spec/unit/type_factory/dsl/test_tuple.rb +73 -0
- data/spec/unit/type_factory/dsl/test_union.rb +81 -0
- data/spec/unit/type_factory/factory/test_builtin.rb +24 -0
- data/spec/unit/type_factory/factory/test_seq_type.rb +44 -0
- data/spec/unit/type_factory/factory/test_set_type.rb +44 -0
- data/spec/unit/type_factory/factory/test_sub_type.rb +53 -0
- data/spec/unit/type_factory/factory/test_tuple_type.rb +43 -0
- data/tasks/gem.rake +73 -0
- data/tasks/test.rake +31 -0
- metadata +344 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Qrb
|
3
|
+
describe TypeFactory, "DSL#adt" do
|
4
|
+
|
5
|
+
let(:factory){ TypeFactory.new }
|
6
|
+
|
7
|
+
let(:contracts){
|
8
|
+
{ rgb: [intType, Color.method(:rgb) ],
|
9
|
+
hex: [floatType, Color.method(:hex) ]}
|
10
|
+
}
|
11
|
+
|
12
|
+
shared_examples_for "The <Color> type" do
|
13
|
+
|
14
|
+
it{ should be_a(AdType) }
|
15
|
+
|
16
|
+
it 'should have the correct ruby type' do
|
17
|
+
subject.ruby_type.should be(Color)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should have the two contracts' do
|
21
|
+
subject.contracts.keys.should eq([:rgb, :hex])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
before do
|
26
|
+
subject
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when used with the standard signature' do
|
30
|
+
subject{
|
31
|
+
factory.adt(Color, contracts)
|
32
|
+
}
|
33
|
+
|
34
|
+
it_should_behave_like "The <Color> type"
|
35
|
+
|
36
|
+
it 'should have the correct name' do
|
37
|
+
subject.name.should eq("Color")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when used with a name' do
|
42
|
+
subject{
|
43
|
+
factory.adt(Color, contracts, "MyColor")
|
44
|
+
}
|
45
|
+
|
46
|
+
it_should_behave_like "The <Color> type"
|
47
|
+
|
48
|
+
it 'should have the correct name' do
|
49
|
+
subject.name.should eq("MyColor")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Qrb
|
3
|
+
describe TypeFactory, "DSL#attribute" do
|
4
|
+
|
5
|
+
let(:factory){ TypeFactory.new }
|
6
|
+
|
7
|
+
shared_examples_for "The a:Integer attribute" do
|
8
|
+
|
9
|
+
it{ should be_a(Attribute) }
|
10
|
+
|
11
|
+
it 'should have the correct name' do
|
12
|
+
subject.name.should eq(:a)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should have the correct type' do
|
16
|
+
subject.type.should eq(intType)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when used with a ruby class' do
|
21
|
+
subject{
|
22
|
+
factory.attribute(:a, Integer)
|
23
|
+
}
|
24
|
+
|
25
|
+
it_should_behave_like "The a:Integer attribute"
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when used with a type' do
|
29
|
+
subject{
|
30
|
+
factory.attribute(:a, intType)
|
31
|
+
}
|
32
|
+
|
33
|
+
it_should_behave_like "The a:Integer attribute"
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Qrb
|
3
|
+
describe TypeFactory, "DSL#attributes" do
|
4
|
+
|
5
|
+
let(:factory){ TypeFactory.new }
|
6
|
+
|
7
|
+
shared_examples_for "The a:Integer, b:Float attributes" do
|
8
|
+
|
9
|
+
it{ should be_a(Array) }
|
10
|
+
|
11
|
+
it 'should be the correct pair' do
|
12
|
+
subject.should eq([ Attribute.new(:a, intType), Attribute.new(:b, floatType) ])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'when used with ruby classes' do
|
17
|
+
subject{
|
18
|
+
factory.attributes(a: Integer, b: Float)
|
19
|
+
}
|
20
|
+
|
21
|
+
it_should_behave_like "The a:Integer, b:Float attributes"
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when used with types' do
|
25
|
+
subject{
|
26
|
+
factory.attributes(a: intType, b: floatType)
|
27
|
+
}
|
28
|
+
|
29
|
+
it_should_behave_like "The a:Integer, b:Float attributes"
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when used with a mix of both types' do
|
33
|
+
subject{
|
34
|
+
factory.attributes(a: Integer, b: floatType)
|
35
|
+
}
|
36
|
+
|
37
|
+
it_should_behave_like "The a:Integer, b:Float attributes"
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Qrb
|
3
|
+
describe TypeFactory, "DSL#builtin" do
|
4
|
+
|
5
|
+
let(:factory){ TypeFactory.new }
|
6
|
+
|
7
|
+
shared_examples_for "The Integer builtin type" do
|
8
|
+
|
9
|
+
it{ should be_a(BuiltinType) }
|
10
|
+
|
11
|
+
it 'should have the correct ruby type' do
|
12
|
+
subject.ruby_type.should be(Integer)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
before do
|
17
|
+
subject
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when used with a ruby class and no name' do
|
21
|
+
subject{
|
22
|
+
factory.builtin(Integer)
|
23
|
+
}
|
24
|
+
|
25
|
+
it_should_behave_like "The Integer builtin type"
|
26
|
+
|
27
|
+
it 'should have the correct name' do
|
28
|
+
subject.name.should eq("Integer")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when used with a ruby class and a name' do
|
33
|
+
subject{
|
34
|
+
factory.builtin(Integer, "Int")
|
35
|
+
}
|
36
|
+
|
37
|
+
it_should_behave_like "The Integer builtin type"
|
38
|
+
|
39
|
+
it 'should have the correct name' do
|
40
|
+
subject.name.should eq("Int")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Qrb
|
3
|
+
describe TypeFactory, "DSL#relation" do
|
4
|
+
|
5
|
+
let(:factory){ TypeFactory.new }
|
6
|
+
|
7
|
+
let(:heading){
|
8
|
+
Heading.new([ Attribute.new(:a, intType) ])
|
9
|
+
}
|
10
|
+
|
11
|
+
shared_examples_for "The Relation[a: Int] type" do
|
12
|
+
|
13
|
+
it{ should be_a(RelationType) }
|
14
|
+
|
15
|
+
it 'should have the correct heading' do
|
16
|
+
subject.heading.should eq(heading)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
before do
|
21
|
+
subject
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when used with the standard signature' do
|
25
|
+
subject{
|
26
|
+
factory.relation(heading, "MyRelation")
|
27
|
+
}
|
28
|
+
|
29
|
+
it_should_behave_like "The Relation[a: Int] type"
|
30
|
+
|
31
|
+
it 'should have the correct name' do
|
32
|
+
subject.name.should eq("MyRelation")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'when used with a tuple type' do
|
37
|
+
subject{
|
38
|
+
factory.relation(TupleType.new(heading), "MyRelation")
|
39
|
+
}
|
40
|
+
|
41
|
+
it_should_behave_like "The Relation[a: Int] type"
|
42
|
+
|
43
|
+
it 'should have the correct name' do
|
44
|
+
subject.name.should eq("MyRelation")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when used with a hash and ruby classes' do
|
49
|
+
subject{
|
50
|
+
factory.relation(a: Integer)
|
51
|
+
}
|
52
|
+
|
53
|
+
it_should_behave_like "The Relation[a: Int] type"
|
54
|
+
|
55
|
+
it 'should have the correct name' do
|
56
|
+
subject.name.should eq("{{a: Integer}}")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'when used with a hash and a name' do
|
61
|
+
subject{
|
62
|
+
factory.relation({a: Integer}, "MyRelation")
|
63
|
+
}
|
64
|
+
|
65
|
+
it_should_behave_like "The Relation[a: Int] type"
|
66
|
+
|
67
|
+
it 'should have the correct name' do
|
68
|
+
subject.name.should eq("MyRelation")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'when used with a hash and types' do
|
73
|
+
subject{
|
74
|
+
factory.relation(a: intType)
|
75
|
+
}
|
76
|
+
|
77
|
+
it_should_behave_like "The Relation[a: Int] type"
|
78
|
+
|
79
|
+
it 'should have the correct name' do
|
80
|
+
subject.name.should eq("{{a: intType}}")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Qrb
|
3
|
+
describe TypeFactory, "DSL#seq" do
|
4
|
+
|
5
|
+
let(:factory){ TypeFactory.new }
|
6
|
+
|
7
|
+
shared_examples_for "The Seq[Int] type" do
|
8
|
+
|
9
|
+
it{ should be_a(SeqType) }
|
10
|
+
|
11
|
+
it 'should have the correct element type' do
|
12
|
+
subject.elm_type.should eq(intType)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
before do
|
17
|
+
subject
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when used with a ruby class' do
|
21
|
+
subject{
|
22
|
+
factory.seq(Integer)
|
23
|
+
}
|
24
|
+
|
25
|
+
it_should_behave_like "The Seq[Int] type"
|
26
|
+
|
27
|
+
it 'should have the correct name' do
|
28
|
+
subject.name.should eq("[Integer]")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when used with a type' do
|
33
|
+
subject{
|
34
|
+
factory.seq(intType)
|
35
|
+
}
|
36
|
+
|
37
|
+
it_should_behave_like "The Seq[Int] type"
|
38
|
+
|
39
|
+
it 'should have the correct name' do
|
40
|
+
subject.name.should eq("[intType]")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when used with an explicit name' do
|
45
|
+
subject{
|
46
|
+
factory.seq(intType, "MySeq")
|
47
|
+
}
|
48
|
+
|
49
|
+
it_should_behave_like "The Seq[Int] type"
|
50
|
+
|
51
|
+
it 'should have the correct name' do
|
52
|
+
subject.name.should eq("MySeq")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Qrb
|
3
|
+
describe TypeFactory, "DSL#set" do
|
4
|
+
|
5
|
+
let(:factory){ TypeFactory.new }
|
6
|
+
|
7
|
+
shared_examples_for "The Set[Int] type" do
|
8
|
+
|
9
|
+
it{ should be_a(SetType) }
|
10
|
+
|
11
|
+
it 'should have the correct element type' do
|
12
|
+
subject.elm_type.should eq(intType)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
before do
|
17
|
+
subject
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when used with a ruby class' do
|
21
|
+
subject{
|
22
|
+
factory.set(Integer)
|
23
|
+
}
|
24
|
+
|
25
|
+
it_should_behave_like "The Set[Int] type"
|
26
|
+
|
27
|
+
it 'should have the correct name' do
|
28
|
+
subject.name.should eq("{Integer}")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when used with a type' do
|
33
|
+
subject{
|
34
|
+
factory.set(intType)
|
35
|
+
}
|
36
|
+
|
37
|
+
it_should_behave_like "The Set[Int] type"
|
38
|
+
|
39
|
+
it 'should have the correct name' do
|
40
|
+
subject.name.should eq("{intType}")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when used with an explicit name' do
|
45
|
+
subject{
|
46
|
+
factory.set(intType, "MySet")
|
47
|
+
}
|
48
|
+
|
49
|
+
it_should_behave_like "The Set[Int] type"
|
50
|
+
|
51
|
+
it 'should have the correct name' do
|
52
|
+
subject.name.should eq("MySet")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Qrb
|
3
|
+
describe TypeFactory, "DSL#subtype" do
|
4
|
+
|
5
|
+
let(:factory){ TypeFactory.new }
|
6
|
+
|
7
|
+
let(:constraints){
|
8
|
+
{ predicate: 1..10 }
|
9
|
+
}
|
10
|
+
|
11
|
+
shared_examples_for "The PosInt type" do
|
12
|
+
|
13
|
+
it{ should be_a(SubType) }
|
14
|
+
|
15
|
+
it 'should have the BuiltinType(Integer) super type' do
|
16
|
+
subject.super_type.should be_a(BuiltinType)
|
17
|
+
subject.super_type.ruby_type.should be(Integer)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should have the correct constraint' do
|
21
|
+
->{
|
22
|
+
subject.dress(-12)
|
23
|
+
}.should raise_error(TypeError)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
shared_examples_for "The SmallInt structural type" do
|
28
|
+
|
29
|
+
it{ should be_a(SubType) }
|
30
|
+
|
31
|
+
it 'should have the BuiltinType(Integer) super type' do
|
32
|
+
subject.super_type.should be_a(BuiltinType)
|
33
|
+
subject.super_type.ruby_type.should be(Integer)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should have the correct constraints' do
|
37
|
+
subject.constraints.should eq(constraints)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
before do
|
42
|
+
subject
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when used with a type' do
|
46
|
+
subject{
|
47
|
+
supertype = BuiltinType.new(Integer)
|
48
|
+
factory.subtype(supertype, constraints)
|
49
|
+
}
|
50
|
+
|
51
|
+
it_should_behave_like "The SmallInt structural type"
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'when used with a ruby class' do
|
55
|
+
subject{
|
56
|
+
factory.subtype(Integer, constraints)
|
57
|
+
}
|
58
|
+
|
59
|
+
it_should_behave_like "The SmallInt structural type"
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when used with a constraints shorthand' do
|
63
|
+
subject{
|
64
|
+
factory.subtype(Integer, 1..10)
|
65
|
+
}
|
66
|
+
|
67
|
+
it_should_behave_like "The SmallInt structural type"
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'when used with a constraint block' do
|
71
|
+
subject{
|
72
|
+
factory.subtype(Integer){|i| i >=0 }
|
73
|
+
}
|
74
|
+
|
75
|
+
it_should_behave_like "The PosInt type"
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'when used with a name' do
|
79
|
+
subject{
|
80
|
+
factory.subtype(Integer, constraints, "SmallInt")
|
81
|
+
}
|
82
|
+
|
83
|
+
it_should_behave_like "The SmallInt structural type"
|
84
|
+
|
85
|
+
it 'should have the correct name' do
|
86
|
+
subject.name.should eq("SmallInt")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Qrb
|
3
|
+
describe TypeFactory, "DSL#tuple" do
|
4
|
+
|
5
|
+
let(:factory){ TypeFactory.new }
|
6
|
+
|
7
|
+
let(:heading){
|
8
|
+
Heading.new([ Attribute.new(:a, intType) ])
|
9
|
+
}
|
10
|
+
|
11
|
+
shared_examples_for "The Tuple[a: Int] type" do
|
12
|
+
|
13
|
+
it{ should be_a(TupleType) }
|
14
|
+
|
15
|
+
it 'should have the correct heading' do
|
16
|
+
subject.heading.should eq(heading)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
before do
|
21
|
+
subject
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when used with the standard signature' do
|
25
|
+
subject{
|
26
|
+
factory.tuple(heading, "MyTuple")
|
27
|
+
}
|
28
|
+
|
29
|
+
it_should_behave_like "The Tuple[a: Int] type"
|
30
|
+
|
31
|
+
it 'should have the correct name' do
|
32
|
+
subject.name.should eq("MyTuple")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'when used with a hash and ruby classes' do
|
37
|
+
subject{
|
38
|
+
factory.tuple(a: Integer)
|
39
|
+
}
|
40
|
+
|
41
|
+
it_should_behave_like "The Tuple[a: Int] type"
|
42
|
+
|
43
|
+
it 'should have the correct name' do
|
44
|
+
subject.name.should eq("{a: Integer}")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when used with a hash and a name' do
|
49
|
+
subject{
|
50
|
+
factory.tuple({a: Integer}, "MyTuple")
|
51
|
+
}
|
52
|
+
|
53
|
+
it_should_behave_like "The Tuple[a: Int] type"
|
54
|
+
|
55
|
+
it 'should have the correct name' do
|
56
|
+
subject.name.should eq("MyTuple")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'when used with a hash and types' do
|
61
|
+
subject{
|
62
|
+
factory.tuple(a: intType)
|
63
|
+
}
|
64
|
+
|
65
|
+
it_should_behave_like "The Tuple[a: Int] type"
|
66
|
+
|
67
|
+
it 'should have the correct name' do
|
68
|
+
subject.name.should eq("{a: intType}")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Qrb
|
3
|
+
describe TypeFactory, "DSL#union" do
|
4
|
+
|
5
|
+
let(:factory){ TypeFactory.new }
|
6
|
+
|
7
|
+
shared_examples_for "The Int|Float union type" do
|
8
|
+
|
9
|
+
it{ should be_a(UnionType) }
|
10
|
+
|
11
|
+
it 'should have the correct candidates' do
|
12
|
+
subject.candidates.should eq([intType, floatType])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
before do
|
17
|
+
subject
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when used with the standard signature' do
|
21
|
+
subject{
|
22
|
+
factory.union([Integer, Float], 'MyUnion')
|
23
|
+
}
|
24
|
+
|
25
|
+
it_should_behave_like "The Int|Float union type"
|
26
|
+
|
27
|
+
it 'should have the correct name' do
|
28
|
+
subject.name.should eq("MyUnion")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when used with the standard signature and no name' do
|
33
|
+
subject{
|
34
|
+
factory.union([Integer, Float])
|
35
|
+
}
|
36
|
+
|
37
|
+
it_should_behave_like "The Int|Float union type"
|
38
|
+
|
39
|
+
it 'should have the correct name' do
|
40
|
+
subject.name.should eq("Integer|Float")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when used with a list of ruby classes' do
|
45
|
+
subject{
|
46
|
+
factory.union(Integer, Float)
|
47
|
+
}
|
48
|
+
|
49
|
+
it_should_behave_like "The Int|Float union type"
|
50
|
+
|
51
|
+
it 'should have the correct name' do
|
52
|
+
subject.name.should eq("Integer|Float")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'when used with a list of types' do
|
57
|
+
subject{
|
58
|
+
factory.union(intType, floatType)
|
59
|
+
}
|
60
|
+
|
61
|
+
it_should_behave_like "The Int|Float union type"
|
62
|
+
|
63
|
+
it 'should have the correct name' do
|
64
|
+
subject.name.should eq("intType|floatType")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'when used with a mix of both' do
|
69
|
+
subject{
|
70
|
+
factory.union(Integer, floatType)
|
71
|
+
}
|
72
|
+
|
73
|
+
it_should_behave_like "The Int|Float union type"
|
74
|
+
|
75
|
+
it 'should have the correct name' do
|
76
|
+
subject.name.should eq("Integer|floatType")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Qrb
|
3
|
+
describe TypeFactory, "Factory#builtin" do
|
4
|
+
|
5
|
+
let(:factory){ TypeFactory.new }
|
6
|
+
|
7
|
+
context 'when use with a ruby class' do
|
8
|
+
subject{ factory.type(Integer) }
|
9
|
+
|
10
|
+
it{ should eq(intType) }
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'when use with a ruby class and a name' do
|
14
|
+
subject{ factory.type(Integer, "Int") }
|
15
|
+
|
16
|
+
it{ should eq(intType) }
|
17
|
+
|
18
|
+
it 'should have the correct name' do
|
19
|
+
subject.name.should eq("Int")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Qrb
|
3
|
+
describe TypeFactory, "Factory#seq" do
|
4
|
+
|
5
|
+
let(:factory){ TypeFactory.new }
|
6
|
+
|
7
|
+
context 'for sequences of scalars' do
|
8
|
+
let(:expected){ SeqType.new(intType) }
|
9
|
+
|
10
|
+
context 'when used with [Class]' do
|
11
|
+
subject{ factory.type([Integer]) }
|
12
|
+
|
13
|
+
it{ should eq(expected) }
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'when used with [Class] and a name' do
|
17
|
+
subject{ factory.type([Integer], "MySeq") }
|
18
|
+
|
19
|
+
it{ should eq(expected) }
|
20
|
+
|
21
|
+
it 'should have the correct name' do
|
22
|
+
subject.name.should eq("MySeq")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'for pseudo-relations' do
|
28
|
+
subject{
|
29
|
+
factory.type([{r: Integer}], "MySeq")
|
30
|
+
}
|
31
|
+
|
32
|
+
let(:expected){
|
33
|
+
factory.seq(factory.tuple(r: Integer))
|
34
|
+
}
|
35
|
+
|
36
|
+
it{ should eq(expected) }
|
37
|
+
|
38
|
+
it 'should have the correct name' do
|
39
|
+
subject.name.should eq("MySeq")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|