finitio 0.7.0.pre.rc4 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +42 -0
- data/Gemfile +1 -11
- data/Gemfile.lock +101 -54
- data/README.md +89 -13
- data/finitio.gemspec +9 -157
- data/lib/finitio.rb +7 -5
- data/lib/finitio/generation.rb +106 -0
- data/lib/finitio/generation/ad_type.rb +10 -0
- data/lib/finitio/generation/alias_type.rb +9 -0
- data/lib/finitio/generation/any_type.rb +11 -0
- data/lib/finitio/generation/builtin_type.rb +9 -0
- data/lib/finitio/generation/hash_based_type.rb +15 -0
- data/lib/finitio/generation/heuristic.rb +8 -0
- data/lib/finitio/generation/heuristic/constant.rb +30 -0
- data/lib/finitio/generation/heuristic/random.rb +52 -0
- data/lib/finitio/generation/rel_based_type.rb +13 -0
- data/lib/finitio/generation/seq_type.rb +13 -0
- data/lib/finitio/generation/set_type.rb +13 -0
- data/lib/finitio/generation/sub_type.rb +9 -0
- data/lib/finitio/generation/union_type.rb +10 -0
- data/lib/finitio/inference.rb +51 -0
- data/lib/finitio/json_schema.rb +16 -0
- data/lib/finitio/json_schema/ad_type.rb +11 -0
- data/lib/finitio/json_schema/alias_type.rb +9 -0
- data/lib/finitio/json_schema/any_type.rb +9 -0
- data/lib/finitio/json_schema/builtin_type.rb +27 -0
- data/lib/finitio/json_schema/hash_based_type.rb +25 -0
- data/lib/finitio/json_schema/rel_based_type.rb +13 -0
- data/lib/finitio/json_schema/seq_type.rb +12 -0
- data/lib/finitio/json_schema/set_type.rb +13 -0
- data/lib/finitio/json_schema/struct_type.rb +12 -0
- data/lib/finitio/json_schema/sub_type.rb +10 -0
- data/lib/finitio/json_schema/union_type.rb +11 -0
- data/lib/finitio/support.rb +18 -0
- data/lib/finitio/support/attribute.rb +8 -0
- data/lib/finitio/support/compilation.rb +18 -18
- data/lib/finitio/support/contract.rb +10 -2
- data/lib/finitio/support/fetch_scope.rb +19 -0
- data/lib/finitio/support/heading.rb +42 -1
- data/lib/finitio/syntax.rb +1 -1
- data/lib/finitio/syntax/lexer.citrus +1 -1
- data/lib/finitio/syntax/type.rb +2 -0
- data/lib/finitio/syntax/type/high_order_type_instantiation.rb +29 -0
- data/lib/finitio/syntax/type/high_order_vars.rb +16 -0
- data/lib/finitio/syntax/type/type_def.rb +11 -1
- data/lib/finitio/syntax/types.citrus +14 -1
- data/lib/finitio/system.rb +18 -4
- data/lib/finitio/type.rb +19 -0
- data/lib/finitio/type/ad_type.rb +9 -1
- data/lib/finitio/type/alias_type.rb +8 -0
- data/lib/finitio/type/any_type.rb +12 -0
- data/lib/finitio/type/builtin_type.rb +4 -0
- data/lib/finitio/type/collection_type.rb +15 -0
- data/lib/finitio/type/heading_based_type.rb +17 -0
- data/lib/finitio/type/high_order_type.rb +39 -0
- data/lib/finitio/type/multi_relation_type.rb +4 -0
- data/lib/finitio/type/multi_tuple_type.rb +4 -0
- data/lib/finitio/type/proxy_type.rb +10 -20
- data/lib/finitio/type/relation_type.rb +4 -0
- data/lib/finitio/type/seq_type.rb +1 -1
- data/lib/finitio/type/struct_type.rb +8 -0
- data/lib/finitio/type/sub_type.rb +8 -0
- data/lib/finitio/type/tuple_type.rb +4 -0
- data/lib/finitio/type/union_type.rb +19 -0
- data/lib/finitio/version.rb +2 -2
- data/spec/finitio/test_system.rb +0 -11
- data/spec/generation/test_generation.rb +169 -0
- data/spec/heading/test_looks_similar.rb +45 -0
- data/spec/heading/test_suppremum.rb +56 -0
- data/spec/inference/test_inference.rb +42 -0
- data/spec/json_schema/test_ad_type.rb +20 -0
- data/spec/json_schema/test_alias_type.rb +15 -0
- data/spec/json_schema/test_any_type.rb +11 -0
- data/spec/json_schema/test_builtin_type.rb +51 -0
- data/spec/json_schema/test_multi_relation_type.rb +58 -0
- data/spec/json_schema/test_multi_tuple_type.rb +50 -0
- data/spec/json_schema/test_relation_type.rb +30 -0
- data/spec/json_schema/test_seq_type.rb +18 -0
- data/spec/json_schema/test_set_type.rb +19 -0
- data/spec/json_schema/test_struct_type.rb +18 -0
- data/spec/json_schema/test_sub_type.rb +17 -0
- data/spec/json_schema/test_tuple_type.rb +26 -0
- data/spec/json_schema/test_union_type.rb +17 -0
- data/spec/regression/test_heading_extra_are_proxy_resolved.rb +41 -0
- data/spec/spec_helper.rb +32 -6
- data/spec/support/test_compare_attrs.rb +67 -0
- data/spec/syntax/test_compile.rb +57 -0
- data/spec/system/fixtures/system.fio +2 -0
- data/spec/{finitio → system/fixtures}/with-duplicates.fio +2 -1
- data/spec/system/test_check_and_warn.rb +55 -0
- data/spec/type/ad_type/test_initialize.rb +1 -8
- data/spec/type/relation_type/test_suppremum.rb +104 -0
- data/spec/type/seq_type/test_suppremum.rb +54 -0
- data/spec/type/set_type/test_suppremum.rb +54 -0
- data/spec/type/test_suppremum.rb +49 -0
- data/spec/type/test_unconstrained.rb +150 -0
- data/spec/type/tuple_type/test_suppremum.rb +119 -0
- data/spec/type/union_type/test_suppremum.rb +51 -0
- data/tasks/test.rake +1 -1
- metadata +203 -17
- data/spec/type/proxy_type/test_delegation.rb +0 -37
- data/spec/type/proxy_type/test_resolve.rb +0 -29
@@ -0,0 +1,58 @@
|
|
1
|
+
module Finitio
|
2
|
+
module JsonSchema
|
3
|
+
describe "MultiRelationType" do
|
4
|
+
|
5
|
+
context 'with a true allow extra and some optional attribute' do
|
6
|
+
let(:heading){
|
7
|
+
Heading.new([
|
8
|
+
Attribute.new(:a, anyType),
|
9
|
+
Attribute.new(:b, anyType, false),
|
10
|
+
], allow_extra: true)
|
11
|
+
}
|
12
|
+
|
13
|
+
let(:multi_relation_type) {
|
14
|
+
MultiRelationType.new(heading)
|
15
|
+
}
|
16
|
+
|
17
|
+
it 'works as expected' do
|
18
|
+
expect(multi_relation_type.to_json_schema).to eql({
|
19
|
+
type: "array",
|
20
|
+
items: {
|
21
|
+
type: "object",
|
22
|
+
properties: {
|
23
|
+
a: {},
|
24
|
+
b: {}
|
25
|
+
},
|
26
|
+
required: [:a],
|
27
|
+
additionalProperties: {}
|
28
|
+
},
|
29
|
+
uniqueItems: true
|
30
|
+
})
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'with a allow extra requiring Strings' do
|
35
|
+
let(:heading){
|
36
|
+
Heading.new([
|
37
|
+
], allow_extra: BuiltinType.new(String))
|
38
|
+
}
|
39
|
+
|
40
|
+
let(:multi_relation_type) {
|
41
|
+
MultiRelationType.new(heading)
|
42
|
+
}
|
43
|
+
|
44
|
+
it 'works as expected' do
|
45
|
+
expect(multi_relation_type.to_json_schema).to eql({
|
46
|
+
type: "array",
|
47
|
+
items: {
|
48
|
+
type: "object",
|
49
|
+
additionalProperties: { type: "string" }
|
50
|
+
},
|
51
|
+
uniqueItems: true
|
52
|
+
})
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Finitio
|
2
|
+
module JsonSchema
|
3
|
+
describe "MultiTupleType" do
|
4
|
+
|
5
|
+
context 'with a true allow extra and some optional attribute' do
|
6
|
+
let(:heading){
|
7
|
+
Heading.new([
|
8
|
+
Attribute.new(:a, anyType),
|
9
|
+
Attribute.new(:b, anyType, false),
|
10
|
+
], allow_extra: true)
|
11
|
+
}
|
12
|
+
|
13
|
+
let(:multi_tuple_type) {
|
14
|
+
MultiTupleType.new(heading)
|
15
|
+
}
|
16
|
+
|
17
|
+
it 'works as expected' do
|
18
|
+
expect(multi_tuple_type.to_json_schema).to eql({
|
19
|
+
type: "object",
|
20
|
+
properties: {
|
21
|
+
a: {},
|
22
|
+
b: {}
|
23
|
+
},
|
24
|
+
required: [:a],
|
25
|
+
additionalProperties: {}
|
26
|
+
})
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'with a allow extra requiring Strings' do
|
31
|
+
let(:heading){
|
32
|
+
Heading.new([
|
33
|
+
], allow_extra: BuiltinType.new(String))
|
34
|
+
}
|
35
|
+
|
36
|
+
let(:multi_tuple_type) {
|
37
|
+
MultiTupleType.new(heading)
|
38
|
+
}
|
39
|
+
|
40
|
+
it 'works as expected' do
|
41
|
+
expect(multi_tuple_type.to_json_schema).to eql({
|
42
|
+
type: "object",
|
43
|
+
additionalProperties: { type: "string" }
|
44
|
+
})
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Finitio
|
2
|
+
module JsonSchema
|
3
|
+
describe "RelationType" do
|
4
|
+
|
5
|
+
let(:heading){
|
6
|
+
Heading.new([Attribute.new(:a, anyType)])
|
7
|
+
}
|
8
|
+
|
9
|
+
let(:tuple_type) {
|
10
|
+
RelationType.new(heading)
|
11
|
+
}
|
12
|
+
|
13
|
+
it 'works as expected' do
|
14
|
+
expect(tuple_type.to_json_schema).to eql({
|
15
|
+
type: "array",
|
16
|
+
items: {
|
17
|
+
type: "object",
|
18
|
+
properties: {
|
19
|
+
a: {}
|
20
|
+
},
|
21
|
+
required: [:a],
|
22
|
+
additionalProperties: false
|
23
|
+
},
|
24
|
+
uniqueItems: true
|
25
|
+
})
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Finitio
|
2
|
+
module JsonSchema
|
3
|
+
describe "SetType" do
|
4
|
+
|
5
|
+
let(:type) {
|
6
|
+
SetType.new(anyType)
|
7
|
+
}
|
8
|
+
|
9
|
+
it 'works as expected' do
|
10
|
+
expect(type.to_json_schema).to eql({
|
11
|
+
type: "array",
|
12
|
+
items: {},
|
13
|
+
uniqueItems: true
|
14
|
+
})
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Finitio
|
2
|
+
module JsonSchema
|
3
|
+
describe "StructType" do
|
4
|
+
|
5
|
+
let(:type) {
|
6
|
+
StructType.new([anyType,anyType])
|
7
|
+
}
|
8
|
+
|
9
|
+
it 'works as expected' do
|
10
|
+
expect(type.to_json_schema).to eql({
|
11
|
+
type: "array",
|
12
|
+
items: [{},{}]
|
13
|
+
})
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Finitio
|
2
|
+
module JsonSchema
|
3
|
+
describe "TupleType" do
|
4
|
+
|
5
|
+
let(:heading){
|
6
|
+
Heading.new([Attribute.new(:a, anyType)])
|
7
|
+
}
|
8
|
+
|
9
|
+
let(:tuple_type) {
|
10
|
+
TupleType.new(heading)
|
11
|
+
}
|
12
|
+
|
13
|
+
it 'works as expected' do
|
14
|
+
expect(tuple_type.to_json_schema).to eql({
|
15
|
+
type: "object",
|
16
|
+
properties: {
|
17
|
+
a: {}
|
18
|
+
},
|
19
|
+
required: [:a],
|
20
|
+
additionalProperties: false
|
21
|
+
})
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Heading extra are properly resolved" do
|
4
|
+
|
5
|
+
describe "When the extra map to a type" do
|
6
|
+
let(:schema){
|
7
|
+
Finitio.system <<~F
|
8
|
+
Type = { ... : World }
|
9
|
+
World = .String
|
10
|
+
Type
|
11
|
+
F
|
12
|
+
}
|
13
|
+
|
14
|
+
it 'works' do
|
15
|
+
expect(schema.dress("hello" => "World")).to eql(hello: "World")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "When the extra maps to nothing" do
|
20
|
+
let(:schema){
|
21
|
+
Finitio.system <<~F
|
22
|
+
{
|
23
|
+
hello: .String
|
24
|
+
...
|
25
|
+
}
|
26
|
+
F
|
27
|
+
}
|
28
|
+
|
29
|
+
it 'works' do
|
30
|
+
expect(schema.dress("hello" => "World")).to eql(hello: "World")
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'supports extra' do
|
34
|
+
expect(schema.dress({
|
35
|
+
"hello" => "World",
|
36
|
+
"extra" => "Foo"
|
37
|
+
})).to eql(hello: "World")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,6 +2,8 @@ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
2
|
require 'path'
|
3
3
|
require 'finitio'
|
4
4
|
require 'finitio/syntax'
|
5
|
+
require 'finitio/generation'
|
6
|
+
require 'finitio/json_schema'
|
5
7
|
|
6
8
|
require 'coveralls'
|
7
9
|
Coveralls.wear!
|
@@ -49,15 +51,27 @@ module SpecHelpers
|
|
49
51
|
end
|
50
52
|
|
51
53
|
def intType
|
52
|
-
Finitio::BuiltinType.new(Integer, "intType")
|
54
|
+
@intType ||= Finitio::BuiltinType.new(Integer, "intType")
|
53
55
|
end
|
54
56
|
|
55
57
|
def floatType
|
56
|
-
Finitio::BuiltinType.new(Float, "floatType")
|
58
|
+
@floatType ||= Finitio::BuiltinType.new(Float, "floatType")
|
57
59
|
end
|
58
60
|
|
59
61
|
def nilType
|
60
|
-
Finitio::BuiltinType.new(NilClass, "nilType")
|
62
|
+
@nilType ||= Finitio::BuiltinType.new(NilClass, "nilType")
|
63
|
+
end
|
64
|
+
|
65
|
+
def trueType
|
66
|
+
@trueType ||= Finitio::BuiltinType.new(TrueClass, "trueType")
|
67
|
+
end
|
68
|
+
|
69
|
+
def falseType
|
70
|
+
@falseType ||= Finitio::BuiltinType.new(FalseClass, "falseType")
|
71
|
+
end
|
72
|
+
|
73
|
+
def stringType
|
74
|
+
@stringType ||= Finitio::BuiltinType.new(String, "stringType")
|
61
75
|
end
|
62
76
|
|
63
77
|
def byte_full
|
@@ -81,15 +95,19 @@ module SpecHelpers
|
|
81
95
|
end
|
82
96
|
|
83
97
|
def byte
|
84
|
-
Finitio::SubType.new(intType, [byte_full])
|
98
|
+
@byte ||= Finitio::SubType.new(intType, [byte_full])
|
99
|
+
end
|
100
|
+
|
101
|
+
def pos_byte
|
102
|
+
@pos_byte ||= Finitio::SubType.new(byte, [positive])
|
85
103
|
end
|
86
104
|
|
87
105
|
def posInt
|
88
|
-
Finitio::SubType.new(intType, [positive])
|
106
|
+
@posInt ||= Finitio::SubType.new(intType, [positive])
|
89
107
|
end
|
90
108
|
|
91
109
|
def negInt
|
92
|
-
Finitio::SubType.new(intType, [negative])
|
110
|
+
@negInt ||= Finitio::SubType.new(intType, [negative])
|
93
111
|
end
|
94
112
|
|
95
113
|
def type_factory
|
@@ -104,6 +122,14 @@ module SpecHelpers
|
|
104
122
|
Color.new(138, 43, 226)
|
105
123
|
end
|
106
124
|
|
125
|
+
def rgb_contract
|
126
|
+
@rgb_contract ||= Finitio::Contract.new(byte, Color.method(:rgb), Finitio::IDENTITY, :rgb)
|
127
|
+
end
|
128
|
+
|
129
|
+
def hex_contract
|
130
|
+
@hex_contract ||= Finitio::Contract.new(stringType, Color.method(:hex), Finitio::IDENTITY, :hex)
|
131
|
+
end
|
132
|
+
|
107
133
|
end
|
108
134
|
|
109
135
|
RSpec.configure do |c|
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Finitio
|
3
|
+
describe Support, "compare_attrs" do
|
4
|
+
include Support
|
5
|
+
|
6
|
+
context 'with arrays' do
|
7
|
+
it 'works on same attrs' do
|
8
|
+
h1 = [:a, :b]
|
9
|
+
h2 = [:b, :a]
|
10
|
+
shared, mine, yours = compare_attrs(h1, h2)
|
11
|
+
expect(shared).to eql([:a, :b])
|
12
|
+
expect(mine).to eql([])
|
13
|
+
expect(yours).to eql([])
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'works on not same attrs' do
|
17
|
+
h1 = [ :a, :b ]
|
18
|
+
h2 = [ :c, :a ]
|
19
|
+
shared, mine, yours = compare_attrs(h1, h2)
|
20
|
+
expect(shared).to eql([:a])
|
21
|
+
expect(mine).to eql([:b])
|
22
|
+
expect(yours).to eql([:c])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'with hashes' do
|
27
|
+
it 'works on same attrs' do
|
28
|
+
h1 = { a: 1, b: 2 }
|
29
|
+
h2 = { a: 1, b: 2 }
|
30
|
+
shared, mine, yours = compare_attrs(h1, h2)
|
31
|
+
expect(shared).to eql([:a, :b])
|
32
|
+
expect(mine).to eql([])
|
33
|
+
expect(yours).to eql([])
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'works on not same attrs' do
|
37
|
+
h1 = { a: 1, b: 2 }
|
38
|
+
h2 = { a: 1, c: 2 }
|
39
|
+
shared, mine, yours = compare_attrs(h1, h2)
|
40
|
+
expect(shared).to eql([:a])
|
41
|
+
expect(mine).to eql([:b])
|
42
|
+
expect(yours).to eql([:c])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'with a block' do
|
47
|
+
it 'works on same attrs' do
|
48
|
+
h1 = [{:name => :a}, {:name => :b}]
|
49
|
+
h2 = [{:name => :b}, {:name => :a}]
|
50
|
+
shared, mine, yours = compare_attrs(h1, h2){|a| a[:name] }
|
51
|
+
expect(shared).to eql([:a, :b])
|
52
|
+
expect(mine).to eql([])
|
53
|
+
expect(yours).to eql([])
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'works on not same attrs' do
|
57
|
+
h1 = [{:name => :a}, {:name => :b}]
|
58
|
+
h2 = [{:name => :c}, {:name => :a}]
|
59
|
+
shared, mine, yours = compare_attrs(h1, h2){|a| a[:name] }
|
60
|
+
expect(shared).to eql([:a])
|
61
|
+
expect(mine).to eql([:b])
|
62
|
+
expect(yours).to eql([:c])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|