2014-08-14 17:40:56 +03:00
|
|
|
require_relative "helper"
|
2014-08-15 18:27:32 +03:00
|
|
|
require "yaml"
|
2014-08-14 17:40:56 +03:00
|
|
|
|
2014-08-14 19:49:20 +03:00
|
|
|
class ObjectWithAttributes
|
|
|
|
def initialize
|
2014-08-16 09:56:11 +03:00
|
|
|
@name = "some name"
|
2014-08-14 19:49:20 +03:00
|
|
|
@number = 1234
|
|
|
|
end
|
2014-08-18 13:33:40 +03:00
|
|
|
attr_accessor :extra
|
2014-08-14 17:40:56 +03:00
|
|
|
end
|
2014-08-18 17:16:18 +03:00
|
|
|
OBJECT_STRING = "ObjectWithAttributes(:name => 'some name', :number => 1234)"
|
2014-08-14 17:40:56 +03:00
|
|
|
|
|
|
|
class BasicSof < MiniTest::Test
|
2014-08-18 08:19:48 +03:00
|
|
|
def check should
|
|
|
|
same = (should == @out)
|
|
|
|
puts "Shouldda\n#{@out}" unless same
|
|
|
|
assert_equal should , @out
|
|
|
|
end
|
2014-08-14 17:40:56 +03:00
|
|
|
def test_true
|
2014-08-18 08:19:48 +03:00
|
|
|
@out = Sof::Writer.write(true)
|
|
|
|
check "true"
|
2014-08-14 17:40:56 +03:00
|
|
|
end
|
|
|
|
def test_num
|
2014-08-18 08:19:48 +03:00
|
|
|
@out = Sof::Writer.write(124)
|
|
|
|
check "124"
|
2014-08-14 17:40:56 +03:00
|
|
|
end
|
2014-08-18 08:19:48 +03:00
|
|
|
def test_simple_object
|
|
|
|
@out = Sof::Writer.write(ObjectWithAttributes.new)
|
|
|
|
check "#{OBJECT_STRING}"
|
2014-08-14 20:24:26 +03:00
|
|
|
end
|
2014-08-17 21:44:34 +03:00
|
|
|
def test_object_extra_array
|
2014-08-18 13:33:40 +03:00
|
|
|
object = ObjectWithAttributes.new
|
|
|
|
object.extra = [:sym , 123]
|
|
|
|
@out = Sof::Writer.write(object)
|
2014-08-18 14:28:28 +03:00
|
|
|
check "#{OBJECT_STRING}\n :extra [:sym, 123]"
|
2014-08-17 21:44:34 +03:00
|
|
|
end
|
2014-08-14 20:24:26 +03:00
|
|
|
def test_simple_array
|
2014-08-18 08:19:48 +03:00
|
|
|
@out = Sof::Writer.write([true, 1234])
|
2014-08-18 14:28:28 +03:00
|
|
|
check "[true, 1234]"
|
2014-08-14 19:49:20 +03:00
|
|
|
end
|
2014-08-15 15:08:45 +03:00
|
|
|
def test_array_object
|
2014-08-18 08:19:48 +03:00
|
|
|
@out = Sof::Writer.write([true, 1234 , ObjectWithAttributes.new])
|
|
|
|
check "-true\n-1234\n-#{OBJECT_STRING}"
|
2014-08-15 14:59:38 +03:00
|
|
|
end
|
2014-08-15 15:08:45 +03:00
|
|
|
def test_array_array
|
2014-08-18 08:19:48 +03:00
|
|
|
@out = Sof::Writer.write([true, 1 , [true , 12 ]])
|
2014-08-18 14:28:28 +03:00
|
|
|
check "-true\n-1\n-[true, 12]"
|
2014-08-16 11:43:41 +03:00
|
|
|
end
|
|
|
|
def test_array_array_reverse
|
2014-08-18 08:19:48 +03:00
|
|
|
@out = Sof::Writer.write([ [true , 12 ], true, 1])
|
2014-08-18 14:28:28 +03:00
|
|
|
check "-[true, 12]\n-true\n-1"
|
2014-08-15 15:08:45 +03:00
|
|
|
end
|
|
|
|
def test_array_array_array
|
2014-08-18 08:19:48 +03:00
|
|
|
@out = Sof::Writer.write([true, 1 , [true , 12 , [true , 123 ]]])
|
2014-08-18 14:28:28 +03:00
|
|
|
check "-true\n-1\n--true\n -12\n -[true, 123]"
|
2014-08-15 15:08:45 +03:00
|
|
|
end
|
2014-08-16 12:34:25 +03:00
|
|
|
def test_array_array_object
|
2014-08-18 08:19:48 +03:00
|
|
|
@out = Sof::Writer.write([true, 1 , [true , 12 , ObjectWithAttributes.new]])
|
|
|
|
check "-true\n-1\n--true\n -12\n -#{OBJECT_STRING}"
|
2014-08-15 15:04:13 +03:00
|
|
|
end
|
2014-08-16 15:16:07 +03:00
|
|
|
def test_simple_hash
|
2014-08-18 08:19:48 +03:00
|
|
|
@out = Sof::Writer.write({ one: 1 , tru: true })
|
2014-08-27 14:46:34 +03:00
|
|
|
check "{:one => 1, :tru => true}"
|
2014-08-15 17:14:49 +03:00
|
|
|
end
|
2014-08-16 15:16:07 +03:00
|
|
|
def test_hash_object
|
2014-08-18 08:19:48 +03:00
|
|
|
@out = Sof::Writer.write({ one: 1 , two: ObjectWithAttributes.new })
|
2014-08-18 17:19:34 +03:00
|
|
|
check "-:one => 1\n-:two => #{OBJECT_STRING}"
|
2014-08-15 18:27:32 +03:00
|
|
|
end
|
2014-08-17 21:44:34 +03:00
|
|
|
def test_array_hash
|
2014-08-18 08:19:48 +03:00
|
|
|
@out = Sof::Writer.write([true, 1 , { one: 1 , tru: true }])
|
2014-08-27 14:46:34 +03:00
|
|
|
check "-true\n-1\n-{:one => 1, :tru => true}"
|
2014-08-17 21:44:34 +03:00
|
|
|
end
|
2014-08-16 15:16:07 +03:00
|
|
|
def test_hash_array
|
2014-08-18 08:19:48 +03:00
|
|
|
@out = Sof::Writer.write({ one: [1 , ObjectWithAttributes.new] , two: true })
|
2014-08-18 17:19:34 +03:00
|
|
|
check "-:one => -1\n -#{OBJECT_STRING}\n-:two => true"
|
2014-08-15 17:18:15 +03:00
|
|
|
end
|
2014-08-18 13:22:03 +03:00
|
|
|
def test_array_recursive
|
|
|
|
ar = [true, 1 ]
|
|
|
|
ar << ar
|
|
|
|
@out = Sof::Writer.write(ar)
|
2014-08-18 14:28:28 +03:00
|
|
|
check "&1 [true, 1, *1]"
|
2014-08-18 13:22:03 +03:00
|
|
|
end
|
2014-08-18 13:33:40 +03:00
|
|
|
def test_object_recursive
|
2014-08-18 13:37:35 +03:00
|
|
|
object = ObjectWithAttributes.new
|
|
|
|
object.extra = object
|
|
|
|
@out = Sof::Writer.write(object)
|
2014-08-18 17:16:18 +03:00
|
|
|
check "&1 ObjectWithAttributes(:name => 'some name', :number => 1234, :extra => *1)"
|
2014-08-18 13:33:40 +03:00
|
|
|
end
|
2014-08-19 23:23:03 +03:00
|
|
|
def test_object_inline
|
|
|
|
object = ObjectWithAttributes.new
|
|
|
|
object.extra = Object.new
|
|
|
|
@out = Sof::Writer.write(object)
|
|
|
|
check "ObjectWithAttributes(:name => 'some name', :number => 1234, :extra => Object())"
|
|
|
|
end
|
2014-08-19 23:01:19 +03:00
|
|
|
def test_class
|
|
|
|
@out = Sof::Writer.write(ObjectWithAttributes)
|
|
|
|
check "ObjectWithAttributes"
|
|
|
|
end
|
2014-08-21 15:40:13 +03:00
|
|
|
def test_class_ref
|
|
|
|
object = ObjectWithAttributes.new
|
|
|
|
object.extra = ObjectWithAttributes
|
|
|
|
ar = [object , ObjectWithAttributes]
|
|
|
|
@out = Sof::Writer.write(ar)
|
|
|
|
check "-ObjectWithAttributes(:name => 'some name', :number => 1234, :extra => *1)\n-&1 ObjectWithAttributes"
|
|
|
|
end
|
2014-08-14 17:40:56 +03:00
|
|
|
end
|