fixing arrays/hashs and starting complex objects

This commit is contained in:
Torsten Ruger
2014-08-17 21:44:34 +03:00
parent 9669831f78
commit b0472753f4
5 changed files with 22 additions and 9 deletions

View File

@ -6,6 +6,10 @@ class ObjectWithAttributes
@name = "some name"
@number = 1234
end
def extra_array
@extra = [:sym , 123]
self
end
end
OBJECT_STRING = "ObjectWithAttributes(name: 'some name', number: 1234)"
@ -22,6 +26,10 @@ class BasicSof < MiniTest::Test
out = Sof::Writer.write(ObjectWithAttributes.new)
assert_equal "#{OBJECT_STRING}" , out
end
def test_object_extra_array
out = Sof::Writer.write(ObjectWithAttributes.new.extra_array)
assert_equal "#{OBJECT_STRING}" , out
end
def test_simple_array
out = Sof::Writer.write([true, 1234])
assert_equal "-true\n-1234" , out
@ -54,6 +62,10 @@ class BasicSof < MiniTest::Test
out = Sof::Writer.write({ one: 1 , two: ObjectWithAttributes.new })
assert_equal "-:one: 1\n-:two: #{OBJECT_STRING}" , out
end
def test_array_hash
out = Sof::Writer.write([true, 1 , { one: 1 , tru: true }])
assert_equal "-true\n-1\n--:one: 1\n -:tru: true" , out
end
def test_hash_array
out = Sof::Writer.write({ one: [1 , ObjectWithAttributes.new] , two: true })
assert_equal "-:one: -1\n -#{OBJECT_STRING}\n-:two: true" , out