fix references (again)

quite tricky logic, but now outputting at lowest level, as intended
This commit is contained in:
Torsten Ruger 2015-06-15 09:07:16 +03:00
parent 4853f944ef
commit 224bd84b01
4 changed files with 24 additions and 11 deletions

View File

@ -44,7 +44,8 @@ module Sof
occurence = @members.objects[object.object_id]
raise "no object #{object}" unless occurence
#puts "#{level} ? #{occurence.level} : ref #{occurence.referenced}"
if( occurence.referenced and (occurence.level <= level) )
if( occurence.referenced )
return SimpleNode.new("*#{occurence.referenced}") unless (level == occurence.level )
#puts "ref #{occurence.referenced} level #{level} at #{occurence.level}"
if( occurence.written.nil? )
occurence.written = true

View File

@ -23,3 +23,13 @@ module Checker
assert_equal should , out
end
end
class ObjectWithAttributes
def initialize
@name = "some name"
@number = 1234
end
attr_accessor :extra , :volotile
end
OBJECT_STRING = "ObjectWithAttributes(:name => 'some name', :number => 1234)"
Sof::Volotile.add(ObjectWithAttributes , [:volotile])

View File

@ -1,12 +1,4 @@
class ObjectWithAttributes
def initialize
@name = "some name"
@number = 1234
end
attr_accessor :extra , :volotile
end
OBJECT_STRING = "ObjectWithAttributes(:name => 'some name', :number => 1234)"
Sof::Volotile.add(ObjectWithAttributes , [:volotile])
require_relative "helper"
class ObjectSof < MiniTest::Test
include Checker
@ -63,6 +55,6 @@ class ObjectSof < MiniTest::Test
object.extra = ObjectWithAttributes
ar = [object , ObjectWithAttributes]
@out = ar
check "-ObjectWithAttributes(:name => 'some name', :number => 1234, :extra => &1 ObjectWithAttributes)\n-*1"
check "-ObjectWithAttributes(:name => 'some name', :number => 1234, :extra => *1)\n-&1 ObjectWithAttributes"
end
end

View File

@ -22,4 +22,14 @@ class TestRefs < MiniTest::Test
check "-&1 {}
-*1"
end
def test_bigger
@out = [ { :one => @array , :two => [{ :three => @array}] } ]
check "--:one => &1 []\n -:two => -{:three => *1}"
end
def test_object
object = ObjectWithAttributes.new
object.extra = [object]
@out = [ {:one => object} , object ]
check "-{:one => *1}\n-&1 ObjectWithAttributes(:name => 'some name', :number => 1234)\n :extra [*1]"
end
end