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