rubyx/test/sof.rb

65 lines
2.0 KiB
Ruby
Raw Normal View History

require_relative "helper"
2014-08-15 17:27:32 +02:00
require "yaml"
class ObjectWithAttributes
def initialize
2014-08-16 08:56:11 +02:00
@name = "some name"
@number = 1234
end
end
2014-08-16 08:56:11 +02:00
OBJECT_STRING = "ObjectWithAttributes(name: 'some name', number: 1234)"
class BasicSof < MiniTest::Test
def test_true
out = Sof::Writer.write(true)
assert_equal "true" , out
end
def test_num
out = Sof::Writer.write(124)
assert_equal "124" , out
end
def test_object
out = Sof::Writer.write(ObjectWithAttributes.new)
2014-08-15 17:27:32 +02:00
assert_equal "#{OBJECT_STRING}" , out
2014-08-14 19:24:26 +02:00
end
def test_simple_array
out = Sof::Writer.write([true, 1234])
assert_equal "-true\n-1234" , out
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])
assert_equal "-true\n-1234\n-#{OBJECT_STRING}" , 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 ]])
assert_equal "-true\n-1\n--true\n -12" , out
end
def test_array_array_reverse
out = Sof::Writer.write([ [true , 12 ], true, 1])
assert_equal "--true\n -12\n-true\n-1" , 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 ]]])
assert_equal "-true\n-1\n--true\n -12\n --true\n -123" , out
2014-08-15 14:08:45 +02:00
end
2014-08-16 11:34:25 +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-16 11:34:25 +02:00
assert_equal "-true\n-1\n--true\n -12\n -#{OBJECT_STRING}" , out
2014-08-15 14:04:13 +02:00
end
def ttest_simple_hash
2014-08-15 16:14:49 +02:00
out = Sof::Writer.write({ one: 1 , tru: true })
2014-08-16 11:34:25 +02:00
puts out
2014-08-15 16:14:49 +02:00
assert_equal "-:one 1\n-:tru true\n" , out
end
def ttest_hash_object
2014-08-15 16:18:15 +02:00
out = Sof::Writer.write({ one: 1 , two: ObjectWithAttributes.new })
2014-08-15 17:27:32 +02:00
assert_equal "-:one 1\n-:two #{OBJECT_STRING}\n" , out
end
def ttest_hash_array
2014-08-15 17:27:32 +02:00
out = Sof::Writer.write({ one: [1 , ObjectWithAttributes.new] , two: true })
puts "\n#{out}"
s = { :one => [1 , ObjectWithAttributes.new] , :two => true }.to_yaml
puts s
2014-08-15 16:18:15 +02:00
assert_equal "-:one 1\n-:two #{OBJECT_STRING}\n\n" , out
end
end