gf-treevisitor 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/treevisitor.rb +1 -1
- data/lib/treevisitor/abs_node.rb +7 -7
- data/lib/treevisitor/tree_node.rb +9 -7
- data/test/treevisitor/tc_tree_node.rb +16 -11
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.12
|
data/lib/treevisitor.rb
CHANGED
data/lib/treevisitor/abs_node.rb
CHANGED
@@ -49,7 +49,7 @@ class AbsNode
|
|
49
49
|
#
|
50
50
|
def invalidate
|
51
51
|
@path = nil
|
52
|
-
@
|
52
|
+
@path_with_prefix = nil
|
53
53
|
@depth = nil
|
54
54
|
end
|
55
55
|
|
@@ -81,21 +81,21 @@ class AbsNode
|
|
81
81
|
def path
|
82
82
|
return @path unless @path.nil?
|
83
83
|
if @parent.nil?
|
84
|
-
@path = @
|
84
|
+
@path = @name
|
85
85
|
else
|
86
86
|
@path = @parent.path + AbsNode::path_separator + @name
|
87
87
|
end
|
88
88
|
@path
|
89
89
|
end
|
90
90
|
|
91
|
-
def
|
92
|
-
return @
|
91
|
+
def path_with_prefix
|
92
|
+
return @path_with_prefix unless @path_with_prefix.nil?
|
93
93
|
if @parent.nil?
|
94
|
-
@
|
94
|
+
@path_with_prefix = @prefix_path.nil? ? @name : @prefix_path + @name
|
95
95
|
else
|
96
|
-
@
|
96
|
+
@path_with_prefix = @parent.path_with_prefix + AbsNode::path_separator + @name
|
97
97
|
end
|
98
|
-
@
|
98
|
+
@path_with_prefix
|
99
99
|
end
|
100
100
|
|
101
101
|
def depth
|
@@ -63,14 +63,16 @@ class TreeNode < AbsNode
|
|
63
63
|
@leaves << leaf
|
64
64
|
end
|
65
65
|
|
66
|
-
def add_child(
|
67
|
-
return if
|
68
|
-
if not
|
69
|
-
|
66
|
+
def add_child( tree_node )
|
67
|
+
return if tree_node.parent == self
|
68
|
+
if not tree_node.parent.nil?
|
69
|
+
tree_node.remove_from_parent()
|
70
|
+
else
|
71
|
+
tree_node.prefix_path = nil
|
70
72
|
end
|
71
|
-
|
72
|
-
|
73
|
-
@children <<
|
73
|
+
tree_node.invalidate
|
74
|
+
tree_node.parent = self
|
75
|
+
@children << tree_node
|
74
76
|
end
|
75
77
|
|
76
78
|
def find( name )
|
@@ -86,13 +86,18 @@ class TCTreeNode < Test::Unit::TestCase
|
|
86
86
|
tb = TreeNode.new( "b", ta )
|
87
87
|
ln3 = LeafNode.new( "3", tb )
|
88
88
|
|
89
|
-
assert_equal( "a", ta.path
|
89
|
+
assert_equal( "a", ta.path )
|
90
90
|
assert_equal( "a/b", tb.path )
|
91
|
+
assert_equal( "a", ta.path_with_prefix )
|
92
|
+
assert_equal( "a/b", tb.path_with_prefix )
|
91
93
|
|
92
94
|
ta.prefix_path= "<root>/"
|
93
|
-
|
94
|
-
assert_equal(
|
95
|
-
assert_equal( "
|
95
|
+
|
96
|
+
assert_equal("<root>/", ta.prefix_path )
|
97
|
+
assert_equal( "a", ta.path )
|
98
|
+
assert_equal( "a/b", tb.path )
|
99
|
+
assert_equal( "<root>/a", ta.path_with_prefix )
|
100
|
+
assert_equal( "<root>/a/b", tb.path_with_prefix )
|
96
101
|
end
|
97
102
|
|
98
103
|
def test_invalidate
|
@@ -101,20 +106,20 @@ class TCTreeNode < Test::Unit::TestCase
|
|
101
106
|
ln2 = LeafNode.new("2", ta)
|
102
107
|
tb = TreeNode.new( "b", ta )
|
103
108
|
ln3 = LeafNode.new( "3", tb )
|
104
|
-
|
105
|
-
#@path = nil
|
106
|
-
#@path_from_root = nil
|
107
|
-
#@depth = nil
|
108
109
|
|
109
|
-
|
110
|
+
ta.prefix_path="root/"
|
110
111
|
assert_equal( "a/b", tb.path )
|
111
|
-
assert_equal( "/b", tb.
|
112
|
+
assert_equal( "root/a/b", tb.path_with_prefix )
|
112
113
|
assert_equal( 2, tb.depth )
|
113
114
|
|
114
115
|
r = TreeNode.new( "r" )
|
115
116
|
r.add_child( ta )
|
116
117
|
assert_equal( "r/a/b", tb.path )
|
117
|
-
assert_equal( "/a/b", tb.
|
118
|
+
assert_equal( "r/a/b", tb.path_with_prefix )
|
119
|
+
|
120
|
+
r.prefix_path="new_root/"
|
121
|
+
assert_equal( "r/a/b", tb.path )
|
122
|
+
assert_equal( "new_root/r/a/b", tb.path_with_prefix )
|
118
123
|
assert_equal( 3, tb.depth )
|
119
124
|
end
|
120
125
|
|