treevisitor 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/README.md +6 -1
  2. data/Rakefile +6 -11
  3. data/lib/tree_visitor.rb +1 -1
  4. data/lib/treevisitor.rb +1 -38
  5. data/lib/treevisitor_cli.rb +2 -4
  6. data/treevisitor.gemspec +16 -28
  7. metadata +11 -143
  8. data/.gemtest +0 -0
  9. data/bin/tree.rb +0 -9
  10. data/examples/directory_walker/directory_without_subdirectory.rb +0 -37
  11. data/examples/directory_walker/find_files.rb +0 -18
  12. data/examples/directory_walker/print_files.rb +0 -12
  13. data/examples/protovis/directory_to_json_visitor.rb +0 -15
  14. data/examples/protovis/index.html +0 -87
  15. data/examples/protovis/protovis-r3.2.js +0 -277
  16. data/examples/protovis/treevisitor.js +0 -33
  17. data/examples/protovis/treevisitor.png +0 -0
  18. data/lib/treevisitor/abs_node.rb +0 -144
  19. data/lib/treevisitor/basic_tree_node_visitor.rb +0 -44
  20. data/lib/treevisitor/cli/cli_tree.rb +0 -106
  21. data/lib/treevisitor/directory_walker.rb +0 -300
  22. data/lib/treevisitor/leaf_node.rb +0 -33
  23. data/lib/treevisitor/tree_node.rb +0 -251
  24. data/lib/treevisitor/tree_node_visitor.rb +0 -119
  25. data/lib/treevisitor/util/dir_processor.rb +0 -46
  26. data/lib/treevisitor/version.rb +0 -4
  27. data/lib/treevisitor/visitors/block_tree_node_visitor.rb +0 -21
  28. data/lib/treevisitor/visitors/build_dir_tree_visitor.rb +0 -57
  29. data/lib/treevisitor/visitors/callback_tree_node_visitor2.rb +0 -48
  30. data/lib/treevisitor/visitors/clone_tree_node_visitor.rb +0 -39
  31. data/lib/treevisitor/visitors/depth_tree_node_visitor.rb +0 -27
  32. data/lib/treevisitor/visitors/directory_to_hash_visitor.rb +0 -33
  33. data/lib/treevisitor/visitors/flat_print_tree_node_visitors.rb +0 -20
  34. data/lib/treevisitor/visitors/print_dir_tree_visitor.rb +0 -21
  35. data/lib/treevisitor/visitors/print_tree_node_visitor.rb +0 -40
  36. data/spec/fixtures/test_dir_1/.dir_with_dot/dummy.txt +0 -0
  37. data/spec/fixtures/test_dir_1/dir.1/dir.1.2/file.1.2.1 +0 -0
  38. data/spec/fixtures/test_dir_1/dir.1/file.1.1 +0 -0
  39. data/spec/fixtures/test_dir_1/dir.2/file.2.1 +0 -0
  40. data/spec/fixtures/test_dir_2/[Dsube]/sub/.gitkeep +0 -0
  41. data/spec/spec_helper.rb +0 -28
  42. data/spec/treevisitor/cli/cli_tree_spec.rb +0 -69
  43. data/spec/treevisitor/directory_walker_spec.rb +0 -99
  44. data/spec/treevisitor/tree_dsl_spec.rb +0 -57
  45. data/spec/treevisitor/tree_dsl_with_derived_class1_spec.rb +0 -53
  46. data/spec/treevisitor/tree_dsl_with_derived_class_spec.rb +0 -51
  47. data/spec/treevisitor/tree_node_paths_spec.rb +0 -70
  48. data/spec/treevisitor/tree_node_spec.rb +0 -135
  49. data/spec/treevisitor/tree_node_visitor_delegate_spec.rb +0 -35
  50. data/spec/treevisitor/tree_node_visitor_dsl_spec.rb +0 -66
  51. data/spec/treevisitor/util/dir_processor_spec.rb +0 -13
  52. data/spec/treevisitor/visitors/block_tree_node_visitor_spec.rb +0 -25
  53. data/spec/treevisitor/visitors/callback_tree_node_visitor2_spec.rb +0 -38
  54. data/spec/treevisitor/visitors/depth_tree_node_visitor_spec.rb +0 -28
  55. data/spec/treevisitor/visitors/tree_node_visitors_spec.rb +0 -27
  56. data/tasks/rspec.rake +0 -34
  57. data/tasks/yard.rake +0 -36
@@ -1,57 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.join(File.dirname(__FILE__), "..", "spec_helper")
3
-
4
- describe "TreeNodeDsl" do
5
-
6
- it "should build tree with dsl" do
7
- tree = TreeNode.create do
8
- node "root" do
9
- leaf "l1"
10
- leaf "l2"
11
- node "sub" do
12
- leaf "l3"
13
- end
14
- node "wo leaves"
15
- end
16
- end
17
-
18
- # puts tree.to_str
19
- out =<<EOS
20
- root
21
- |-- l1
22
- |-- l2
23
- |-- sub
24
- | `-- l3
25
- `-- wo leaves
26
- EOS
27
- tree.to_str.should == out
28
- end
29
-
30
- it "test_dsl_block_with_arg" do
31
- tree = TreeNode.create do
32
- node "root" do |node|
33
- node.prefix_path=("pre/")
34
- leaf "l1"
35
- leaf "l2"
36
- node "sub" do
37
- leaf "l3" do |leaf|
38
- end
39
- end
40
- node "woleaves"
41
- end
42
- end
43
-
44
- # puts tree.to_str
45
- out =<<EOS
46
- root
47
- |-- l1
48
- |-- l2
49
- |-- sub
50
- | `-- l3
51
- `-- woleaves
52
- EOS
53
- tree.to_str.should == out
54
- tree.find("l3").path_with_prefix.should == "pre/root/sub/l3"
55
- end
56
-
57
- end
@@ -1,53 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.join(File.dirname(__FILE__), "..", "spec_helper")
3
-
4
- describe "Tree Node Dsl Derived Class with n-arg constructor" do
5
-
6
- class ArgsTreeNode < TreeNode
7
- attr_reader :description
8
-
9
- def initialize(name, description, parent)
10
- super(name, parent)
11
- @description = description
12
- end
13
-
14
- def to_s
15
- "a: #{description}"
16
- end
17
- end
18
-
19
- class ArgsLeafNode < LeafNode
20
- attr_reader :description
21
-
22
- def initialize(name, description, parent)
23
- super(name, parent)
24
- @description = description
25
- end
26
-
27
- def to_s
28
- "a: #{description}"
29
- end
30
- end
31
-
32
- it "test_derivated_args" do
33
- tree = TreeNode.create(ArgsTreeNode, ArgsLeafNode) do
34
- node "root", "droot" do
35
- leaf "l1", "dl1"
36
- leaf "l2", "dl2"
37
- node "sub", "dsub" do
38
- leaf "l3", "dl3"
39
- end
40
- end
41
- end
42
-
43
- # puts tree.to_str
44
- out =<<EOS
45
- a: droot
46
- |-- a: dl1
47
- |-- a: dl2
48
- `-- a: dsub
49
- `-- a: dl3
50
- EOS
51
- tree.to_str.should == out
52
- end
53
- end
@@ -1,51 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.join(File.dirname(__FILE__), "..", "spec_helper")
3
-
4
- describe "Tree Node Dsl Derived Class with no-arg constructor " do
5
-
6
- class DTreeNode < TreeNode
7
- def to_s
8
- "dt: #{content}"
9
- end
10
- end
11
-
12
- class DLeafNode < LeafNode
13
- def to_s
14
- "dl: #{content}"
15
- end
16
- end
17
-
18
- it "dsl with non-arg constructor" do
19
- tree = TreeNode.create(DTreeNode, DLeafNode) do
20
- node "root" do
21
- leaf "l1"
22
- leaf "l2"
23
- node "sub" do
24
- leaf "l3"
25
- end
26
- end
27
- end
28
-
29
- # puts tree.to_str
30
- out =<<EOS
31
- dt: root
32
- |-- dl: l1
33
- |-- dl: l2
34
- `-- dt: sub
35
- `-- dl: l3
36
- EOS
37
- tree.to_str.should == out
38
-
39
- tree = DTreeNode.create(DLeafNode) do
40
- node "root" do
41
- leaf "l1"
42
- leaf "l2"
43
- node "sub" do
44
- leaf "l3"
45
- end
46
- end
47
- end
48
- tree.to_str.should == out
49
- end
50
-
51
- end
@@ -1,70 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.join(File.dirname(__FILE__), "..", "spec_helper")
3
-
4
- describe TreeNode do
5
-
6
- context "paths" do
7
-
8
- before do
9
- @tree = TreeNode.new("a")
10
- ln1 = LeafNode.new("1", @tree)
11
- ln2 = LeafNode.new("2", @tree)
12
- @sub_tree = TreeNode.new("b", @tree)
13
- @ln3 = LeafNode.new("3", @sub_tree)
14
- @ln4 = LeafNode.new("12", @sub_tree)
15
- end
16
-
17
- it "correct path" do
18
- @tree.path.should == "a"
19
- @sub_tree.path.should == "a/b"
20
- @tree.path_with_prefix.should == "a"
21
- @sub_tree.path_with_prefix.should == "a/b"
22
- end
23
-
24
- it "assign prefix path with a /" do
25
- @tree.prefix_path= "<root>/"
26
-
27
- @tree.prefix_path.should == "<root>/"
28
- @tree.path.should == "a"
29
- @sub_tree.path.should == "a/b"
30
- @tree.path_with_prefix.should == "<root>/a"
31
- @sub_tree.path_with_prefix.should == "<root>/a/b"
32
- end
33
-
34
- it "assign empty prefix path" do
35
- @tree.prefix_path= ""
36
-
37
- @tree.prefix_path.should == "/"
38
- @tree.path.should == "a"
39
- @sub_tree.path.should == "a/b"
40
- @tree.path_with_prefix.should == "/a"
41
- @sub_tree.path_with_prefix.should == "/a/b"
42
- end
43
-
44
- it "assign prefix path wo a /" do
45
- @tree.prefix_path= "<root>"
46
-
47
- @tree.prefix_path.should == "<root>/"
48
- @tree.path_with_prefix.should == "<root>/a"
49
- @sub_tree.path_with_prefix.should == "<root>/a/b"
50
- end
51
-
52
- it "invalidate" do
53
- @tree.prefix_path="root/"
54
- @sub_tree.path.should == "a/b"
55
- @sub_tree.path_with_prefix.should == "root/a/b"
56
- @sub_tree.depth.should == 2
57
-
58
- r = TreeNode.new("r")
59
- r.add_child(@tree)
60
- @sub_tree.path.should == "r/a/b"
61
- @sub_tree.path_with_prefix.should == "r/a/b"
62
-
63
- r.prefix_path="new_root/"
64
- @sub_tree.path.should == "r/a/b"
65
- @sub_tree.path_with_prefix.should == "new_root/r/a/b"
66
- @sub_tree.depth.should == 3
67
- end
68
-
69
- end
70
- end
@@ -1,135 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.join(File.dirname(__FILE__), "..", "spec_helper")
3
-
4
- describe TreeNode do
5
-
6
- it "should initialize correctly" do
7
- ta = TreeNode.new("a")
8
- ta.should be_root
9
-
10
- ln1 = LeafNode.new("1", ta)
11
- ln1.parent.should == ta
12
- ln1.should_not be_root
13
-
14
- ln2 = LeafNode.new("2", ta)
15
- tb = TreeNode.new("b", ta)
16
- ln3 = LeafNode.new("3", tb)
17
- ln3.parent.should == tb
18
-
19
- # test depth
20
- tb.depth.should == 2
21
- ln3.depth.should == 3
22
-
23
- # test nr_nodes
24
- tb.nr_nodes.should == 1
25
- ta.nr_nodes.should == 4
26
-
27
- # puts ta.to_str
28
- end
29
-
30
- it "should add child and leaf" do
31
- ta = TreeNode.new("a")
32
- ta.should be_root
33
-
34
- ln1 = LeafNode.new("1")
35
- ta.add_leaf(ln1)
36
- ln1.parent.should == ta
37
-
38
- ln2 = LeafNode.new("2", ta)
39
- ta.add_leaf(ln2)
40
-
41
- tb = TreeNode.new("b", ta)
42
- ln3 = LeafNode.new("3", tb)
43
- tb.add_leaf(ln3)
44
- ln3.parent.should == tb
45
-
46
- ta.add_child(tb)
47
- # puts ta.to_str
48
- end
49
-
50
- it "next and prev" do
51
- ta = TreeNode.new("a")
52
- ta.prev.should be_nil
53
- ta.next.should be_nil
54
-
55
- ln1 = LeafNode.new("1", ta)
56
- ln1.prev.should be_nil
57
- ln1.next.should be_nil
58
-
59
- ln2 = LeafNode.new("2", ta)
60
- ln2.prev.should == ln1
61
- ln2.next.should be_nil
62
-
63
- ln3 = LeafNode.new("3", ta)
64
- ln2.next.should == ln3
65
-
66
- tb = TreeNode.new("b", ta)
67
- tb.next.should be_nil
68
- tb.prev.should be_nil
69
-
70
- tc = TreeNode.new("c", ta)
71
- tc.prev.should == tb
72
- tc.next.should be_nil
73
- end
74
-
75
- context "navigate tree" do
76
-
77
- before do
78
- @tree = TreeNode.new("a")
79
- ln1 = LeafNode.new("1", @tree)
80
- ln2 = LeafNode.new("2", @tree)
81
- @sub_tree = TreeNode.new("b", @tree)
82
- @ln3 = LeafNode.new("3", @sub_tree)
83
- @ln4 = LeafNode.new("12", @sub_tree)
84
- end
85
-
86
- it "nr_nodes and nr_leaves and nr_children" do
87
- @tree.nr_nodes.should == 5
88
- @tree.nr_leaves.should == 4
89
- @tree.nr_children.should == 1
90
-
91
- @sub_tree.nr_nodes.should == 2
92
- @sub_tree.nr_leaves.should == 2
93
- @sub_tree.nr_children.should == 0
94
- end
95
-
96
-
97
- context "find" do
98
-
99
- it "find by string" do
100
- @tree.find("a").should === @tree
101
- @tree.find("b").should === @sub_tree
102
- @tree.find("3").should === @ln3
103
- @tree.find("not existent").should be_nil
104
- end
105
-
106
- it "find by regex" do
107
- @tree.find(/[a,b]/).should === @tree
108
- @tree.find(/[b,c]/).should === @sub_tree
109
- @tree.find(/\d\d/).should === @ln4
110
- @tree.find(/not existent/).should be_nil
111
- end
112
-
113
- it "find with block" do
114
- @tree.find { |e| e.content == "a" }.should === @tree
115
- @tree.find { |e| e.content == "b" }.should === @sub_tree
116
- @tree.find { |e| e.content == "3" }.should === @ln3
117
- @tree.find { |e| e.content == "not existent" }.should be_nil
118
- end
119
-
120
- it "to_str" do
121
- out = <<EOS
122
- a
123
- |-- 1
124
- |-- 2
125
- `-- b
126
- |-- 3
127
- `-- 12
128
- EOS
129
- @tree.to_str.should == out
130
- end
131
-
132
- end
133
-
134
- end
135
- end
@@ -1,35 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.join(File.dirname(__FILE__), "..", "spec_helper")
3
-
4
- describe TreeNodeVisitor do
5
-
6
- class Delegate
7
- def enter_node(node)
8
- @entered_node= true
9
- end
10
-
11
- def exit_node(node)
12
- @exit_node= true
13
- end
14
-
15
- def visit_leaf(leaf)
16
- @visited_leaf= true
17
- end
18
- end
19
-
20
- it "should use a delegate" do
21
-
22
- delegate = Delegate.new
23
- visitor = TreeNodeVisitor.new(delegate)
24
-
25
- visitor.enter_node(nil)
26
- delegate.instance_eval{ @entered_node }.should be_true
27
-
28
- visitor.exit_node(nil)
29
- delegate.instance_eval{ @exit_node }.should be_true
30
-
31
- visitor.visit_leaf(nil)
32
- delegate.instance_eval{ @visited_leaf }.should be_true
33
- end
34
-
35
- end
@@ -1,66 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.join(File.dirname(__FILE__), "..", "spec_helper")
3
-
4
- describe TreeNodeVisitor do
5
-
6
- it "should initialize correctly" do
7
- visitor = TreeNodeVisitor.new do
8
-
9
- on_enter_node do |tree_node|
10
- @entered_node = true
11
- end
12
-
13
- on_exit_node do |tree_node|
14
- @exit_node = true
15
- end
16
-
17
- on_leaf do |leaf_node|
18
- @visit_leaf = true
19
- end
20
- end
21
-
22
- visitor.enter_node(nil)
23
- visitor.instance_eval{ @entered_node }.should be_true
24
-
25
- visitor.exit_node(nil)
26
- visitor.instance_eval{ @exit_node }.should be_true
27
-
28
- visitor.visit_leaf(nil)
29
- visitor.instance_eval{ @visit_leaf }.should be_true
30
- end
31
-
32
- it "should initialize correctly" do
33
- visitor = TreeNodeVisitor.new do
34
-
35
- on_enter_node do |node, parent|
36
- @node = node
37
- @parent = parent
38
- end
39
-
40
- on_exit_node do |node, parent|
41
- @node = node
42
- @parent = parent
43
- end
44
-
45
- on_leaf do |leaf, parent|
46
- @leaf = leaf
47
- @parent = parent
48
- end
49
- end
50
-
51
- visitor.instance_eval{ @stack = ["p"] }
52
- visitor.enter_node("n")
53
- visitor.instance_eval{ @node }.should == "n"
54
- visitor.instance_eval{ @parent }.should == "p"
55
- visitor.instance_eval{ @stack }.should have(2).node
56
-
57
- visitor.exit_node("n")
58
- visitor.instance_eval{ @node }.should == "n"
59
- visitor.instance_eval{ @stack }.should have(1).node
60
-
61
- visitor.instance_eval{ @stack = ["p"] }
62
- visitor.visit_leaf("l")
63
- visitor.instance_eval{ @leaf }.should == "l"
64
- visitor.instance_eval{ @parent }.should == "p"
65
- end
66
- end