This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
covers 'facets/proc/bind'
|
||||
|
||||
test_case Proc do
|
||||
|
||||
# Not sure why this is thread critical?
|
||||
method :bind do
|
||||
test "thread critial" do
|
||||
a = 2
|
||||
tproc = lambda { |x| x + a }
|
||||
99.times {
|
||||
tmethod = tproc.bind(self) #to_method
|
||||
tmethod.call(1).assert == 3
|
||||
}
|
||||
|
||||
meths = (
|
||||
Object.instance_methods +
|
||||
Object.public_instance_methods +
|
||||
Object.private_instance_methods +
|
||||
Object.protected_instance_methods
|
||||
)
|
||||
meths = meths.select{ |s| s.to_s =~ /^_bind_/ }
|
||||
#meths = Symbol.all_symbols.select { |s| s.to_s =~ /^_bind_/ } # why?
|
||||
|
||||
meths.size.assert == 0
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,17 @@
|
||||
covers 'facets/proc/bind_to'
|
||||
|
||||
test_case Proc do
|
||||
|
||||
method :bind_to do
|
||||
|
||||
test do
|
||||
a = [1,2,3]
|
||||
p1 = Proc.new{ join(' ') }
|
||||
p2 = p1.bind_to(a)
|
||||
p2.call.assert == '1 2 3'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
covers 'facets/proc/compose'
|
||||
|
||||
test_case Proc do
|
||||
|
||||
method :compose do
|
||||
|
||||
test do
|
||||
a = lambda { |x| x + 4 }
|
||||
b = lambda { |y| y / 2 }
|
||||
(a.compose(b)).call(4).assert == 6
|
||||
(b.compose(a)).call(4).assert == 4
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
method :* do
|
||||
|
||||
test do
|
||||
a = lambda { |x| x + 4 }
|
||||
b = lambda { |y| y / 2 }
|
||||
(a * b).call(4).assert == 6
|
||||
(b * a).call(4).assert == 4
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,27 @@
|
||||
covers 'facets/proc/partial'
|
||||
|
||||
test_case Proc do
|
||||
|
||||
method :partial do
|
||||
|
||||
test "first argument" do
|
||||
f = Proc.new{ |a,b,c| a + b + c }
|
||||
n = f.partial(NA,2,3)
|
||||
n[1].assert == 6
|
||||
end
|
||||
|
||||
test "second argument" do
|
||||
f = Proc.new{ |a,b,c| a + b + c }
|
||||
n = f.partial(1,NA,3)
|
||||
n[2].assert == 6
|
||||
end
|
||||
|
||||
test "third argument" do
|
||||
f = Proc.new{ |a,b,c| a + b + c }
|
||||
n = f.partial(1,2,NA)
|
||||
n[3].assert == 6
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,43 @@
|
||||
covers 'facets/proc/to_method'
|
||||
|
||||
test_case Proc do
|
||||
|
||||
method :to_method do
|
||||
|
||||
test do
|
||||
o = Object.new
|
||||
tproc = proc { |x| x + 2 }
|
||||
|
||||
tmeth = tproc.to_method(o, :tryit)
|
||||
|
||||
tmeth.call(1).assert == 3
|
||||
o.assert.respond_to?(:tryit)
|
||||
o.tryit(1).assert == 3
|
||||
end
|
||||
|
||||
test "with immutable object" do
|
||||
o = :foo
|
||||
tproc = proc{ self }
|
||||
|
||||
tmeth = tproc.to_method(o, :tryit)
|
||||
|
||||
tmeth.call.assert == :foo
|
||||
o.assert.respond_to?(:tryit)
|
||||
o.tryit.assert == :foo
|
||||
end
|
||||
|
||||
test "ensure method is in object scope" do
|
||||
o = Struct.new(:a).new(1)
|
||||
tproc = proc{ a }
|
||||
|
||||
tmeth = tproc.to_method(o, :tryit)
|
||||
|
||||
tmeth.call.assert == 1
|
||||
o.assert.respond_to?(:tryit)
|
||||
o.tryit.assert == 1
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
covers 'facets/proc/update'
|
||||
|
||||
test_case Proc do
|
||||
|
||||
method :update do
|
||||
|
||||
test do
|
||||
p1 = Proc.new{ 'here' }
|
||||
p1.update.assert == 'here'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user