short version for array
This commit is contained in:
parent
1dee9a4bd1
commit
a874bd49d2
@ -10,10 +10,26 @@ module Sof
|
|||||||
end
|
end
|
||||||
def out io , level = 0
|
def out io , level = 0
|
||||||
super
|
super
|
||||||
|
short = true
|
||||||
|
children.each do |c|
|
||||||
|
short = false unless c.is_a?(SimpleNode)
|
||||||
|
end
|
||||||
|
if(short and children.length < 7 )
|
||||||
|
short_out(io,level)
|
||||||
|
else
|
||||||
long_out(io , level)
|
long_out(io , level)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
def short_out(io,level)
|
||||||
|
io.write("[")
|
||||||
|
@children.each_with_index do |child , i|
|
||||||
|
child.out(io , level + 1)
|
||||||
|
io.write ", " unless (i+1) == children.length
|
||||||
|
end
|
||||||
|
io.write("]")
|
||||||
|
end
|
||||||
def long_out io , level
|
def long_out io , level
|
||||||
indent = " " * level
|
indent = " " * level
|
||||||
@children.each_with_index do |child , i|
|
@children.each_with_index do |child , i|
|
||||||
|
12
test/sof.rb
12
test/sof.rb
@ -32,11 +32,11 @@ class BasicSof < MiniTest::Test
|
|||||||
object = ObjectWithAttributes.new
|
object = ObjectWithAttributes.new
|
||||||
object.extra = [:sym , 123]
|
object.extra = [:sym , 123]
|
||||||
@out = Sof::Writer.write(object)
|
@out = Sof::Writer.write(object)
|
||||||
check "#{OBJECT_STRING}\n :extra -:sym\n -123"
|
check "#{OBJECT_STRING}\n :extra [:sym, 123]"
|
||||||
end
|
end
|
||||||
def test_simple_array
|
def test_simple_array
|
||||||
@out = Sof::Writer.write([true, 1234])
|
@out = Sof::Writer.write([true, 1234])
|
||||||
check "-true\n-1234"
|
check "[true, 1234]"
|
||||||
end
|
end
|
||||||
def test_array_object
|
def test_array_object
|
||||||
@out = Sof::Writer.write([true, 1234 , ObjectWithAttributes.new])
|
@out = Sof::Writer.write([true, 1234 , ObjectWithAttributes.new])
|
||||||
@ -44,15 +44,15 @@ class BasicSof < MiniTest::Test
|
|||||||
end
|
end
|
||||||
def test_array_array
|
def test_array_array
|
||||||
@out = Sof::Writer.write([true, 1 , [true , 12 ]])
|
@out = Sof::Writer.write([true, 1 , [true , 12 ]])
|
||||||
check "-true\n-1\n--true\n -12"
|
check "-true\n-1\n-[true, 12]"
|
||||||
end
|
end
|
||||||
def test_array_array_reverse
|
def test_array_array_reverse
|
||||||
@out = Sof::Writer.write([ [true , 12 ], true, 1])
|
@out = Sof::Writer.write([ [true , 12 ], true, 1])
|
||||||
check "--true\n -12\n-true\n-1"
|
check "-[true, 12]\n-true\n-1"
|
||||||
end
|
end
|
||||||
def test_array_array_array
|
def test_array_array_array
|
||||||
@out = Sof::Writer.write([true, 1 , [true , 12 , [true , 123 ]]])
|
@out = Sof::Writer.write([true, 1 , [true , 12 , [true , 123 ]]])
|
||||||
check "-true\n-1\n--true\n -12\n --true\n -123"
|
check "-true\n-1\n--true\n -12\n -[true, 123]"
|
||||||
end
|
end
|
||||||
def test_array_array_object
|
def test_array_array_object
|
||||||
@out = Sof::Writer.write([true, 1 , [true , 12 , ObjectWithAttributes.new]])
|
@out = Sof::Writer.write([true, 1 , [true , 12 , ObjectWithAttributes.new]])
|
||||||
@ -78,7 +78,7 @@ class BasicSof < MiniTest::Test
|
|||||||
ar = [true, 1 ]
|
ar = [true, 1 ]
|
||||||
ar << ar
|
ar << ar
|
||||||
@out = Sof::Writer.write(ar)
|
@out = Sof::Writer.write(ar)
|
||||||
check "&1 -true\n-1\n-*1"
|
check "&1 [true, 1, *1]"
|
||||||
end
|
end
|
||||||
def test_object_recursive
|
def test_object_recursive
|
||||||
object = ObjectWithAttributes.new
|
object = ObjectWithAttributes.new
|
||||||
|
Loading…
Reference in New Issue
Block a user