[Core] fix format_helper assuming p returns nil
on ruby 1.9 it returns the printed string so x = foo || p("foo was false") always evaluates to something truthy
This commit is contained in:
parent
66038db5cb
commit
519efbf179
|
@ -48,7 +48,8 @@ module Shindo
|
||||||
format.delete(key)
|
format.delete(key)
|
||||||
case value
|
case value
|
||||||
when Array
|
when Array
|
||||||
valid &&= datum.is_a?(Array) || p("#{key.inspect} not Array: #{datum.inspect}")
|
p("#{key.inspect} not Array: #{datum.inspect}") unless datum.is_a?(Array)
|
||||||
|
valid &&= datum.is_a?(Array)
|
||||||
if datum.is_a?(Array) && !value.empty?
|
if datum.is_a?(Array) && !value.empty?
|
||||||
for element in datum
|
for element in datum
|
||||||
type = value.first
|
type = value.first
|
||||||
|
@ -60,7 +61,8 @@ module Shindo
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
when Hash
|
when Hash
|
||||||
valid &&= datum.is_a?(Hash) || p("#{key.inspect} not Hash: #{datum.inspect}")
|
p("#{key.inspect} not Hash: #{datum.inspect}") unless datum.is_a?(Hash)
|
||||||
|
valid &&= datum.is_a?(Hash)
|
||||||
valid &&= formats_kernel(datum, value, false, strict)
|
valid &&= formats_kernel(datum, value, false, strict)
|
||||||
else
|
else
|
||||||
p "#{key.inspect} not #{value.inspect}: #{datum.inspect}" unless datum.is_a?(value)
|
p "#{key.inspect} not #{value.inspect}: #{datum.inspect}" unless datum.is_a?(value)
|
||||||
|
|
|
@ -40,6 +40,15 @@ Shindo.tests('test_helper', 'meta') do
|
||||||
!formats_kernel({}, {:a => String})
|
!formats_kernel({}, {:a => String})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test('when an array is expected but another data type is found') do
|
||||||
|
!formats_kernel({:a => 'not an array'}, {:a => []})
|
||||||
|
end
|
||||||
|
|
||||||
|
test('when a hash is expected but another data type is found') do
|
||||||
|
!formats_kernel({:a => 'not a hash'}, {:a => {}}, true, false)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
test('non strict extra data') do
|
test('non strict extra data') do
|
||||||
!formats_kernel({:a => :b, :b => :c}, {:z => Symbol}, true, false)
|
!formats_kernel({:a => :b, :b => :c}, {:z => Symbol}, true, false)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue