2014-08-14 16:40:56 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
2014-08-14 18:49:20 +02:00
|
|
|
class ObjectWithAttributes
|
|
|
|
def initialize
|
|
|
|
@name = "some object"
|
|
|
|
@number = 1234
|
|
|
|
end
|
2014-08-14 16:40:56 +02:00
|
|
|
end
|
2014-08-15 14:13:36 +02:00
|
|
|
OBJECT_STRING = "ObjectWithAttributes(name: 'some object' ,number: 1234)"
|
2014-08-14 16:40:56 +02:00
|
|
|
|
|
|
|
class BasicSof < MiniTest::Test
|
|
|
|
def test_true
|
2014-08-14 18:24:18 +02:00
|
|
|
out = Sof::Writer.write(true)
|
|
|
|
assert_equal "true" , out
|
2014-08-14 16:40:56 +02:00
|
|
|
end
|
|
|
|
def test_num
|
2014-08-14 18:24:18 +02:00
|
|
|
out = Sof::Writer.write(124)
|
|
|
|
assert_equal "124" , out
|
2014-08-14 16:40:56 +02:00
|
|
|
end
|
2014-08-14 18:49:20 +02:00
|
|
|
def test_object
|
|
|
|
out = Sof::Writer.write(ObjectWithAttributes.new)
|
2014-08-15 14:13:36 +02:00
|
|
|
assert_equal "#{OBJECT_STRING}\n" , out
|
2014-08-14 19:24:26 +02:00
|
|
|
end
|
|
|
|
def test_simple_array
|
|
|
|
out = Sof::Writer.write([true, 1234])
|
2014-08-15 14:13:36 +02:00
|
|
|
assert_equal "-true\n-1234\n" , out
|
2014-08-14 18:49:20 +02:00
|
|
|
end
|
2014-08-15 14:08:45 +02:00
|
|
|
def test_array_object
|
2014-08-15 13:59:38 +02:00
|
|
|
out = Sof::Writer.write([true, 1234 , ObjectWithAttributes.new])
|
2014-08-15 14:13:36 +02:00
|
|
|
assert_equal "-true\n-1234\n-#{OBJECT_STRING}\n\n" , out
|
2014-08-15 13:59:38 +02:00
|
|
|
end
|
2014-08-15 14:08:45 +02:00
|
|
|
def test_array_array
|
|
|
|
out = Sof::Writer.write([true, 1 , [true , 12 ]])
|
2014-08-15 14:13:36 +02:00
|
|
|
assert_equal "-true\n-1\n--true\n -12\n\n" , out
|
2014-08-15 14:08:45 +02:00
|
|
|
end
|
|
|
|
def test_array_array_array
|
|
|
|
out = Sof::Writer.write([true, 1 , [true , 12 , [true , 123 ]]])
|
2014-08-15 14:13:36 +02:00
|
|
|
assert_equal "-true\n-1\n--true\n -12\n --true\n -123\n\n\n" , out
|
2014-08-15 14:08:45 +02:00
|
|
|
end
|
2014-08-15 14:13:36 +02:00
|
|
|
def test_array_array_object
|
2014-08-15 14:08:45 +02:00
|
|
|
out = Sof::Writer.write([true, 1 , [true , 12 , ObjectWithAttributes.new]])
|
2014-08-15 14:13:36 +02:00
|
|
|
assert_equal "-true\n-1\n--true\n -12\n -#{OBJECT_STRING}\n\n\n" , out
|
2014-08-15 14:04:13 +02:00
|
|
|
end
|
2014-08-15 16:14:49 +02:00
|
|
|
def test_simple_hash
|
|
|
|
out = Sof::Writer.write({ one: 1 , tru: true })
|
|
|
|
puts out
|
|
|
|
assert_equal "-:one 1\n-:tru true\n" , out
|
|
|
|
end
|
2014-08-14 16:40:56 +02:00
|
|
|
end
|