finitio 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +66 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +34 -30
- data/finitio.gemspec +1 -1
- data/lib/finitio.rb +7 -39
- data/lib/finitio/errors.rb +14 -0
- data/lib/finitio/support.rb +4 -1
- data/lib/finitio/support/attribute.rb +13 -7
- data/lib/finitio/support/compilation.rb +55 -0
- data/lib/finitio/support/constraint.rb +46 -0
- data/lib/finitio/support/contract.rb +33 -0
- data/lib/finitio/support/dress_helper.rb +3 -2
- data/lib/finitio/support/heading.rb +57 -17
- data/lib/finitio/support/metadata.rb +20 -0
- data/lib/finitio/support/type_factory.rb +154 -41
- data/lib/finitio/syntax.rb +16 -31
- data/lib/finitio/syntax/expr.rb +56 -0
- data/lib/finitio/syntax/expr/arith_op.rb +22 -0
- data/lib/finitio/syntax/expr/comparison.rb +22 -0
- data/lib/finitio/syntax/expr/fn_call.rb +24 -0
- data/lib/finitio/syntax/expr/identifier.rb +18 -0
- data/lib/finitio/syntax/expr/literal.rb +19 -0
- data/lib/finitio/syntax/expr/logic_dyadic.rb +22 -0
- data/lib/finitio/syntax/expr/logic_not.rb +21 -0
- data/lib/finitio/syntax/expr/oo_call.rb +24 -0
- data/lib/finitio/syntax/expr/parenthesized.rb +20 -0
- data/lib/finitio/syntax/expr/unary_minus_op.rb +21 -0
- data/lib/finitio/syntax/expressions.citrus +129 -0
- data/lib/finitio/syntax/finitio.citrus +10 -208
- data/lib/finitio/syntax/finitio.sexp +5 -1
- data/lib/finitio/syntax/lexer.citrus +91 -0
- data/lib/finitio/syntax/literal.rb +16 -0
- data/lib/finitio/syntax/literal/boolean.rb +22 -0
- data/lib/finitio/syntax/literal/integer.rb +14 -0
- data/lib/finitio/syntax/literal/real.rb +14 -0
- data/lib/finitio/syntax/literal/string.rb +14 -0
- data/lib/finitio/syntax/literals.citrus +44 -0
- data/lib/finitio/syntax/node.rb +53 -0
- data/lib/finitio/syntax/type.rb +28 -0
- data/lib/finitio/syntax/type/ad_type.rb +29 -0
- data/lib/finitio/syntax/{any_type.rb → type/any_type.rb} +1 -1
- data/lib/finitio/syntax/type/attribute.rb +33 -0
- data/lib/finitio/syntax/{builtin_type.rb → type/builtin_type.rb} +3 -1
- data/lib/finitio/syntax/{constraint_def.rb → type/constraint_def.rb} +4 -3
- data/lib/finitio/syntax/type/constraints.rb +17 -0
- data/lib/finitio/syntax/{contract.rb → type/contract.rb} +9 -3
- data/lib/finitio/syntax/{definitions.rb → type/definitions.rb} +1 -0
- data/lib/finitio/syntax/{expression.rb → type/expression.rb} +2 -1
- data/lib/finitio/syntax/{external_pair.rb → type/external_pair.rb} +3 -1
- data/lib/finitio/syntax/type/heading.rb +30 -0
- data/lib/finitio/syntax/{inline_pair.rb → type/inline_pair.rb} +3 -1
- data/lib/finitio/syntax/{lambda_expr.rb → type/lambda_expr.rb} +3 -0
- data/lib/finitio/syntax/type/main_type.rb +18 -0
- data/lib/finitio/syntax/type/metadata.rb +18 -0
- data/lib/finitio/syntax/type/metadata_attr.rb +15 -0
- data/lib/finitio/syntax/{named_constraint.rb → type/named_constraint.rb} +10 -3
- data/lib/finitio/syntax/type/relation_type.rb +24 -0
- data/lib/finitio/syntax/{seq_type.rb → type/seq_type.rb} +3 -0
- data/lib/finitio/syntax/{set_type.rb → type/set_type.rb} +3 -0
- data/lib/finitio/syntax/type/struct_type.rb +17 -0
- data/lib/finitio/syntax/{sub_type.rb → type/sub_type.rb} +3 -0
- data/lib/finitio/syntax/{system.rb → type/system.rb} +5 -4
- data/lib/finitio/syntax/type/tuple_type.rb +24 -0
- data/lib/finitio/syntax/{type_def.rb → type/type_def.rb} +8 -3
- data/lib/finitio/syntax/{type_ref.rb → type/type_ref.rb} +4 -1
- data/lib/finitio/syntax/{union_type.rb → type/union_type.rb} +1 -0
- data/lib/finitio/syntax/{unnamed_constraint.rb → type/unnamed_constraint.rb} +7 -1
- data/lib/finitio/syntax/types.citrus +196 -0
- data/lib/finitio/system.rb +15 -15
- data/lib/finitio/type.rb +38 -6
- data/lib/finitio/type/ad_type.rb +41 -18
- data/lib/finitio/type/alias_type.rb +37 -0
- data/lib/finitio/type/any_type.rb +7 -3
- data/lib/finitio/type/builtin_type.rb +5 -4
- data/lib/finitio/{support → type}/collection_type.rb +3 -4
- data/lib/finitio/type/hash_based_type.rb +91 -0
- data/lib/finitio/type/heading_based_type.rb +28 -0
- data/lib/finitio/type/multi_relation_type.rb +34 -0
- data/lib/finitio/type/multi_tuple_type.rb +29 -0
- data/lib/finitio/type/proxy_type.rb +40 -0
- data/lib/finitio/type/rel_based_type.rb +42 -0
- data/lib/finitio/type/relation_type.rb +6 -47
- data/lib/finitio/type/seq_type.rb +4 -0
- data/lib/finitio/type/set_type.rb +4 -0
- data/lib/finitio/type/struct_type.rb +84 -0
- data/lib/finitio/type/sub_type.rb +25 -22
- data/lib/finitio/type/tuple_type.rb +6 -57
- data/lib/finitio/type/union_type.rb +12 -5
- data/lib/finitio/version.rb +2 -2
- data/spec/{unit/attribute → attribute}/test_equality.rb +8 -5
- data/spec/{unit/attribute → attribute}/test_fetch_on.rb +5 -5
- data/spec/attribute/test_initialize.rb +26 -0
- data/spec/attribute/test_optional.rb +18 -0
- data/spec/attribute/test_required.rb +18 -0
- data/spec/attribute/test_to_name.rb +20 -0
- data/spec/constraint/test_anonymous.rb +20 -0
- data/spec/constraint/test_equality.rb +39 -0
- data/spec/constraint/test_name.rb +20 -0
- data/spec/constraint/test_named.rb +20 -0
- data/spec/constraint/test_triple_equal.rb +13 -0
- data/spec/{unit/qrb/system.q → finitio/system.fio} +0 -0
- data/spec/{unit/qrb → finitio}/test_ast.rb +0 -0
- data/spec/finitio/test_parse.rb +23 -0
- data/spec/{unit/qrb/test_parse.rb → finitio/test_system.rb} +6 -6
- data/spec/heading/test_allow_extra.rb +24 -0
- data/spec/{unit/heading → heading}/test_each.rb +2 -2
- data/spec/heading/test_equality.rb +38 -0
- data/spec/heading/test_hash.rb +38 -0
- data/spec/heading/test_hash_get.rb +17 -0
- data/spec/{unit/heading → heading}/test_initialize.rb +2 -2
- data/spec/heading/test_multi.rb +57 -0
- data/spec/{unit/heading → heading}/test_size.rb +0 -0
- data/spec/heading/test_to_name.rb +58 -0
- data/spec/spec_helper.rb +17 -1
- data/spec/syntax/expr/test_free_variables.rb +46 -0
- data/spec/syntax/expr/test_to_proc_source.rb +43 -0
- data/spec/{unit/syntax → syntax}/nodes/test_ad_type.rb +26 -26
- data/spec/{unit/syntax → syntax}/nodes/test_any_type.rb +2 -2
- data/spec/syntax/nodes/test_attribute.rb +65 -0
- data/spec/{unit/syntax → syntax}/nodes/test_builtin_type.rb +5 -5
- data/spec/{unit/syntax → syntax}/nodes/test_comment.rb +1 -1
- data/spec/{unit/syntax → syntax}/nodes/test_constraint_def.rb +3 -8
- data/spec/{unit/syntax → syntax}/nodes/test_constraints.rb +21 -16
- data/spec/{unit/syntax → syntax}/nodes/test_contract.rb +28 -35
- data/spec/{unit/syntax → syntax}/nodes/test_expression.rb +13 -5
- data/spec/{unit/syntax → syntax}/nodes/test_heading.rb +25 -7
- data/spec/syntax/nodes/test_metadata.rb +28 -0
- data/spec/{unit/syntax → syntax}/nodes/test_named_constraint.rb +8 -8
- data/spec/syntax/nodes/test_relation_type.rb +84 -0
- data/spec/{unit/syntax → syntax}/nodes/test_seq_type.rb +4 -4
- data/spec/{unit/syntax → syntax}/nodes/test_set_type.rb +4 -4
- data/spec/{unit/syntax → syntax}/nodes/test_spacing.rb +1 -1
- data/spec/syntax/nodes/test_struct_type.rb +38 -0
- data/spec/{unit/syntax → syntax}/nodes/test_sub_type.rb +14 -14
- data/spec/{unit/syntax → syntax}/nodes/test_system.rb +3 -3
- data/spec/syntax/nodes/test_tuple_type.rb +94 -0
- data/spec/syntax/nodes/test_type_def.rb +57 -0
- data/spec/{unit/syntax → syntax}/nodes/test_type_ref.rb +3 -3
- data/spec/{unit/syntax → syntax}/nodes/test_union_type.rb +3 -3
- data/spec/{unit/syntax → syntax}/nodes/test_unnamed_constraint.rb +7 -7
- data/spec/syntax/test_compile.rb +41 -0
- data/spec/{unit/syntax → syntax}/test_compile_type.rb +1 -1
- data/spec/{unit/system → system}/test_add_type.rb +6 -6
- data/spec/{unit/system → system}/test_dsl.rb +2 -2
- data/spec/{unit/system → system}/test_dup.rb +4 -4
- data/spec/{unit/system → system}/test_fetch.rb +4 -4
- data/spec/{unit/system → system}/test_get_type.rb +2 -2
- data/spec/{unit/system → system}/test_initialize.rb +0 -0
- data/spec/test_finitio.rb +8 -0
- data/spec/{unit/type → type}/ad_type/test_default_name.rb +1 -2
- data/spec/{unit/type → type}/ad_type/test_dress.rb +19 -9
- data/spec/{unit/type → type}/ad_type/test_include.rb +3 -3
- data/spec/{unit/type → type}/ad_type/test_initialize.rb +15 -8
- data/spec/{unit/type → type}/ad_type/test_name.rb +2 -2
- data/spec/type/alias_type/test_default_name.rb +10 -0
- data/spec/type/alias_type/test_delegation.rb +29 -0
- data/spec/type/alias_type/test_name.rb +10 -0
- data/spec/{unit/type → type}/any_type/test_default_name.rb +1 -1
- data/spec/{unit/type → type}/any_type/test_dress.rb +0 -0
- data/spec/{unit/type → type}/any_type/test_equality.rb +4 -4
- data/spec/{unit/type → type}/any_type/test_include.rb +2 -2
- data/spec/{unit/type → type}/any_type/test_initialize.rb +0 -0
- data/spec/{unit/type → type}/any_type/test_name.rb +2 -2
- data/spec/{unit/type → type}/builtin_type/test_default_name.rb +1 -1
- data/spec/{unit/type → type}/builtin_type/test_dress.rb +3 -3
- data/spec/{unit/type → type}/builtin_type/test_equality.rb +4 -4
- data/spec/{unit/type → type}/builtin_type/test_include.rb +2 -2
- data/spec/{unit/type → type}/builtin_type/test_initialize.rb +1 -1
- data/spec/{unit/type → type}/builtin_type/test_name.rb +2 -2
- data/spec/type/multi_relation_type/test_default_name.rb +19 -0
- data/spec/type/multi_relation_type/test_dress.rb +206 -0
- data/spec/type/multi_relation_type/test_equality.rb +36 -0
- data/spec/type/multi_relation_type/test_include.rb +89 -0
- data/spec/type/multi_relation_type/test_initialize.rb +29 -0
- data/spec/type/multi_relation_type/test_name.rb +27 -0
- data/spec/type/multi_tuple_type/test_default_name.rb +17 -0
- data/spec/type/multi_tuple_type/test_dress.rb +146 -0
- data/spec/type/multi_tuple_type/test_equality.rb +32 -0
- data/spec/type/multi_tuple_type/test_include.rb +73 -0
- data/spec/type/multi_tuple_type/test_initialize.rb +30 -0
- data/spec/type/multi_tuple_type/test_name.rb +24 -0
- data/spec/type/proxy_type/test_delegation.rb +37 -0
- data/spec/type/proxy_type/test_resolve.rb +29 -0
- data/spec/{unit/type → type}/relation_type/test_default_name.rb +0 -0
- data/spec/{unit/type → type}/relation_type/test_dress.rb +24 -24
- data/spec/{unit/type → type}/relation_type/test_equality.rb +6 -6
- data/spec/{unit/type → type}/relation_type/test_include.rb +4 -4
- data/spec/{unit/type → type}/relation_type/test_initialize.rb +2 -2
- data/spec/{unit/type → type}/relation_type/test_name.rb +0 -0
- data/spec/{unit/type → type}/seq_type/test_default_name.rb +0 -0
- data/spec/{unit/type → type}/seq_type/test_dress.rb +5 -5
- data/spec/{unit/type → type}/seq_type/test_equality.rb +4 -4
- data/spec/{unit/type → type}/seq_type/test_include.rb +4 -4
- data/spec/{unit/type → type}/seq_type/test_initialize.rb +3 -3
- data/spec/{unit/type → type}/seq_type/test_name.rb +0 -0
- data/spec/{unit/type → type}/set_type/test_default_name.rb +0 -0
- data/spec/{unit/type → type}/set_type/test_dress.rb +8 -8
- data/spec/{unit/type → type}/set_type/test_equality.rb +4 -4
- data/spec/{unit/type → type}/set_type/test_include.rb +4 -4
- data/spec/{unit/type → type}/set_type/test_initialize.rb +3 -3
- data/spec/{unit/type → type}/set_type/test_name.rb +0 -0
- data/spec/type/struct_type/test_default_name.rb +10 -0
- data/spec/type/struct_type/test_dress.rb +105 -0
- data/spec/type/struct_type/test_equality.rb +28 -0
- data/spec/type/struct_type/test_include.rb +40 -0
- data/spec/type/struct_type/test_initialize.rb +22 -0
- data/spec/type/struct_type/test_name.rb +20 -0
- data/spec/{unit/type → type}/sub_type/test_default_name.rb +2 -2
- data/spec/{unit/type → type}/sub_type/test_dress.rb +14 -14
- data/spec/type/sub_type/test_equality.rb +46 -0
- data/spec/{unit/type → type}/sub_type/test_include.rb +6 -6
- data/spec/type/sub_type/test_initialize.rb +13 -0
- data/spec/{unit/type → type}/sub_type/test_name.rb +4 -4
- data/spec/{unit/type → type}/tuple_type/test_default_name.rb +0 -0
- data/spec/{unit/type → type}/tuple_type/test_dress.rb +18 -18
- data/spec/{unit/type → type}/tuple_type/test_equality.rb +6 -6
- data/spec/{unit/type → type}/tuple_type/test_include.rb +4 -4
- data/spec/{unit/type → type}/tuple_type/test_initialize.rb +4 -4
- data/spec/{unit/type → type}/tuple_type/test_name.rb +0 -0
- data/spec/{unit/type → type}/union_type/test_default_name.rb +0 -0
- data/spec/{unit/type → type}/union_type/test_dress.rb +7 -6
- data/spec/{unit/type → type}/union_type/test_equality.rb +7 -7
- data/spec/{unit/type → type}/union_type/test_include.rb +3 -3
- data/spec/{unit/type → type}/union_type/test_initialize.rb +3 -3
- data/spec/{unit/type → type}/union_type/test_name.rb +0 -0
- data/spec/{unit/type_factory → type_factory}/dsl/test_adt.rb +4 -4
- data/spec/{unit/type_factory → type_factory}/dsl/test_any.rb +1 -1
- data/spec/{unit/type_factory → type_factory}/dsl/test_attribute.rb +16 -2
- data/spec/{unit/type_factory → type_factory}/dsl/test_attributes.rb +1 -1
- data/spec/{unit/type_factory → type_factory}/dsl/test_builtin.rb +3 -3
- data/spec/type_factory/dsl/test_multi_relation.rb +39 -0
- data/spec/type_factory/dsl/test_multi_tuple.rb +37 -0
- data/spec/{unit/type_factory → type_factory}/dsl/test_relation.rb +6 -6
- data/spec/{unit/type_factory → type_factory}/dsl/test_seq.rb +4 -4
- data/spec/{unit/type_factory → type_factory}/dsl/test_set.rb +4 -4
- data/spec/type_factory/dsl/test_struct.rb +45 -0
- data/spec/{unit/type_factory → type_factory}/dsl/test_subtype.rb +10 -8
- data/spec/{unit/type_factory → type_factory}/dsl/test_tuple.rb +5 -5
- data/spec/{unit/type_factory → type_factory}/dsl/test_union.rb +6 -6
- data/spec/{unit/type_factory → type_factory}/factory/test_builtin.rb +1 -1
- data/spec/{unit/type_factory → type_factory}/factory/test_seq_type.rb +2 -2
- data/spec/{unit/type_factory → type_factory}/factory/test_set_type.rb +2 -2
- data/spec/type_factory/factory/test_struct_type.rb +18 -0
- data/spec/{unit/type_factory → type_factory}/factory/test_sub_type.rb +7 -7
- data/spec/{unit/type_factory → type_factory}/factory/test_tuple_type.rb +4 -4
- metadata +398 -286
- data/lib/finitio/data_type.rb +0 -29
- data/lib/finitio/syntax/ad_type.rb +0 -32
- data/lib/finitio/syntax/attribute.rb +0 -15
- data/lib/finitio/syntax/constraints.rb +0 -22
- data/lib/finitio/syntax/heading.rb +0 -19
- data/lib/finitio/syntax/relation_type.rb +0 -15
- data/lib/finitio/syntax/support.rb +0 -13
- data/lib/finitio/syntax/tuple_type.rb +0 -15
- data/spec/acceptance/Finitio/test_default.rb +0 -96
- data/spec/acceptance/Finitio/test_parsing.rb +0 -15
- data/spec/acceptance/ad_type/test_in_finitio.rb +0 -82
- data/spec/acceptance/ad_type/test_in_ruby.rb +0 -60
- data/spec/unit/attribute/test_initialize.rb +0 -13
- data/spec/unit/attribute/test_to_name.rb +0 -10
- data/spec/unit/heading/test_equality.rb +0 -28
- data/spec/unit/heading/test_to_name.rb +0 -32
- data/spec/unit/syntax/nodes/test_attribute.rb +0 -38
- data/spec/unit/syntax/nodes/test_relation_type.rb +0 -59
- data/spec/unit/syntax/nodes/test_tuple_type.rb +0 -59
- data/spec/unit/syntax/nodes/test_type_def.rb +0 -33
- data/spec/unit/test_finitio.rb +0 -15
- data/spec/unit/type/sub_type/test_equality.rb +0 -34
- data/spec/unit/type/sub_type/test_initialize.rb +0 -16
@@ -14,7 +14,7 @@ module Finitio
|
|
14
14
|
let(:name){ "intType" }
|
15
15
|
|
16
16
|
it 'should return the type' do
|
17
|
-
subject.
|
17
|
+
expect(subject).to eq(intType)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -22,7 +22,7 @@ module Finitio
|
|
22
22
|
let(:name){ "noSuchOne" }
|
23
23
|
|
24
24
|
it 'should return nil' do
|
25
|
-
subject.
|
25
|
+
expect(subject).to be_nil
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
File without changes
|
@@ -2,9 +2,16 @@ require 'spec_helper'
|
|
2
2
|
module Finitio
|
3
3
|
describe AdType, 'dress' do
|
4
4
|
|
5
|
+
let(:rgb){
|
6
|
+
Contract.new(intType, ->(i){ Color.new(i,i,i) }, Finitio::IDENTITY, :rgb)
|
7
|
+
}
|
8
|
+
|
9
|
+
let(:hex){
|
10
|
+
Contract.new(floatType, ->(f){ Color.new(f.to_i,f.to_i,f.to_i) }, Finitio::IDENTITY, :hex)
|
11
|
+
}
|
12
|
+
|
5
13
|
let(:type){
|
6
|
-
AdType.new(Color, rgb
|
7
|
-
hex: [floatType, ->(f){ f*3 }, Finitio::IDENTITY ])
|
14
|
+
AdType.new(Color, [rgb, hex])
|
8
15
|
}
|
9
16
|
|
10
17
|
subject{
|
@@ -20,34 +27,37 @@ module Finitio
|
|
20
27
|
context 'with an integer' do
|
21
28
|
let(:arg){ 12 }
|
22
29
|
|
23
|
-
it{ should eq(
|
30
|
+
it{ should eq(Color.new(12,12,12)) }
|
24
31
|
end
|
25
32
|
|
26
33
|
context 'with a float' do
|
27
34
|
let(:arg){ 12.0 }
|
28
35
|
|
29
|
-
it{ should eq(
|
36
|
+
it{ should eq(Color.new(12,12,12)) }
|
30
37
|
end
|
31
38
|
|
32
39
|
context 'with an unrecognized' do
|
33
40
|
let(:arg){ "foo" }
|
34
41
|
|
35
42
|
it 'should raise an error' do
|
36
|
-
|
43
|
+
expect{
|
37
44
|
subject
|
38
|
-
}.
|
45
|
+
}.to raise_error(TypeError, "Invalid Color `foo`")
|
39
46
|
end
|
40
47
|
end
|
41
48
|
|
42
49
|
context 'when the upper raises an error' do
|
50
|
+
let(:rgb){
|
51
|
+
Contract.new(intType, ->(t){ raise ArgumentError }, Finitio::IDENTITY, :rgb)
|
52
|
+
}
|
43
53
|
let(:type){
|
44
|
-
AdType.new(Color,
|
54
|
+
AdType.new(Color, [ rgb ])
|
45
55
|
}
|
46
56
|
|
47
57
|
it 'should hide the error' do
|
48
58
|
err = type.dress(12) rescue $!
|
49
|
-
err.
|
50
|
-
err.message.
|
59
|
+
expect(err).to be_a(TypeError)
|
60
|
+
expect(err.message).to eq("Invalid Color `12`")
|
51
61
|
end
|
52
62
|
end
|
53
63
|
|
@@ -2,20 +2,20 @@ require 'spec_helper'
|
|
2
2
|
module Finitio
|
3
3
|
describe AdType, "include?" do
|
4
4
|
|
5
|
-
let(:type){ AdType.new(Color,
|
5
|
+
let(:type){ AdType.new(Color, []) }
|
6
6
|
|
7
7
|
subject{ type.include?(arg) }
|
8
8
|
|
9
9
|
context 'when not included' do
|
10
10
|
let(:arg){ "12" }
|
11
11
|
|
12
|
-
it{ should
|
12
|
+
it{ should eq(false) }
|
13
13
|
end
|
14
14
|
|
15
15
|
context 'when included' do
|
16
16
|
let(:arg){ blueviolet }
|
17
17
|
|
18
|
-
it{ should
|
18
|
+
it{ should eq(true) }
|
19
19
|
end
|
20
20
|
|
21
21
|
end
|
@@ -2,17 +2,24 @@ require 'spec_helper'
|
|
2
2
|
module Finitio
|
3
3
|
describe AdType, 'initialize' do
|
4
4
|
|
5
|
+
let(:rgb){
|
6
|
+
Contract.new(intType, Color.method(:rgb), Finitio::IDENTITY, :rgb)
|
7
|
+
}
|
8
|
+
|
9
|
+
let(:hex){
|
10
|
+
Contract.new(floatType, Color.method(:hex), Finitio::IDENTITY, :hex)
|
11
|
+
}
|
12
|
+
|
5
13
|
subject{
|
6
|
-
AdType.new(Color,
|
7
|
-
hex: [floatType, Color.method(:hex), Finitio::IDENTITY ])
|
14
|
+
AdType.new(Color, [rgb, hex])
|
8
15
|
}
|
9
16
|
|
10
17
|
context 'with valid arguments' do
|
11
18
|
it{ should be_a(AdType) }
|
12
19
|
|
13
20
|
it 'should set the instance variables' do
|
14
|
-
subject.ruby_type.
|
15
|
-
subject.contracts.
|
21
|
+
expect(subject.ruby_type).to be(Color)
|
22
|
+
expect(subject.contracts).to be_a(Array)
|
16
23
|
end
|
17
24
|
end
|
18
25
|
|
@@ -20,9 +27,9 @@ module Finitio
|
|
20
27
|
subject{ AdType.new("foo", {}) }
|
21
28
|
|
22
29
|
it 'should raise an error' do
|
23
|
-
|
30
|
+
expect{
|
24
31
|
subject
|
25
|
-
}.
|
32
|
+
}.to raise_error(ArgumentError, 'Module expected, got `foo`')
|
26
33
|
end
|
27
34
|
end
|
28
35
|
|
@@ -30,9 +37,9 @@ module Finitio
|
|
30
37
|
subject{ AdType.new(Object, "bar") }
|
31
38
|
|
32
39
|
it 'should raise an error' do
|
33
|
-
|
40
|
+
expect{
|
34
41
|
subject
|
35
|
-
}.
|
42
|
+
}.to raise_error(ArgumentError, '[Contract] expected, got `bar`')
|
36
43
|
end
|
37
44
|
end
|
38
45
|
|
@@ -5,13 +5,13 @@ module Finitio
|
|
5
5
|
subject{ type.name }
|
6
6
|
|
7
7
|
context 'when provided' do
|
8
|
-
let(:type){ AdType.new(Color,
|
8
|
+
let(:type){ AdType.new(Color, [], "Foo") }
|
9
9
|
|
10
10
|
it{ should eq('Foo') }
|
11
11
|
end
|
12
12
|
|
13
13
|
context 'when not provided' do
|
14
|
-
let(:type){ AdType.new(Color,
|
14
|
+
let(:type){ AdType.new(Color, []) }
|
15
15
|
|
16
16
|
it{ should eq('Color') }
|
17
17
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Finitio
|
3
|
+
describe AliasType, "delegation pattern" do
|
4
|
+
|
5
|
+
let(:type){ AliasType.new(intType, 'Alias') }
|
6
|
+
|
7
|
+
it 'should delegate hash' do
|
8
|
+
expect(type.hash).to eq(intType.hash)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should delegate ==' do
|
12
|
+
expect(intType == type).to eq(true)
|
13
|
+
expect(type == intType).to eq(true)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should delegate dress' do
|
17
|
+
expect(type.dress(12)).to eq(12)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should delegate include?' do
|
21
|
+
expect(type.include?(12)).to eq(true)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should delegate to_s' do
|
25
|
+
expect(type.to_s).to eq(intType.to_s)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
File without changes
|
@@ -7,19 +7,19 @@ module Finitio
|
|
7
7
|
let(:fltType) { BuiltinType.new(Float) }
|
8
8
|
|
9
9
|
it 'should apply structural equality' do
|
10
|
-
(anyType == anyType2).
|
10
|
+
expect(anyType == anyType2).to eq(true)
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'should apply distinguish different types' do
|
14
|
-
(anyType == fltType).
|
14
|
+
expect(anyType == fltType).to eq(false)
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'should be a total function, with nil for non types' do
|
18
|
-
(anyType == 12).
|
18
|
+
expect(anyType == 12).to eq(false)
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should implement hash accordingly' do
|
22
|
-
(anyType.hash == anyType2.hash).
|
22
|
+
expect(anyType.hash == anyType2.hash).to eq(true)
|
23
23
|
end
|
24
24
|
|
25
25
|
end
|
File without changes
|
@@ -8,7 +8,7 @@ module Finitio
|
|
8
8
|
let(:type){ AnyType.new }
|
9
9
|
|
10
10
|
it 'uses the default name' do
|
11
|
-
subject.
|
11
|
+
expect(subject).to eq("Any")
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -16,7 +16,7 @@ module Finitio
|
|
16
16
|
let(:type){ AnyType.new("foo") }
|
17
17
|
|
18
18
|
it 'uses the specified name' do
|
19
|
-
subject.
|
19
|
+
expect(subject).to eq("foo")
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -20,12 +20,12 @@ module Finitio
|
|
20
20
|
}
|
21
21
|
|
22
22
|
it 'should raise an Error' do
|
23
|
-
subject.
|
24
|
-
subject.message.
|
23
|
+
expect(subject).to be_a(TypeError)
|
24
|
+
expect(subject.message).to eq("Invalid int `12.0`")
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'should have no location' do
|
28
|
-
subject.location.
|
28
|
+
expect(subject.location).to eq('')
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -7,19 +7,19 @@ module Finitio
|
|
7
7
|
let(:fltType) { BuiltinType.new(Float) }
|
8
8
|
|
9
9
|
it 'should apply structural equality' do
|
10
|
-
(intType == intType2).
|
10
|
+
expect(intType == intType2).to eq(true)
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'should apply distinguish different types' do
|
14
|
-
(intType == fltType).
|
14
|
+
expect(intType == fltType).to eq(false)
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'should be a total function, with nil for non types' do
|
18
|
-
(intType == 12).
|
18
|
+
expect(intType == 12).to eq(false)
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should implement hash accordingly' do
|
22
|
-
(intType.hash == intType2.hash).
|
22
|
+
expect(intType.hash == intType2.hash).to eq(true)
|
23
23
|
end
|
24
24
|
|
25
25
|
end
|
@@ -9,13 +9,13 @@ module Finitio
|
|
9
9
|
context 'when not included' do
|
10
10
|
let(:arg){ "12" }
|
11
11
|
|
12
|
-
it{ should
|
12
|
+
it{ should eq(false) }
|
13
13
|
end
|
14
14
|
|
15
15
|
context 'when included' do
|
16
16
|
let(:arg){ 12 }
|
17
17
|
|
18
|
-
it{ should
|
18
|
+
it{ should eq(true) }
|
19
19
|
end
|
20
20
|
|
21
21
|
end
|
@@ -8,7 +8,7 @@ module Finitio
|
|
8
8
|
let(:type){ BuiltinType.new(Integer) }
|
9
9
|
|
10
10
|
it 'uses the default name' do
|
11
|
-
subject.
|
11
|
+
expect(subject).to eq("Integer")
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -16,7 +16,7 @@ module Finitio
|
|
16
16
|
let(:type){ BuiltinType.new(Integer, "int") }
|
17
17
|
|
18
18
|
it 'uses the specified name' do
|
19
|
-
subject.
|
19
|
+
expect(subject).to eq("int")
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Finitio
|
3
|
+
describe MultiRelationType, "default_name" do
|
4
|
+
|
5
|
+
let(:heading){
|
6
|
+
Heading.new([
|
7
|
+
Attribute.new(:a, byte),
|
8
|
+
Attribute.new(:b, byte, false)
|
9
|
+
])
|
10
|
+
}
|
11
|
+
|
12
|
+
subject{ type.default_name }
|
13
|
+
|
14
|
+
let(:type){ MultiRelationType.new(heading) }
|
15
|
+
|
16
|
+
it{ should eq("{{a: Byte, b :? Byte}}") }
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,206 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Finitio
|
3
|
+
describe MultiRelationType, "dress" do
|
4
|
+
|
5
|
+
let(:heading){
|
6
|
+
Heading.new([Attribute.new(:r, byte),
|
7
|
+
Attribute.new(:g, byte),
|
8
|
+
Attribute.new(:b, byte, false)])
|
9
|
+
}
|
10
|
+
|
11
|
+
let(:type){
|
12
|
+
MultiRelationType.new(heading, "colors")
|
13
|
+
}
|
14
|
+
|
15
|
+
subject{ type.dress(arg) }
|
16
|
+
|
17
|
+
context 'with a valid array of Hashes' do
|
18
|
+
let(:arg){
|
19
|
+
[
|
20
|
+
{ "r" => 12, "g" => 13, "b" => 255 },
|
21
|
+
{ "r" => 12, "g" => 15, "b" => 198 }
|
22
|
+
]
|
23
|
+
}
|
24
|
+
let(:expected){
|
25
|
+
[
|
26
|
+
{ r: 12, g: 13, b: 255 },
|
27
|
+
{ r: 12, g: 15, b: 198 }
|
28
|
+
]
|
29
|
+
}
|
30
|
+
|
31
|
+
it 'should coerce to an Enumerable of tuples' do
|
32
|
+
expect(subject).to be_a(Enumerable)
|
33
|
+
expect(subject.to_a).to eq(expected)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'with a valid array of Hashes with some optional missing' do
|
38
|
+
let(:arg){
|
39
|
+
[
|
40
|
+
{ "r" => 12, "g" => 13, "b" => 255 },
|
41
|
+
{ "r" => 12, "g" => 15 }
|
42
|
+
]
|
43
|
+
}
|
44
|
+
let(:expected){
|
45
|
+
[
|
46
|
+
{ r: 12, g: 13, b: 255 },
|
47
|
+
{ r: 12, g: 15 }
|
48
|
+
]
|
49
|
+
}
|
50
|
+
|
51
|
+
it 'should coerce to an Enumerable of tuples' do
|
52
|
+
expect(subject).to be_a(Enumerable)
|
53
|
+
expect(subject.to_a).to eq(expected)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'with an empty array' do
|
58
|
+
let(:arg){
|
59
|
+
[]
|
60
|
+
}
|
61
|
+
let(:expected){
|
62
|
+
[]
|
63
|
+
}
|
64
|
+
|
65
|
+
it 'should coerce to an Enumerable of tuples' do
|
66
|
+
expect(subject).to be_a(Enumerable)
|
67
|
+
expect(subject.to_a).to eq(expected)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'when raising an error' do
|
72
|
+
|
73
|
+
subject do
|
74
|
+
type.dress(arg) rescue $!
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'with something else than an Array' do
|
78
|
+
let(:arg){
|
79
|
+
"foo"
|
80
|
+
}
|
81
|
+
|
82
|
+
it 'should raise a TypeError' do
|
83
|
+
expect(subject).to be_a(TypeError)
|
84
|
+
expect(subject.message).to eq("Invalid colors `foo`")
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should have no cause' do
|
88
|
+
expect(subject.cause).to be_nil
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should have an empty location' do
|
92
|
+
expect(subject.location).to eq('')
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'with Array of non-tuples' do
|
97
|
+
let(:arg){
|
98
|
+
["foo"]
|
99
|
+
}
|
100
|
+
|
101
|
+
it 'should raise a TypeError' do
|
102
|
+
expect(subject).to be_a(TypeError)
|
103
|
+
expect(subject.message).to eq("Invalid {r: Byte, g: Byte, b :? Byte} `foo`")
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should have no cause' do
|
107
|
+
expect(subject.cause).to be_nil
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should have the correct location' do
|
111
|
+
expect(subject.location).to eq('0')
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context 'with a wrong tuple' do
|
116
|
+
let(:arg){
|
117
|
+
[
|
118
|
+
{ "r" => 12, "g" => 13, "b" => 255 },
|
119
|
+
{ "r" => 12, "b" => 13 }
|
120
|
+
]
|
121
|
+
}
|
122
|
+
|
123
|
+
it 'should raise a TypeError' do
|
124
|
+
expect(subject).to be_a(TypeError)
|
125
|
+
expect(subject.message).to eq("Missing attribute `g`")
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'should have no cause' do
|
129
|
+
expect(subject.cause).to be_nil
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should have the correct location' do
|
133
|
+
expect(subject.location).to eq('1')
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'with a tuple with extra attribute' do
|
138
|
+
let(:arg){
|
139
|
+
[
|
140
|
+
{ "r" => 12, "g" => 13, "b" => 255 },
|
141
|
+
{ "r" => 12, "g" => 13, "f" => 13 }
|
142
|
+
]
|
143
|
+
}
|
144
|
+
|
145
|
+
it 'should raise a TypeError' do
|
146
|
+
expect(subject).to be_a(TypeError)
|
147
|
+
expect(subject.message).to eq("Unrecognized attribute `f`")
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'should have no cause' do
|
151
|
+
expect(subject.cause).to be_nil
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should have the correct location' do
|
155
|
+
expect(subject.location).to eq('1')
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
context 'with a wrong tuple attribute' do
|
160
|
+
let(:arg){
|
161
|
+
[
|
162
|
+
{ "r" => 12, "g" => 13, "b" => 255 },
|
163
|
+
{ "r" => 12, "g" => 13, "b" => 12.0 }
|
164
|
+
]
|
165
|
+
}
|
166
|
+
|
167
|
+
it 'should raise a TypeError' do
|
168
|
+
expect(subject).to be_a(TypeError)
|
169
|
+
expect(subject.message).to eq("Invalid Byte `12.0`")
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should have a cause' do
|
173
|
+
expect(subject.cause).not_to be_nil
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'should have the correct location' do
|
177
|
+
expect(subject.location).to eq('1/b')
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
context 'with a duplicate tuple' do
|
182
|
+
let(:arg){
|
183
|
+
[
|
184
|
+
{ "r" => 12, "g" => 13, "b" => 255 },
|
185
|
+
{ "r" => 12, "g" => 192, "b" => 13 },
|
186
|
+
{ "r" => 12, "g" => 13, "b" => 255 }
|
187
|
+
]
|
188
|
+
}
|
189
|
+
|
190
|
+
it 'should raise a TypeError' do
|
191
|
+
expect(subject).to be_a(TypeError)
|
192
|
+
expect(subject.message).to eq("Duplicate tuple")
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'should have no cause' do
|
196
|
+
expect(subject.cause).to be_nil
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'should have the correct location' do
|
200
|
+
expect(subject.location).to eq('2')
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
206
|
+
end
|