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
@@ -2,32 +2,32 @@ require 'spec_helper'
|
|
2
2
|
module Finitio
|
3
3
|
describe SubType, "include?" do
|
4
4
|
|
5
|
-
let(:type){ SubType.new(intType,
|
5
|
+
let(:type){ SubType.new(intType, [byte_min, byte_max], "byte") }
|
6
6
|
|
7
7
|
subject{ type.include?(arg) }
|
8
8
|
|
9
9
|
context 'when included on int' do
|
10
10
|
let(:arg){ 12 }
|
11
11
|
|
12
|
-
it{ should
|
12
|
+
it{ should eq(true) }
|
13
13
|
end
|
14
14
|
|
15
15
|
context 'when not included on int (I)' do
|
16
16
|
let(:arg){ -12 }
|
17
17
|
|
18
|
-
it{ should
|
18
|
+
it{ should eq(false) }
|
19
19
|
end
|
20
20
|
|
21
21
|
context 'when not included on int (II)' do
|
22
|
-
let(:arg){
|
22
|
+
let(:arg){ 256 }
|
23
23
|
|
24
|
-
it{ should
|
24
|
+
it{ should eq(false) }
|
25
25
|
end
|
26
26
|
|
27
27
|
context 'when not included' do
|
28
28
|
let(:arg){ "12" }
|
29
29
|
|
30
|
-
it{ should
|
30
|
+
it{ should eq(false) }
|
31
31
|
end
|
32
32
|
|
33
33
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Finitio
|
3
|
+
describe SubType, "initialize" do
|
4
|
+
|
5
|
+
let(:sub){ SubType.new(intType, [byte_min, byte_max]) }
|
6
|
+
|
7
|
+
it 'sets the variable instances' do
|
8
|
+
expect(sub.super_type).to eq(intType)
|
9
|
+
expect(sub.constraints).to eq([byte_min, byte_max])
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -5,18 +5,18 @@ module Finitio
|
|
5
5
|
subject{ type.name }
|
6
6
|
|
7
7
|
context 'when provided' do
|
8
|
-
let(:type){ SubType.new(intType,
|
8
|
+
let(:type){ SubType.new(intType, [positive], "Foo") }
|
9
9
|
|
10
10
|
it 'uses the specified one' do
|
11
|
-
subject.
|
11
|
+
expect(subject).to eq("Foo")
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
context 'when not provided' do
|
16
|
-
let(:type){ SubType.new(intType,
|
16
|
+
let(:type){ SubType.new(intType, [positive]) }
|
17
17
|
|
18
18
|
it 'uses the first constraint name' do
|
19
|
-
subject.
|
19
|
+
expect(subject).to eq("Positive")
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
File without changes
|
@@ -20,7 +20,7 @@ module Finitio
|
|
20
20
|
}
|
21
21
|
|
22
22
|
it 'should coerce to a tuple' do
|
23
|
-
subject.
|
23
|
+
expect(subject).to eq(r: 12, g: 13, b: 255)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -36,16 +36,16 @@ module Finitio
|
|
36
36
|
}
|
37
37
|
|
38
38
|
it 'should raise a TypeError' do
|
39
|
-
subject.
|
40
|
-
subject.message.
|
39
|
+
expect(subject).to be_a(TypeError)
|
40
|
+
expect(subject.message).to eq("Invalid color `foo`")
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'should have no cause' do
|
44
|
-
subject.cause.
|
44
|
+
expect(subject.cause).to be_nil
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'should have an empty location' do
|
48
|
-
subject.location.
|
48
|
+
expect(subject.location).to eq('')
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -55,16 +55,16 @@ module Finitio
|
|
55
55
|
}
|
56
56
|
|
57
57
|
it 'should raise a TypeError' do
|
58
|
-
subject.
|
59
|
-
subject.message.
|
58
|
+
expect(subject).to be_a(TypeError)
|
59
|
+
expect(subject.message).to eq("Missing attribute `b`")
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'should have no cause' do
|
63
|
-
subject.cause.
|
63
|
+
expect(subject.cause).to be_nil
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'should have an empty location' do
|
67
|
-
subject.location.
|
67
|
+
expect(subject.location).to eq('')
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -74,16 +74,16 @@ module Finitio
|
|
74
74
|
}
|
75
75
|
|
76
76
|
it 'should raise a TypeError' do
|
77
|
-
subject.
|
78
|
-
subject.message.
|
77
|
+
expect(subject).to be_a(TypeError)
|
78
|
+
expect(subject.message).to eq("Unrecognized attribute `extr`")
|
79
79
|
end
|
80
80
|
|
81
81
|
it 'should have no cause' do
|
82
|
-
subject.cause.
|
82
|
+
expect(subject.cause).to be_nil
|
83
83
|
end
|
84
84
|
|
85
85
|
it 'should have an empty location' do
|
86
|
-
subject.location.
|
86
|
+
expect(subject.location).to eq('')
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -93,17 +93,17 @@ module Finitio
|
|
93
93
|
}
|
94
94
|
|
95
95
|
it 'should raise a TypeError' do
|
96
|
-
subject.
|
97
|
-
subject.message.
|
96
|
+
expect(subject).to be_a(TypeError)
|
97
|
+
expect(subject.message).to eq("Invalid Byte `12.0`")
|
98
98
|
end
|
99
99
|
|
100
100
|
it 'should have the correct cause' do
|
101
|
-
subject.cause.
|
102
|
-
subject.cause.message.
|
101
|
+
expect(subject.cause).to be_a(TypeError)
|
102
|
+
expect(subject.cause.message).to eq("Invalid intType `12.0`")
|
103
103
|
end
|
104
104
|
|
105
105
|
it 'should have the correct location' do
|
106
|
-
subject.location.
|
106
|
+
expect(subject.location).to eq("r")
|
107
107
|
end
|
108
108
|
end
|
109
109
|
end
|
@@ -11,21 +11,21 @@ module Finitio
|
|
11
11
|
let(:type3) { TupleType.new(h3) }
|
12
12
|
|
13
13
|
it 'should apply structural equality' do
|
14
|
-
(type1 == type2).
|
15
|
-
(type2 == type1).
|
14
|
+
expect(type1 == type2).to eq(true)
|
15
|
+
expect(type2 == type1).to eq(true)
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'should apply distinguish different types' do
|
19
|
-
(type1 == type3).
|
20
|
-
(type2 == type3).
|
19
|
+
expect(type1 == type3).to eq(false)
|
20
|
+
expect(type2 == type3).to eq(false)
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'should be a total function, with nil for non types' do
|
24
|
-
(type1 == 12).
|
24
|
+
expect(type1 == 12).to eq(false)
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'should implement hash accordingly' do
|
28
|
-
[type1, type2].map(&:hash).uniq.size.
|
28
|
+
expect([type1, type2].map(&:hash).uniq.size).to eq(1)
|
29
29
|
end
|
30
30
|
|
31
31
|
end
|
@@ -13,25 +13,25 @@ module Finitio
|
|
13
13
|
context 'when a valid hash' do
|
14
14
|
let(:arg){ {a: 12} }
|
15
15
|
|
16
|
-
it{ should
|
16
|
+
it{ should eq(true) }
|
17
17
|
end
|
18
18
|
|
19
19
|
context 'when an invalid hash (too many attributes)' do
|
20
20
|
let(:arg){ {a: 12, b: 15} }
|
21
21
|
|
22
|
-
it{ should
|
22
|
+
it{ should eq(false) }
|
23
23
|
end
|
24
24
|
|
25
25
|
context 'when an invalid hash (too few attributes)' do
|
26
26
|
let(:arg){ {b: 12} }
|
27
27
|
|
28
|
-
it{ should
|
28
|
+
it{ should eq(false) }
|
29
29
|
end
|
30
30
|
|
31
31
|
context 'when an invalid hash (wrong type)' do
|
32
32
|
let(:arg){ {a: 12.0} }
|
33
33
|
|
34
|
-
it{ should
|
34
|
+
it{ should eq(false) }
|
35
35
|
end
|
36
36
|
|
37
37
|
end
|
@@ -12,7 +12,7 @@ module Finitio
|
|
12
12
|
it{ should be_a(TupleType) }
|
13
13
|
|
14
14
|
it 'correctly sets the instance variable' do
|
15
|
-
subject.heading.
|
15
|
+
expect(subject.heading).to eq(heading)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -20,11 +20,11 @@ module Finitio
|
|
20
20
|
subject{ TupleType.new("foo") }
|
21
21
|
|
22
22
|
it 'should raise an error' do
|
23
|
-
|
23
|
+
expect{
|
24
24
|
subject
|
25
|
-
}.
|
25
|
+
}.to raise_error(ArgumentError, "Heading expected, got `foo`")
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
end
|
30
|
-
end
|
30
|
+
end
|
File without changes
|
File without changes
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
module Finitio
|
3
3
|
describe UnionType, "dress" do
|
4
4
|
|
5
|
-
let(:type)
|
5
|
+
let(:type){ UnionType.new([intType, floatType], "union") }
|
6
6
|
|
7
7
|
subject{ type.dress(arg) }
|
8
8
|
|
@@ -26,16 +26,17 @@ module Finitio
|
|
26
26
|
}
|
27
27
|
|
28
28
|
it 'should raise an Error' do
|
29
|
-
subject.
|
30
|
-
subject.message.
|
29
|
+
expect(subject).to be_a(TypeError)
|
30
|
+
expect(subject.message).to eq("Invalid union `foo`")
|
31
31
|
end
|
32
32
|
|
33
|
-
it 'should have
|
34
|
-
subject.cause.
|
33
|
+
it 'should have a cause' do
|
34
|
+
expect(subject.cause).to be_a(TypeError)
|
35
|
+
expect(subject.cause.message).to eq("Invalid intType `foo`")
|
35
36
|
end
|
36
37
|
|
37
38
|
it 'should have an empty location' do
|
38
|
-
subject.location.
|
39
|
+
expect(subject.location).to eq('')
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
@@ -8,22 +8,22 @@ module Finitio
|
|
8
8
|
let(:uType4) { UnionType.new([intType]) }
|
9
9
|
|
10
10
|
it 'should apply structural equality' do
|
11
|
-
(uType == uType2).
|
12
|
-
(uType == uType3).
|
13
|
-
(uType2 == uType3).
|
11
|
+
expect(uType == uType2).to eq(true)
|
12
|
+
expect(uType == uType3).to eq(true)
|
13
|
+
expect(uType2 == uType3).to eq(true)
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'should apply distinguish different types' do
|
17
|
-
(uType == uType4).
|
18
|
-
(uType == intType).
|
17
|
+
expect(uType == uType4).to eq(false)
|
18
|
+
expect(uType == intType).to eq(false)
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should be a total function, with nil for non types' do
|
22
|
-
(uType == 12).
|
22
|
+
expect(uType == 12).to eq(false)
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'should implement hash accordingly' do
|
26
|
-
[uType, uType2, uType3].map(&:hash).uniq.size.
|
26
|
+
expect([uType, uType2, uType3].map(&:hash).uniq.size).to eq(1)
|
27
27
|
end
|
28
28
|
|
29
29
|
end
|
@@ -9,19 +9,19 @@ 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 on int' do
|
16
16
|
let(:arg){ 12 }
|
17
17
|
|
18
|
-
it{ should
|
18
|
+
it{ should eq(true) }
|
19
19
|
end
|
20
20
|
|
21
21
|
context 'when included on float' do
|
22
22
|
let(:arg){ 12.0 }
|
23
23
|
|
24
|
-
it{ should
|
24
|
+
it{ should eq(true) }
|
25
25
|
end
|
26
26
|
|
27
27
|
end
|
@@ -6,7 +6,7 @@ module Finitio
|
|
6
6
|
let(:union){ UnionType.new([intType, floatType]) }
|
7
7
|
|
8
8
|
it 'sets the variable instances' do
|
9
|
-
union.candidates.
|
9
|
+
expect(union.candidates).to eq([intType, floatType])
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -14,9 +14,9 @@ module Finitio
|
|
14
14
|
let(:union){ UnionType.new(["bar"]) }
|
15
15
|
|
16
16
|
it 'should raise an error' do
|
17
|
-
|
17
|
+
expect{
|
18
18
|
union
|
19
|
-
}.
|
19
|
+
}.to raise_error(ArgumentError, %Q{[Finitio::Type] expected, got ["bar"]})
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
File without changes
|
@@ -14,11 +14,11 @@ module Finitio
|
|
14
14
|
it{ should be_a(AdType) }
|
15
15
|
|
16
16
|
it 'should have the correct ruby type' do
|
17
|
-
subject.ruby_type.
|
17
|
+
expect(subject.ruby_type).to be(Color)
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'should have the two contracts' do
|
21
|
-
subject.contracts.
|
21
|
+
expect(subject.contracts.map(&:name)).to eq([:rgb, :hex])
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -34,7 +34,7 @@ module Finitio
|
|
34
34
|
it_should_behave_like "The <Color> type"
|
35
35
|
|
36
36
|
it 'should have the correct name' do
|
37
|
-
subject.name.
|
37
|
+
expect(subject.name).to eq("Color")
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -46,7 +46,7 @@ module Finitio
|
|
46
46
|
it_should_behave_like "The <Color> type"
|
47
47
|
|
48
48
|
it 'should have the correct name' do
|
49
|
-
subject.name.
|
49
|
+
expect(subject.name).to eq("MyColor")
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -9,11 +9,11 @@ module Finitio
|
|
9
9
|
it{ should be_a(Attribute) }
|
10
10
|
|
11
11
|
it 'should have the correct name' do
|
12
|
-
subject.name.
|
12
|
+
expect(subject.name).to eq(:a)
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'should have the correct type' do
|
16
|
-
subject.type.
|
16
|
+
expect(subject.type).to eq(intType)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -23,6 +23,8 @@ module Finitio
|
|
23
23
|
}
|
24
24
|
|
25
25
|
it_should_behave_like "The a:Integer attribute"
|
26
|
+
|
27
|
+
it{ should be_required }
|
26
28
|
end
|
27
29
|
|
28
30
|
context 'when used with a type' do
|
@@ -31,6 +33,18 @@ module Finitio
|
|
31
33
|
}
|
32
34
|
|
33
35
|
it_should_behave_like "The a:Integer attribute"
|
36
|
+
|
37
|
+
it{ should be_required }
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when used for an optional attribute' do
|
41
|
+
subject{
|
42
|
+
factory.attribute(:a, intType, false)
|
43
|
+
}
|
44
|
+
|
45
|
+
it_should_behave_like "The a:Integer attribute"
|
46
|
+
|
47
|
+
it{ should_not be_required }
|
34
48
|
end
|
35
49
|
|
36
50
|
end
|