fix all existing (hash) tests
This commit is contained in:
parent
90e4837b2e
commit
9669831f78
@ -1,9 +1,12 @@
|
||||
Hash.class_eval do
|
||||
def to_sof_node(members , level)
|
||||
node = Sof::NodeList.new(nil)
|
||||
node = Sof::NodeList.new()
|
||||
each do |key , object|
|
||||
k = key.to_sof() + ": "
|
||||
v = members.to_sof_node( object )
|
||||
v.data = "#{k}#{v.data}"
|
||||
node.add v
|
||||
end
|
||||
node
|
||||
end
|
||||
end
|
||||
|
@ -10,17 +10,18 @@ module Sof
|
||||
end
|
||||
|
||||
class SimpleNode < Node
|
||||
def initialize head
|
||||
@head = head
|
||||
def initialize data
|
||||
@data = data
|
||||
end
|
||||
attr_accessor :head
|
||||
attr_accessor :data
|
||||
def out io , level
|
||||
io.write(head) if head
|
||||
io.write(data) if data
|
||||
end
|
||||
end
|
||||
|
||||
class NodeList < Node
|
||||
class NodeList < SimpleNode
|
||||
def initialize
|
||||
super(nil)
|
||||
@children = []
|
||||
end
|
||||
attr_accessor :children
|
||||
@ -31,6 +32,7 @@ module Sof
|
||||
end
|
||||
|
||||
def out io , level = 0
|
||||
super
|
||||
return if @children.empty?
|
||||
first = @children.first
|
||||
io.write "-"
|
||||
|
16
test/sof.rb
16
test/sof.rb
@ -46,20 +46,16 @@ class BasicSof < MiniTest::Test
|
||||
out = Sof::Writer.write([true, 1 , [true , 12 , ObjectWithAttributes.new]])
|
||||
assert_equal "-true\n-1\n--true\n -12\n -#{OBJECT_STRING}" , out
|
||||
end
|
||||
def ttest_simple_hash
|
||||
def test_simple_hash
|
||||
out = Sof::Writer.write({ one: 1 , tru: true })
|
||||
puts out
|
||||
assert_equal "-:one 1\n-:tru true\n" , out
|
||||
assert_equal "-:one: 1\n-:tru: true" , out
|
||||
end
|
||||
def ttest_hash_object
|
||||
def test_hash_object
|
||||
out = Sof::Writer.write({ one: 1 , two: ObjectWithAttributes.new })
|
||||
assert_equal "-:one 1\n-:two #{OBJECT_STRING}\n" , out
|
||||
assert_equal "-:one: 1\n-:two: #{OBJECT_STRING}" , out
|
||||
end
|
||||
def ttest_hash_array
|
||||
def test_hash_array
|
||||
out = Sof::Writer.write({ one: [1 , ObjectWithAttributes.new] , two: true })
|
||||
puts "\n#{out}"
|
||||
s = { :one => [1 , ObjectWithAttributes.new] , :two => true }.to_yaml
|
||||
puts s
|
||||
assert_equal "-:one 1\n-:two #{OBJECT_STRING}\n\n" , out
|
||||
assert_equal "-:one: -1\n -#{OBJECT_STRING}\n-:two: true" , out
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user