finitio 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Finitio
|
3
|
+
describe Attribute, "initialize" do
|
4
|
+
|
5
|
+
context 'when implicitely required' do
|
6
|
+
subject{ Attribute.new(:red, intType) }
|
7
|
+
|
8
|
+
it 'should correctly set the instance variables' do
|
9
|
+
expect(subject.name).to eq(:red)
|
10
|
+
expect(subject.type).to eq(intType)
|
11
|
+
expect(subject).to be_required
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when not required' do
|
16
|
+
subject{ Attribute.new(:red, intType, false) }
|
17
|
+
|
18
|
+
it 'should correctly set the instance variables' do
|
19
|
+
expect(subject.name).to eq(:red)
|
20
|
+
expect(subject.type).to eq(intType)
|
21
|
+
expect(subject).not_to be_required
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Finitio
|
3
|
+
describe Attribute, "optional?" do
|
4
|
+
|
5
|
+
it 'is false by default' do
|
6
|
+
expect(Attribute.new(:red, intType)).not_to be_optional
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'is is the reverse of required' do
|
10
|
+
expect(Attribute.new(:red, intType, false)).to be_optional
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'is is the reverse of !required' do
|
14
|
+
expect(Attribute.new(:red, intType, true)).not_to be_optional
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Finitio
|
3
|
+
describe Attribute, "required?" do
|
4
|
+
|
5
|
+
it 'is true by default' do
|
6
|
+
expect(Attribute.new(:red, intType)).to be_required
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'is can be set to true' do
|
10
|
+
expect(Attribute.new(:red, intType, true)).to be_required
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'is can be set to false' do
|
14
|
+
expect(Attribute.new(:red, intType, false)).not_to be_required
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Finitio
|
3
|
+
describe Attribute, "to_name" do
|
4
|
+
|
5
|
+
subject{ attr.to_name }
|
6
|
+
|
7
|
+
context 'when required' do
|
8
|
+
let(:attr){ Attribute.new(:red, intType) }
|
9
|
+
|
10
|
+
it{ should eq("red: intType") }
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'when not required' do
|
14
|
+
let(:attr){ Attribute.new(:red, intType, false) }
|
15
|
+
|
16
|
+
it{ should eq("red :? intType") }
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Finitio
|
3
|
+
describe Constraint, "anonymous?" do
|
4
|
+
|
5
|
+
subject{ constraint.anonymous? }
|
6
|
+
|
7
|
+
context 'with an unnamed constraint' do
|
8
|
+
let(:constraint){ Constraint.new(byte_full) }
|
9
|
+
|
10
|
+
it{ should eq(true) }
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'with a named constraint' do
|
14
|
+
let(:constraint){ Constraint.new(byte_full, :byte) }
|
15
|
+
|
16
|
+
it{ should eq(false) }
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Finitio
|
3
|
+
describe Constraint, "==" do
|
4
|
+
|
5
|
+
def constraint(proc, name = nil)
|
6
|
+
Constraint.new(proc, name)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'recognizes same procs' do
|
10
|
+
expect(constraint(byte_min)).to eq(constraint(byte_min))
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'recognizes non constraints' do
|
14
|
+
expect(constraint(byte_min)).not_to eq(nil)
|
15
|
+
expect(constraint(byte_min)).not_to eq(1)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'recognizes non equivalent constraints' do
|
19
|
+
expect(constraint(byte_min)).not_to eq(constraint(byte_max))
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'does not take name into accound' do
|
23
|
+
expect(constraint(byte_min, :foo)).to eq(constraint(byte_min, :bar))
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'implements hash accordingly' do
|
27
|
+
c1 = constraint(byte_min)
|
28
|
+
c2 = constraint(byte_min)
|
29
|
+
expect(c1.hash).to eq(c2.hash)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'is smart enough to have different hash codes for different constraints' do
|
33
|
+
c1 = constraint(byte_min)
|
34
|
+
c2 = constraint(byte_max)
|
35
|
+
expect(c1.hash).not_to eq(c2.hash)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Finitio
|
3
|
+
describe Constraint, "name" do
|
4
|
+
|
5
|
+
subject{ constraint.name }
|
6
|
+
|
7
|
+
context 'with an unnamed constraint' do
|
8
|
+
let(:constraint){ Constraint.new(byte_full) }
|
9
|
+
|
10
|
+
it{ should eq(:default) }
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'with a named constraint' do
|
14
|
+
let(:constraint){ Constraint.new(byte_full, :byte) }
|
15
|
+
|
16
|
+
it{ should eq(:byte) }
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Finitio
|
3
|
+
describe Constraint, "named?" do
|
4
|
+
|
5
|
+
subject{ constraint.named? }
|
6
|
+
|
7
|
+
context 'with an unnamed constraint' do
|
8
|
+
let(:constraint){ Constraint.new(byte_full) }
|
9
|
+
|
10
|
+
it{ should eq(false) }
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'with a named constraint' do
|
14
|
+
let(:constraint){ Constraint.new(byte_full, :byte) }
|
15
|
+
|
16
|
+
it{ should eq(true) }
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Finitio
|
3
|
+
describe Constraint, "===" do
|
4
|
+
|
5
|
+
let(:constraint){ Constraint.new(byte_full) }
|
6
|
+
|
7
|
+
it 'delegates to the proc' do
|
8
|
+
expect(constraint.===(17)).to eq(true)
|
9
|
+
expect(constraint.===(1700)).to eq(false)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Finitio, "parse" do
|
3
|
+
|
4
|
+
context 'with a string' do
|
5
|
+
subject{
|
6
|
+
Finitio.parse <<-EOF
|
7
|
+
Posint = .Fixnum( i | i>=0 )
|
8
|
+
Point = { x: Posint, y: Posint }
|
9
|
+
EOF
|
10
|
+
}
|
11
|
+
|
12
|
+
it{ should be_a(Finitio::Syntax::System) }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with a Path' do
|
16
|
+
subject{
|
17
|
+
Finitio.parse(Path.dir/"system.fio")
|
18
|
+
}
|
19
|
+
|
20
|
+
it{ should be_a(Finitio::Syntax::System) }
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
describe Finitio, "
|
2
|
+
describe Finitio, "system" do
|
3
3
|
|
4
4
|
context 'with a string' do
|
5
5
|
subject{
|
6
|
-
Finitio.
|
6
|
+
Finitio.system <<-EOF
|
7
7
|
Posint = .Fixnum( i | i>=0 )
|
8
8
|
Point = { x: Posint, y: Posint }
|
9
9
|
EOF
|
@@ -12,20 +12,20 @@ describe Finitio, "parse" do
|
|
12
12
|
it{ should be_a(Finitio::System) }
|
13
13
|
|
14
14
|
it 'should have the expected types' do
|
15
|
-
subject["Posint"].
|
16
|
-
subject["Point"].
|
15
|
+
expect(subject["Posint"]).to be_a(Finitio::SubType)
|
16
|
+
expect(subject["Point"]).to be_a(Finitio::TupleType)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
context 'with a Path' do
|
21
21
|
subject{
|
22
|
-
Finitio.
|
22
|
+
Finitio.system(Path.dir/"system.fio")
|
23
23
|
}
|
24
24
|
|
25
25
|
it{ should be_a(Finitio::System) }
|
26
26
|
|
27
27
|
it 'should have the expected types' do
|
28
|
-
subject["Posint"].
|
28
|
+
expect(subject["Posint"]).to be_a(Finitio::SubType)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Finitio
|
3
|
+
describe Heading, "allow_extra" do
|
4
|
+
|
5
|
+
let(:r){ Attribute.new(:r, intType) }
|
6
|
+
|
7
|
+
def heading(attributes, options = nil)
|
8
|
+
Heading.new(attributes, options)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'is false by default' do
|
12
|
+
expect(heading([r])).not_to be_allow_extra
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'can be set to true' do
|
16
|
+
expect(heading([r], allow_extra: true)).to be_allow_extra
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'can be set to false explicitely' do
|
20
|
+
expect(heading([r], allow_extra: false)).not_to be_allow_extra
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -9,7 +9,7 @@ module Finitio
|
|
9
9
|
context 'without a block' do
|
10
10
|
|
11
11
|
it 'should return an enumerator' do
|
12
|
-
h.each.
|
12
|
+
expect(h.each).to be_a(Enumerator)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -20,7 +20,7 @@ module Finitio
|
|
20
20
|
h.each do |attr|
|
21
21
|
seen << attr
|
22
22
|
end
|
23
|
-
seen.
|
23
|
+
expect(seen).to eq([a, b])
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Finitio
|
3
|
+
describe Heading, "equality" do
|
4
|
+
|
5
|
+
let(:r) { Attribute.new(:r, intType) }
|
6
|
+
let(:b) { Attribute.new(:b, intType) }
|
7
|
+
let(:maybe_r){ Attribute.new(:r, intType, false) }
|
8
|
+
|
9
|
+
def heading(attributes, options = nil)
|
10
|
+
Heading.new(attributes, options)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'does not put significance to attributes ordering' do
|
14
|
+
expect(heading([r, b])).to eq(heading([b, r]))
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'distinguishes between different attribute sets' do
|
18
|
+
expect(heading([r])).not_to eq(heading([b]))
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'distinguishes between attribute obligations' do
|
22
|
+
expect(heading([r])).not_to eq(heading([maybe_r]))
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'distinguishes between extra allowance' do
|
26
|
+
h1 = heading([r], allow_extra: true)
|
27
|
+
h2 = heading([r], allow_extra: false)
|
28
|
+
expect(h1).not_to eq(h2)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'distinguishes between attribute types' do
|
32
|
+
a1 = Attribute.new(:r, intType)
|
33
|
+
a2 = Attribute.new(:r, floatType)
|
34
|
+
expect(heading([a1])).not_to eq(heading([a2]))
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Finitio
|
3
|
+
describe Heading, "hash" do
|
4
|
+
|
5
|
+
let(:r) { Attribute.new(:r, intType) }
|
6
|
+
let(:b) { Attribute.new(:b, intType) }
|
7
|
+
let(:maybe_r){ Attribute.new(:r, intType, false) }
|
8
|
+
|
9
|
+
def heading(attributes, options = nil)
|
10
|
+
Heading.new(attributes, options)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'returns same code on equal headings' do
|
14
|
+
expect(heading([r]).hash).to eq(heading([r]).hash)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'does not put significance to attributes ordering' do
|
18
|
+
expect(heading([r, b]).hash).to eq(heading([b, r]).hash)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'is good enough to distinguish between attribute obligations' do
|
22
|
+
expect(heading([r]).hash).not_to eq(heading([maybe_r]).hash)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'is good enough to distinguish between extra allowance' do
|
26
|
+
h1 = heading([r], allow_extra: true)
|
27
|
+
h2 = heading([r], allow_extra: false)
|
28
|
+
expect(h1.hash).not_to eq(h2.hash)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'is be good enough to distinguish between different headings' do
|
32
|
+
a1 = Attribute.new(:r, intType)
|
33
|
+
a2 = Attribute.new(:r, floatType)
|
34
|
+
expect(heading([a1]).hash).not_to eq(heading([a2]).hash)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Finitio
|
3
|
+
describe Heading, "[]" do
|
4
|
+
|
5
|
+
let(:a){ Attribute.new(:a, intType) }
|
6
|
+
let(:h){ Heading.new([a]) }
|
7
|
+
|
8
|
+
it 'returns the attribute by name' do
|
9
|
+
expect(h[:a]).to be(a)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns nil if no such attribute' do
|
13
|
+
expect(h[:b]).to be_nil
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Finitio
|
3
|
+
describe Heading, "multi?" do
|
4
|
+
|
5
|
+
let(:red){
|
6
|
+
Attribute.new(:red, intType)
|
7
|
+
}
|
8
|
+
|
9
|
+
let(:blue){
|
10
|
+
Attribute.new(:blue, floatType)
|
11
|
+
}
|
12
|
+
|
13
|
+
let(:maybe_blue){
|
14
|
+
Attribute.new(:blue, floatType, false)
|
15
|
+
}
|
16
|
+
|
17
|
+
subject{ Heading.new(attributes, options).multi? }
|
18
|
+
|
19
|
+
let(:options){ nil }
|
20
|
+
|
21
|
+
context 'with no attribute' do
|
22
|
+
let(:attributes){
|
23
|
+
[ ]
|
24
|
+
}
|
25
|
+
|
26
|
+
it{ should eq(false) }
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'with required attributes only' do
|
30
|
+
let(:attributes){
|
31
|
+
[ red, blue ]
|
32
|
+
}
|
33
|
+
|
34
|
+
it{ should eq(false) }
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'with some optional attributes' do
|
38
|
+
let(:attributes){
|
39
|
+
[ red, maybe_blue ]
|
40
|
+
}
|
41
|
+
|
42
|
+
it{ should eq(true) }
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'with allow_extra set to true' do
|
46
|
+
let(:attributes){
|
47
|
+
[ red, blue ]
|
48
|
+
}
|
49
|
+
let(:options){
|
50
|
+
{allow_extra: true}
|
51
|
+
}
|
52
|
+
|
53
|
+
it{ should eq(true) }
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|