refactoring on tests

This commit is contained in:
Torsten Ruger 2015-05-15 21:03:11 +03:00
parent b5d44bf2f3
commit 217eda2436
4 changed files with 25 additions and 24 deletions

View File

@ -17,8 +17,9 @@ require 'salama-object-file'
module Checker module Checker
def check should def check should
same = (should == @out) out = Sof::Writer.write(@out)
puts "Shouldda\n#{@out}" unless same same = (should == out)
assert_equal should , @out puts "Shouldda\n#{out}" unless same
assert_equal should , out
end end
end end

View File

@ -4,45 +4,45 @@ class BasicSof < MiniTest::Test
include Checker include Checker
def test_true def test_true
@out = Sof::Writer.write(true) @out = true
check "true" check "true"
end end
def test_string def test_string
@out = Sof::Writer.write("true") @out = "true"
check "'true'" check "'true'"
end end
def test_num def test_num
@out = Sof::Writer.write(124) @out = 124
check "124" check "124"
end end
def test_simple_array def test_simple_array
@out = Sof::Writer.write([true, 1234]) @out = [true, 1234]
check "[true, 1234]" check "[true, 1234]"
end end
def test_array_array def test_array_array
@out = Sof::Writer.write([true, 1 , [true , 12 ]]) @out = [true, 1 , [true , 12 ]]
check "-true\n-1\n-[true, 12]" check "-true\n-1\n-[true, 12]"
end end
def test_array_array_reverse def test_array_array_reverse
@out = Sof::Writer.write([ [true , 12 ], true, 1]) @out = [ [true , 12 ], true, 1]
check "-[true, 12]\n-true\n-1" check "-[true, 12]\n-true\n-1"
end end
def test_array_array_array def test_array_array_array
@out = Sof::Writer.write([true, 1 , [true , 12 , [true , 123 ]]]) @out = [true, 1 , [true , 12 , [true , 123 ]]]
check "-true\n-1\n--true\n -12\n -[true, 123]" check "-true\n-1\n--true\n -12\n -[true, 123]"
end end
def test_simple_hash def test_simple_hash
@out = Sof::Writer.write({ one: 1 , tru: true }) @out = { one: 1 , tru: true }
check "{:one => 1, :tru => true}" check "{:one => 1, :tru => true}"
end end
def test_array_hash def test_array_hash
@out = Sof::Writer.write([true, 1 , { one: 1 , tru: true }]) @out = [true, 1 , { one: 1 , tru: true }]
check "-true\n-1\n-{:one => 1, :tru => true}" check "-true\n-1\n-{:one => 1, :tru => true}"
end end
def test_array_recursive def test_array_recursive
ar = [true, 1 ] ar = [true, 1 ]
ar << ar ar << ar
@out = Sof::Writer.write(ar) @out = ar
check "&1 [true, 1, *1]" check "&1 [true, 1, *1]"
end end
end end

View File

@ -24,7 +24,7 @@ class ObjectSof < MiniTest::Test
end end
def test_basic def test_basic
@out = Sof::Writer.write(BasicValue.new("name")) @out = BasicValue.new("name")
check "'name'" check "'name'"
end end

View File

@ -11,52 +11,52 @@ class ObjectSof < MiniTest::Test
include Checker include Checker
def test_simple_object def test_simple_object
@out = Sof::Writer.write(ObjectWithAttributes.new) @out = ObjectWithAttributes.new
check "#{OBJECT_STRING}" check "#{OBJECT_STRING}"
end end
def test_object_extra_array def test_object_extra_array
object = ObjectWithAttributes.new object = ObjectWithAttributes.new
object.extra = [:sym , 123] object.extra = [:sym , 123]
@out = Sof::Writer.write(object) @out = object
check "#{OBJECT_STRING}\n :extra [:sym, 123]" check "#{OBJECT_STRING}\n :extra [:sym, 123]"
end end
def test_array_object def test_array_object
@out = Sof::Writer.write([true, 1234 , ObjectWithAttributes.new]) @out = [true, 1234 , ObjectWithAttributes.new]
check "-true\n-1234\n-#{OBJECT_STRING}" check "-true\n-1234\n-#{OBJECT_STRING}"
end end
def test_array_array_object def test_array_array_object
@out = Sof::Writer.write([true, 1 , [true , 12 , ObjectWithAttributes.new]]) @out = [true, 1 , [true , 12 , ObjectWithAttributes.new]]
check "-true\n-1\n--true\n -12\n -#{OBJECT_STRING}" check "-true\n-1\n--true\n -12\n -#{OBJECT_STRING}"
end end
def test_hash_object def test_hash_object
@out = Sof::Writer.write({ one: 1 , two: ObjectWithAttributes.new }) @out = { one: 1 , two: ObjectWithAttributes.new }
check "-:one => 1\n-:two => #{OBJECT_STRING}" check "-:one => 1\n-:two => #{OBJECT_STRING}"
end end
def test_hash_array def test_hash_array
@out = Sof::Writer.write({ one: [1 , ObjectWithAttributes.new] , two: true }) @out = { one: [1 , ObjectWithAttributes.new] , two: true }
check "-:one => -1\n -#{OBJECT_STRING}\n-:two => true" check "-:one => -1\n -#{OBJECT_STRING}\n-:two => true"
end end
def test_object_recursive def test_object_recursive
object = ObjectWithAttributes.new object = ObjectWithAttributes.new
object.extra = object object.extra = object
@out = Sof::Writer.write(object) @out = object
check "&1 ObjectWithAttributes(:name => 'some name', :number => 1234, :extra => *1)" check "&1 ObjectWithAttributes(:name => 'some name', :number => 1234, :extra => *1)"
end end
def test_object_inline def test_object_inline
object = ObjectWithAttributes.new object = ObjectWithAttributes.new
object.extra = Object.new object.extra = Object.new
@out = Sof::Writer.write(object) @out = object
check "ObjectWithAttributes(:name => 'some name', :number => 1234, :extra => Object())" check "ObjectWithAttributes(:name => 'some name', :number => 1234, :extra => Object())"
end end
def test_class def test_class
@out = Sof::Writer.write(ObjectWithAttributes) @out = ObjectWithAttributes
check "ObjectWithAttributes" check "ObjectWithAttributes"
end end
def test_class_ref def test_class_ref
object = ObjectWithAttributes.new object = ObjectWithAttributes.new
object.extra = ObjectWithAttributes object.extra = ObjectWithAttributes
ar = [object , ObjectWithAttributes] ar = [object , ObjectWithAttributes]
@out = Sof::Writer.write(ar) @out = ar
check "-ObjectWithAttributes(:name => 'some name', :number => 1234, :extra => *1)\n-&1 ObjectWithAttributes" check "-ObjectWithAttributes(:name => 'some name', :number => 1234, :extra => *1)\n-&1 ObjectWithAttributes"
end end
end end