rubyx/test/sof.rb
2014-08-18 12:49:38 +03:00

78 lines
2.2 KiB
Ruby

require_relative "helper"
require "yaml"
class ObjectWithAttributes
def initialize
@name = "some name"
@number = 1234
end
def extra_array
@extra = [:sym , 123]
self
end
end
OBJECT_STRING = "ObjectWithAttributes(name: 'some name', number: 1234)"
class BasicSof < MiniTest::Test
def check should
same = (should == @out)
puts "Shouldda\n#{@out}" unless same
assert_equal should , @out
end
def test_true
@out = Sof::Writer.write(true)
check "true"
end
def test_num
@out = Sof::Writer.write(124)
check "124"
end
def test_simple_object
@out = Sof::Writer.write(ObjectWithAttributes.new)
check "#{OBJECT_STRING}"
end
def test_object_extra_array
@out = Sof::Writer.write(ObjectWithAttributes.new.extra_array)
check "#{OBJECT_STRING}\n :extra -:sym\n -123"
end
def test_simple_array
@out = Sof::Writer.write([true, 1234])
check "-true\n-1234"
end
def test_array_object
@out = Sof::Writer.write([true, 1234 , ObjectWithAttributes.new])
check "-true\n-1234\n-#{OBJECT_STRING}"
end
def test_array_array
@out = Sof::Writer.write([true, 1 , [true , 12 ]])
check "-true\n-1\n--true\n -12"
end
def test_array_array_reverse
@out = Sof::Writer.write([ [true , 12 ], true, 1])
check "--true\n -12\n-true\n-1"
end
def test_array_array_array
@out = Sof::Writer.write([true, 1 , [true , 12 , [true , 123 ]]])
check "-true\n-1\n--true\n -12\n --true\n -123"
end
def test_array_array_object
@out = Sof::Writer.write([true, 1 , [true , 12 , ObjectWithAttributes.new]])
check "-true\n-1\n--true\n -12\n -#{OBJECT_STRING}"
end
def test_simple_hash
@out = Sof::Writer.write({ one: 1 , tru: true })
check "-:one: 1\n-:tru: true"
end
def test_hash_object
@out = Sof::Writer.write({ one: 1 , two: ObjectWithAttributes.new })
check "-:one: 1\n-:two: #{OBJECT_STRING}"
end
def test_array_hash
@out = Sof::Writer.write([true, 1 , { one: 1 , tru: true }])
check "-true\n-1\n--:one: 1\n -:tru: true"
end
def test_hash_array
@out = Sof::Writer.write({ one: [1 , ObjectWithAttributes.new] , two: true })
check "-:one: -1\n -#{OBJECT_STRING}\n-:two: true"
end
end