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
@@ -6,10 +6,6 @@ module Finitio
|
|
6
6
|
Syntax.parse(input, root: "contract")
|
7
7
|
}
|
8
8
|
|
9
|
-
let(:contract){
|
10
|
-
compiled.values.first
|
11
|
-
}
|
12
|
-
|
13
9
|
let(:ast){
|
14
10
|
subject.to_ast
|
15
11
|
}
|
@@ -21,17 +17,16 @@ module Finitio
|
|
21
17
|
subject.compile(type_factory, Color)
|
22
18
|
}
|
23
19
|
|
24
|
-
it 'compiles to the expected
|
25
|
-
compiled.
|
26
|
-
compiled.
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
contract[2].should be_a(Proc)
|
20
|
+
it 'compiles to the expected Contract' do
|
21
|
+
expect(compiled).to be_a(Contract)
|
22
|
+
expect(compiled.name).to eq(:rgb)
|
23
|
+
expect(compiled.infotype).to be_a(TupleType)
|
24
|
+
expect(compiled.dresser).to be_a(Method)
|
25
|
+
expect(compiled.undresser).to be_a(Proc)
|
31
26
|
end
|
32
27
|
|
33
28
|
it 'has expected AST' do
|
34
|
-
ast.
|
29
|
+
expect(ast).to eq([
|
35
30
|
:contract,
|
36
31
|
"rgb",
|
37
32
|
[:tuple_type,
|
@@ -52,17 +47,16 @@ module Finitio
|
|
52
47
|
subject.compile(type_factory, nil)
|
53
48
|
}
|
54
49
|
|
55
|
-
it 'compiles to the expected
|
56
|
-
compiled.
|
57
|
-
compiled.
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
contract[2].should be(Finitio::IDENTITY)
|
50
|
+
it 'compiles to the expected Contract' do
|
51
|
+
expect(compiled).to be_a(Contract)
|
52
|
+
expect(compiled.name).to eq(:rgb)
|
53
|
+
expect(compiled.infotype).to be_a(TupleType)
|
54
|
+
expect(compiled.dresser).to be(Finitio::IDENTITY)
|
55
|
+
expect(compiled.undresser).to be(Finitio::IDENTITY)
|
62
56
|
end
|
63
57
|
|
64
58
|
it 'has expected AST' do
|
65
|
-
ast.
|
59
|
+
expect(ast).to eq([
|
66
60
|
:contract,
|
67
61
|
"rgb",
|
68
62
|
[:tuple_type,
|
@@ -83,16 +77,16 @@ module Finitio
|
|
83
77
|
subject.compile(type_factory, nil)
|
84
78
|
}
|
85
79
|
|
86
|
-
it 'compiles to the expected
|
87
|
-
compiled.
|
88
|
-
compiled.
|
89
|
-
|
90
|
-
|
91
|
-
|
80
|
+
it 'compiles to the expected Contract' do
|
81
|
+
expect(compiled).to be_a(Contract)
|
82
|
+
expect(compiled.name).to eq(:iso)
|
83
|
+
expect(compiled.infotype).to be_a(BuiltinType)
|
84
|
+
expect(compiled.dresser).to be_a(Proc)
|
85
|
+
expect(compiled.undresser).to be_a(Proc)
|
92
86
|
end
|
93
87
|
|
94
88
|
it 'has expected AST' do
|
95
|
-
ast.
|
89
|
+
expect(ast).to eq([
|
96
90
|
:contract,
|
97
91
|
"iso",
|
98
92
|
[:builtin_type, "String"],
|
@@ -111,17 +105,16 @@ module Finitio
|
|
111
105
|
subject.compile(type_factory, nil)
|
112
106
|
}
|
113
107
|
|
114
|
-
it 'compiles to the expected
|
115
|
-
compiled.
|
116
|
-
compiled.
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
contract[2].should be_a(Method)
|
108
|
+
it 'compiles to the expected Contract' do
|
109
|
+
expect(compiled).to be_a(Contract)
|
110
|
+
expect(compiled.name).to eq(:iso)
|
111
|
+
expect(compiled.infotype).to be_a(BuiltinType)
|
112
|
+
expect(compiled.dresser).to be_a(Method)
|
113
|
+
expect(compiled.undresser).to be_a(Method)
|
121
114
|
end
|
122
115
|
|
123
116
|
it 'has expected AST' do
|
124
|
-
ast.
|
117
|
+
expect(ast).to eq([
|
125
118
|
:contract,
|
126
119
|
"iso",
|
127
120
|
[:builtin_type, "String"],
|
@@ -14,12 +14,12 @@ module Finitio
|
|
14
14
|
let(:input){ 'a >= 10' }
|
15
15
|
|
16
16
|
it 'compiles to an Proc' do
|
17
|
-
compiled.
|
17
|
+
expect(compiled).to be_a(Proc)
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'should be the correct Proc' do
|
21
|
-
compiled.call(12).
|
22
|
-
compiled.call(9).
|
21
|
+
expect(compiled.call(12)).to eq(true)
|
22
|
+
expect(compiled.call(9)).to eq(false)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -27,7 +27,7 @@ module Finitio
|
|
27
27
|
let(:input){ '(a >= 10)' }
|
28
28
|
|
29
29
|
it 'compiles to an Proc' do
|
30
|
-
compiled.
|
30
|
+
expect(compiled).to be_a(Proc)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -35,7 +35,15 @@ module Finitio
|
|
35
35
|
let(:input){ 'acall(a)' }
|
36
36
|
|
37
37
|
it 'compiles to an Proc' do
|
38
|
-
compiled.
|
38
|
+
expect(compiled).to be_a(Proc)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 's =~ /^(test)$/' do
|
43
|
+
let(:input){ 's =~ /^(test)$/' }
|
44
|
+
|
45
|
+
it 'compiles to an Proc' do
|
46
|
+
expect(compiled).to be_a(Proc)
|
39
47
|
end
|
40
48
|
end
|
41
49
|
|
@@ -15,8 +15,8 @@ module Finitio
|
|
15
15
|
let(:input){ ' ' }
|
16
16
|
|
17
17
|
it 'compiles to a Heading' do
|
18
|
-
compiled.
|
19
|
-
compiled.to_name.
|
18
|
+
expect(compiled).to be_a(Heading)
|
19
|
+
expect(compiled.to_name).to eq('')
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -24,8 +24,8 @@ module Finitio
|
|
24
24
|
let(:input){ 'a: .Integer' }
|
25
25
|
|
26
26
|
it 'compiles to a Heading' do
|
27
|
-
compiled.
|
28
|
-
compiled.to_name.
|
27
|
+
expect(compiled).to be_a(Heading)
|
28
|
+
expect(compiled.to_name).to eq('a: Integer')
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -33,8 +33,26 @@ module Finitio
|
|
33
33
|
let(:input){ 'a: .Integer, b: .Float' }
|
34
34
|
|
35
35
|
it 'compiles to a Heading' do
|
36
|
-
compiled.
|
37
|
-
compiled.to_name.
|
36
|
+
expect(compiled).to be_a(Heading)
|
37
|
+
expect(compiled.to_name).to eq('a: Integer, b: Float')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'a: .Integer, b :? .Float' do
|
42
|
+
let(:input){ 'a: .Integer, b :? .Float' }
|
43
|
+
|
44
|
+
it 'compiles to a Heading' do
|
45
|
+
expect(compiled).to be_a(Heading)
|
46
|
+
expect(compiled.to_name).to eq('a: Integer, b :? Float')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'a: .Integer, ...' do
|
51
|
+
let(:input){ 'a: .Integer, ...' }
|
52
|
+
|
53
|
+
it 'compiles to a Heading' do
|
54
|
+
expect(compiled).to be_a(Heading)
|
55
|
+
expect(compiled.to_name).to eq('a: Integer, ...')
|
38
56
|
end
|
39
57
|
end
|
40
58
|
end
|
@@ -47,7 +65,7 @@ module Finitio
|
|
47
65
|
}
|
48
66
|
|
49
67
|
it{
|
50
|
-
ast.
|
68
|
+
expect(ast).to eq([
|
51
69
|
:heading,
|
52
70
|
[ :attribute, "a", [:builtin_type, "Integer" ]],
|
53
71
|
[ :attribute, "b", [:builtin_type, "Float" ]]
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Finitio
|
3
|
+
describe Syntax, "metadata" do
|
4
|
+
|
5
|
+
let(:match){
|
6
|
+
Syntax.parse(input, root: "metadata")
|
7
|
+
}
|
8
|
+
|
9
|
+
describe "value" do
|
10
|
+
subject{
|
11
|
+
match.value
|
12
|
+
}
|
13
|
+
|
14
|
+
context 'simple description' do
|
15
|
+
let(:input){ '/- Hello World -/' }
|
16
|
+
|
17
|
+
it{ should eq({description: "Hello World"}) }
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'tuple' do
|
21
|
+
let(:input){ '/- label: "Hello World" -/' }
|
22
|
+
|
23
|
+
it{ should eq({label: "Hello World"}) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -14,24 +14,24 @@ module Finitio
|
|
14
14
|
subject.to_ast('a')
|
15
15
|
}
|
16
16
|
|
17
|
-
context 'a >= 10' do
|
17
|
+
context 'foo: a >= 10' do
|
18
18
|
let(:input){ 'foo: a >= 10' }
|
19
19
|
|
20
|
-
it 'compiles to
|
21
|
-
compiled.
|
20
|
+
it 'compiles to a Constraint' do
|
21
|
+
expect(compiled).to be_a(Constraint)
|
22
22
|
end
|
23
23
|
|
24
|
-
it 'has expected
|
25
|
-
compiled.
|
24
|
+
it 'has expected name' do
|
25
|
+
expect(compiled.name).to eq(:foo)
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'should be the correct Proc' do
|
29
|
-
compiled
|
30
|
-
compiled
|
29
|
+
expect(compiled.===(12)).to eq(true)
|
30
|
+
expect(compiled.===(9)).to eq(false)
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'has the expected AST' do
|
34
|
-
ast.
|
34
|
+
expect(ast).to eq([
|
35
35
|
:constraint,
|
36
36
|
"foo",
|
37
37
|
[:fn, [:parameters, "a"], [:source, "a >= 10"]]
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Finitio
|
3
|
+
describe Syntax, "relation_type" do
|
4
|
+
|
5
|
+
subject{
|
6
|
+
Syntax.parse(input, root: "relation_type")
|
7
|
+
}
|
8
|
+
|
9
|
+
describe "compilation result" do
|
10
|
+
let(:compiled){
|
11
|
+
subject.compile(type_factory)
|
12
|
+
}
|
13
|
+
|
14
|
+
context 'empty heading' do
|
15
|
+
let(:input){ '{{ }}' }
|
16
|
+
|
17
|
+
it 'compiles to a RelationType' do
|
18
|
+
expect(compiled).to be_a(RelationType)
|
19
|
+
expect(compiled.heading).to be_empty
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context '{{a: .Integer}}' do
|
24
|
+
let(:input){ '{{a: .Integer}}' }
|
25
|
+
|
26
|
+
it 'compiles to a RelationType' do
|
27
|
+
expect(compiled).to be_a(RelationType)
|
28
|
+
expect(compiled.heading.size).to eq(1)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context '{{a: .Integer, b: .Float}}' do
|
33
|
+
let(:input){ '{{a: .Integer, b: .Float}}' }
|
34
|
+
|
35
|
+
it 'compiles to a RelationType' do
|
36
|
+
expect(compiled).to be_a(RelationType)
|
37
|
+
expect(compiled.heading.size).to eq(2)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context '{{a: .Integer, b :? .Float}}' do
|
42
|
+
let(:input){ '{{a: .Integer, b :? .Float}}' }
|
43
|
+
|
44
|
+
it 'compiles to a MultiRelationType' do
|
45
|
+
expect(compiled).to be_a(MultiRelationType)
|
46
|
+
expect(compiled.heading.size).to eq(2)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "AST" do
|
52
|
+
let(:ast){ subject.to_ast }
|
53
|
+
|
54
|
+
context '{{a: .Integer}}' do
|
55
|
+
let(:input){ '{{a: .Integer}}' }
|
56
|
+
|
57
|
+
it{
|
58
|
+
expect(ast).to eq([
|
59
|
+
:relation_type,
|
60
|
+
[
|
61
|
+
:heading,
|
62
|
+
[ :attribute, "a", [:builtin_type, "Integer" ]]
|
63
|
+
]
|
64
|
+
])
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
context '{{a :? .Integer}}' do
|
69
|
+
let(:input){ '{{a :? .Integer}}' }
|
70
|
+
|
71
|
+
it{
|
72
|
+
expect(ast).to eq([
|
73
|
+
:multi_relation_type,
|
74
|
+
[
|
75
|
+
:heading,
|
76
|
+
[ :attribute, "a", [:builtin_type, "Integer" ], false]
|
77
|
+
]
|
78
|
+
])
|
79
|
+
}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
@@ -15,9 +15,9 @@ module Finitio
|
|
15
15
|
let(:input){ '[.Integer]' }
|
16
16
|
|
17
17
|
it 'compiles to a SeqType' do
|
18
|
-
compiled.
|
19
|
-
compiled.elm_type.
|
20
|
-
compiled.elm_type.ruby_type.
|
18
|
+
expect(compiled).to be_a(SeqType)
|
19
|
+
expect(compiled.elm_type).to be_a(BuiltinType)
|
20
|
+
expect(compiled.elm_type.ruby_type).to be(Integer)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -27,7 +27,7 @@ module Finitio
|
|
27
27
|
|
28
28
|
let(:ast){ subject.to_ast }
|
29
29
|
|
30
|
-
it{ ast.
|
30
|
+
it{ expect(ast).to eq([
|
31
31
|
:seq_type,
|
32
32
|
[:builtin_type, "Integer"]
|
33
33
|
])
|
@@ -15,9 +15,9 @@ module Finitio
|
|
15
15
|
let(:input){ '{.Integer}' }
|
16
16
|
|
17
17
|
it 'compiles to a SeqType' do
|
18
|
-
compiled.
|
19
|
-
compiled.elm_type.
|
20
|
-
compiled.elm_type.ruby_type.
|
18
|
+
expect(compiled).to be_a(SetType)
|
19
|
+
expect(compiled.elm_type).to be_a(BuiltinType)
|
20
|
+
expect(compiled.elm_type.ruby_type).to be(Integer)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -27,7 +27,7 @@ module Finitio
|
|
27
27
|
|
28
28
|
let(:ast){ subject.to_ast }
|
29
29
|
|
30
|
-
it{ ast.
|
30
|
+
it{ expect(ast).to eq([
|
31
31
|
:set_type,
|
32
32
|
[:builtin_type, "Integer"]
|
33
33
|
])
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Finitio
|
3
|
+
describe Syntax, "struct_type" do
|
4
|
+
|
5
|
+
subject{
|
6
|
+
Syntax.parse(input, root: "struct_type")
|
7
|
+
}
|
8
|
+
|
9
|
+
describe "compilation result" do
|
10
|
+
let(:compiled){
|
11
|
+
subject.compile(type_factory)
|
12
|
+
}
|
13
|
+
|
14
|
+
context '<.Integer, .Float>' do
|
15
|
+
let(:input){ '<.Integer, .Float>' }
|
16
|
+
|
17
|
+
it 'compiles to a StructType' do
|
18
|
+
expect(compiled).to be_a(StructType)
|
19
|
+
expect(compiled.component_types).to eq([intType, floatType])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "AST" do
|
25
|
+
let(:input){ '<.Integer, .Float>' }
|
26
|
+
|
27
|
+
let(:ast){ subject.to_ast }
|
28
|
+
|
29
|
+
it{ expect(ast).to eq([
|
30
|
+
:struct_type,
|
31
|
+
[:builtin_type, "Integer"],
|
32
|
+
[:builtin_type, "Float"]
|
33
|
+
])
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|