2014-08-14 16:40:56 +02:00
|
|
|
require_relative "helper"
|
2014-08-15 17:27:32 +02:00
|
|
|
require "yaml"
|
2014-08-14 16:40:56 +02:00
|
|
|
|
2014-08-14 18:49:20 +02:00
|
|
|
class ObjectWithAttributes
|
|
|
|
def initialize
|
2014-08-16 08:56:11 +02:00
|
|
|
@name = "some name"
|
2014-08-14 18:49:20 +02:00
|
|
|
@number = 1234
|
|
|
|
end
|
2014-08-17 20:44:34 +02:00
|
|
|
def extra_array
|
|
|
|
@extra = [:sym , 123]
|
|
|
|
self
|
|
|
|
end
|
2014-08-14 16:40:56 +02:00
|
|
|
end
|
2014-08-16 08:56:11 +02:00
|
|
|
OBJECT_STRING = "ObjectWithAttributes(name: 'some name', number: 1234)"
|
2014-08-14 16:40:56 +02:00
|
|
|
|
|
|
|
class BasicSof < MiniTest::Test
|
2014-08-18 07:19:48 +02:00
|
|
|
def check should
|
|
|
|
same = (should == @out)
|
|
|
|
puts "Shouldda\n#{@out}" unless same
|
|
|
|
assert_equal should , @out
|
|
|
|
end
|
2014-08-14 16:40:56 +02:00
|
|
|
def test_true
|
2014-08-18 07:19:48 +02:00
|
|
|
@out = Sof::Writer.write(true)
|
|
|
|
check "true"
|
2014-08-14 16:40:56 +02:00
|
|
|
end
|
|
|
|
def test_num
|
2014-08-18 07:19:48 +02:00
|
|
|
@out = Sof::Writer.write(124)
|
|
|
|
check "124"
|
2014-08-14 16:40:56 +02:00
|
|
|
end
|
2014-08-18 07:19:48 +02:00
|
|
|
def test_simple_object
|
|
|
|
@out = Sof::Writer.write(ObjectWithAttributes.new)
|
|
|
|
check "#{OBJECT_STRING}"
|
2014-08-14 19:24:26 +02:00
|
|
|
end
|
2014-08-17 20:44:34 +02:00
|
|
|
def test_object_extra_array
|
2014-08-18 07:19:48 +02:00
|
|
|
@out = Sof::Writer.write(ObjectWithAttributes.new.extra_array)
|
2014-08-18 11:49:38 +02:00
|
|
|
check "#{OBJECT_STRING}\n :extra -:sym\n -123"
|
2014-08-17 20:44:34 +02:00
|
|
|
end
|
2014-08-14 19:24:26 +02:00
|
|
|
def test_simple_array
|
2014-08-18 07:19:48 +02:00
|
|
|
@out = Sof::Writer.write([true, 1234])
|
|
|
|
check "-true\n-1234"
|
2014-08-14 18:49:20 +02:00
|
|
|
end
|
2014-08-15 14:08:45 +02:00
|
|
|
def test_array_object
|
2014-08-18 07:19:48 +02:00
|
|
|
@out = Sof::Writer.write([true, 1234 , ObjectWithAttributes.new])
|
|
|
|
check "-true\n-1234\n-#{OBJECT_STRING}"
|
2014-08-15 13:59:38 +02:00
|
|
|
end
|
2014-08-15 14:08:45 +02:00
|
|
|
def test_array_array
|
2014-08-18 07:19:48 +02:00
|
|
|
@out = Sof::Writer.write([true, 1 , [true , 12 ]])
|
|
|
|
check "-true\n-1\n--true\n -12"
|
2014-08-16 10:43:41 +02:00
|
|
|
end
|
|
|
|
def test_array_array_reverse
|
2014-08-18 07:19:48 +02:00
|
|
|
@out = Sof::Writer.write([ [true , 12 ], true, 1])
|
|
|
|
check "--true\n -12\n-true\n-1"
|
2014-08-15 14:08:45 +02:00
|
|
|
end
|
|
|
|
def test_array_array_array
|
2014-08-18 07:19:48 +02:00
|
|
|
@out = Sof::Writer.write([true, 1 , [true , 12 , [true , 123 ]]])
|
|
|
|
check "-true\n-1\n--true\n -12\n --true\n -123"
|
2014-08-15 14:08:45 +02:00
|
|
|
end
|
2014-08-16 11:34:25 +02:00
|
|
|
def test_array_array_object
|
2014-08-18 07:19:48 +02: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 14:04:13 +02:00
|
|
|
end
|
2014-08-16 14:16:07 +02:00
|
|
|
def test_simple_hash
|
2014-08-18 07:19:48 +02:00
|
|
|
@out = Sof::Writer.write({ one: 1 , tru: true })
|
|
|
|
check "-:one: 1\n-:tru: true"
|
2014-08-15 16:14:49 +02:00
|
|
|
end
|
2014-08-16 14:16:07 +02:00
|
|
|
def test_hash_object
|
2014-08-18 07:19:48 +02:00
|
|
|
@out = Sof::Writer.write({ one: 1 , two: ObjectWithAttributes.new })
|
|
|
|
check "-:one: 1\n-:two: #{OBJECT_STRING}"
|
2014-08-15 17:27:32 +02:00
|
|
|
end
|
2014-08-17 20:44:34 +02:00
|
|
|
def test_array_hash
|
2014-08-18 07:19:48 +02:00
|
|
|
@out = Sof::Writer.write([true, 1 , { one: 1 , tru: true }])
|
|
|
|
check "-true\n-1\n--:one: 1\n -:tru: true"
|
2014-08-17 20:44:34 +02:00
|
|
|
end
|
2014-08-16 14:16:07 +02:00
|
|
|
def test_hash_array
|
2014-08-18 07:19:48 +02:00
|
|
|
@out = Sof::Writer.write({ one: [1 , ObjectWithAttributes.new] , two: true })
|
|
|
|
check "-:one: -1\n -#{OBJECT_STRING}\n-:two: true"
|
2014-08-15 16:18:15 +02:00
|
|
|
end
|
2014-08-14 16:40:56 +02:00
|
|
|
end
|