finitio 0.7.0.pre.rc2 → 0.7.0.pre.rc3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b4c180986cc7160e2b3f76c23e37d23237cbaaf
4
- data.tar.gz: b26dd47b86792ad28524e5e8f8df0ab5d56d0071
3
+ metadata.gz: bceafae3cf07b42eeafcd42847e29426ee8b9694
4
+ data.tar.gz: 947dd8fccf1bc29439a8948e18850f7e53f502b9
5
5
  SHA512:
6
- metadata.gz: b19ef54ca53c5e463aa6b4557d0ecd6ea537e6cdaa9349f960356b1b31525908be7d1a196cc2be9ab4985f70eea4133d2c54c03d3ee57b14cf48175efe7aaf02
7
- data.tar.gz: 14d1db5a7285d522ce1ab093a5dc712f52b0c846b84e582e86fedbdfbd1320e6eafa7741b907f553aabdb29094bc7ebecf0b1a54a6358cc2ac9b761ae2289238
6
+ metadata.gz: 541944fb0f9e729886145707c46f88c70677a9ea63272021e9fa67d083b867a2ec35c24e1035763c04c21ab8006cccd111717c144c40ed297c06e0b8b6b7ec4a
7
+ data.tar.gz: 297ce451632080bd09e888c2e16fe1991722485375348ce08b06225c2a15b3f34220a805e05f22fcb623e37aba26e982629c89709b1c643ee8af13f8f63a733e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- finitio (0.7.0.pre.rc2)
4
+ finitio (0.7.0.pre.rc3)
5
5
  citrus (>= 2.4, < 4.0)
6
6
 
7
7
  GEM
@@ -1,3 +1,4 @@
1
+ require_relative 'support/proc_with_code'
1
2
  require_relative 'support/metadata'
2
3
  require_relative 'support/attribute'
3
4
  require_relative 'support/constraint'
@@ -29,5 +29,20 @@ module Finitio
29
29
  @undresser = clazz.instance_method(:"to_#{name}")
30
30
  end
31
31
 
32
+ def hash
33
+ [infotype, dresser, undresser].hash
34
+ end
35
+
36
+ def ==(other)
37
+ super || (
38
+ other.is_a?(Contract) &&
39
+ name == other.name &&
40
+ infotype == other.infotype &&
41
+ dresser == other.dresser &&
42
+ undresser == other.undresser
43
+ )
44
+ end
45
+ alias :eql? :==
46
+
32
47
  end # class Contract
33
48
  end # module Finitio
@@ -0,0 +1,34 @@
1
+ module Finitio
2
+ class ProcWithCode < Proc
3
+
4
+ def self.new(*args, &bl)
5
+ return Proc.new(*args, &bl) unless args.size == 2 && bl.nil?
6
+
7
+ p = Kernel.eval("->(#{args.first}){ #{args.last} }")
8
+ p.instance_variable_set(:@_finitio_src, args)
9
+
10
+ def p.finitio_src
11
+ @_finitio_src
12
+ end
13
+
14
+ def p.hash
15
+ @_finitio_src.hash
16
+ end
17
+
18
+ def p.==(other)
19
+ super || (
20
+ other.is_a?(Proc) &&
21
+ other.respond_to?(:finitio_src) &&
22
+ other.finitio_src == self.finitio_src
23
+ )
24
+ end
25
+
26
+ def p.eql?(other)
27
+ self.==(other)
28
+ end
29
+
30
+ p
31
+ end
32
+
33
+ end # module ProcWithCode
34
+ end # module Finitio
@@ -4,8 +4,7 @@ module Finitio
4
4
  include Node
5
5
 
6
6
  def compile(var_name)
7
- expr = "->(#{var_name}){ #{to_str} }"
8
- ::Kernel.eval(expr)
7
+ ProcWithCode.new(var_name, to_str)
9
8
  end
10
9
 
11
10
  end # module Expression
@@ -131,5 +131,18 @@ module Finitio
131
131
  handler.failed!(self, value, error)
132
132
  end
133
133
 
134
+ def hash
135
+ [ ruby_type, contracts ].hash
136
+ end
137
+
138
+ def ==(other)
139
+ super || (
140
+ other.is_a?(AdType) &&
141
+ ruby_type == other.ruby_type &&
142
+ contracts == other.contracts
143
+ )
144
+ end
145
+ alias :eql? :==
146
+
134
147
  end # class AdType
135
148
  end # module Finitio
@@ -3,7 +3,7 @@ module Finitio
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 7
6
- TINY = "0-rc2"
6
+ TINY = "0-rc3"
7
7
 
8
8
  def self.to_s
9
9
  [ MAJOR, MINOR, TINY ].join('.')
@@ -30,8 +30,11 @@ describe Finitio, "system" do
30
30
  end
31
31
 
32
32
  context "feedback about duplicate types" do
33
+ before {
34
+ Finitio.stdlib_path(Path.dir.parent)
35
+ }
33
36
  subject{
34
- Finitio.system(Path.dir/"with-duplicates.fio")
37
+ Finitio.system(Path.dir/"with-duplicates.fio").check_and_warn
35
38
  }
36
39
 
37
40
  it{ should be_a(Finitio::System) }
@@ -1,3 +1,5 @@
1
1
  @import finitio/data
2
+ @import finitio/system
2
3
 
3
4
  NilClass = .NilClass
5
+ Posint = .Integer( i | i >= 0 )
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ module Finitio
3
+ describe ProcWithCode do
4
+
5
+ it 'acts like a proc' do
6
+ p = ProcWithCode.new{|t| t>0 }
7
+ expect(p).to be_a(Proc)
8
+ expect(p.call(2)).to eq(true)
9
+ expect(p.call(-2)).to eq(false)
10
+ end
11
+
12
+ it 'lets compile from source code' do
13
+ p = ProcWithCode.new("t", "t>0")
14
+ expect(p).to be_a(Proc)
15
+ expect(p.call(2)).to eq(true)
16
+ expect(p.call(-2)).to eq(false)
17
+ end
18
+
19
+ it 'yields equal procs for same source code' do
20
+ p1 = ProcWithCode.new("t", "t>0")
21
+ p2 = ProcWithCode.new("t", "t>0")
22
+ expect(p1).to eql(p2)
23
+ expect(p1.hash).to eql(p2.hash)
24
+ end
25
+
26
+ end
27
+ end
@@ -43,6 +43,7 @@ module Finitio
43
43
  ]
44
44
  ])
45
45
  end
46
+
46
47
  end
47
48
 
48
49
  context 'Two contracts' do
@@ -160,6 +161,11 @@ module Finitio
160
161
  ]
161
162
  ])
162
163
  end
164
+
165
+ it 'is equal to itself' do
166
+ j = Syntax.parse(input, root: "ad_type").compile(type_factory)
167
+ expect(j).to eql(compiled)
168
+ end
163
169
  end
164
170
 
165
171
  end
@@ -96,6 +96,11 @@ module Finitio
96
96
  ]
97
97
  ])
98
98
  end
99
+
100
+ it 'is equal to itself by code' do
101
+ j = Syntax.parse(input, root: "contract").compile(type_factory, nil)
102
+ expect(j).to eql(compiled)
103
+ end
99
104
  end
100
105
 
101
106
  context 'A contract with external dressers' do
@@ -21,6 +21,11 @@ module Finitio
21
21
  expect(compiled.call(12)).to eq(true)
22
22
  expect(compiled.call(9)).to eq(false)
23
23
  end
24
+
25
+ it 'is equal to itself' do
26
+ j = Syntax.parse(input, root: "expression").compile("a")
27
+ expect(j).to eq(compiled)
28
+ end
24
29
  end
25
30
 
26
31
  context '(a >= 10)' do
@@ -30,6 +30,11 @@ module Finitio
30
30
  [:constraint, "default", [:fn, [:parameters, "i"], [:source, "i >= 0"]]]
31
31
  ])
32
32
  end
33
+
34
+ it 'is equal to the same type' do
35
+ j = Syntax.parse(input, root: "sub_type").compile(type_factory)
36
+ expect(j).to eq(compiled)
37
+ end
33
38
  end
34
39
 
35
40
  context '.Integer( i | positive: i >= 0 )' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: finitio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0.pre.rc2
4
+ version: 0.7.0.pre.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Lambeau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-21 00:00:00.000000000 Z
11
+ date: 2019-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: citrus
@@ -59,6 +59,7 @@ files:
59
59
  - lib/finitio/support/dress_helper.rb
60
60
  - lib/finitio/support/heading.rb
61
61
  - lib/finitio/support/metadata.rb
62
+ - lib/finitio/support/proc_with_code.rb
62
63
  - lib/finitio/support/type_factory.rb
63
64
  - lib/finitio/syntax.rb
64
65
  - lib/finitio/syntax/definitions.rb
@@ -163,6 +164,7 @@ files:
163
164
  - spec/heading/test_size.rb
164
165
  - spec/heading/test_to_name.rb
165
166
  - spec/spec_helper.rb
167
+ - spec/support/test_proc_with_code.rb
166
168
  - spec/syntax/expr/test_free_variables.rb
167
169
  - spec/syntax/expr/test_to_proc_source.rb
168
170
  - spec/syntax/nodes/imported.fio
@@ -446,6 +448,7 @@ test_files:
446
448
  - spec/type/multi_tuple_type/test_include.rb
447
449
  - spec/type/multi_tuple_type/test_default_name.rb
448
450
  - spec/type/multi_tuple_type/test_dress.rb
451
+ - spec/support/test_proc_with_code.rb
449
452
  - spec/syntax/nodes/test_tuple_type.rb
450
453
  - spec/syntax/nodes/test_set_type.rb
451
454
  - spec/syntax/nodes/test_union_type.rb