nanoc3 3.2.0a3 → 3.2.0a4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. data/.gemtest +0 -0
  2. data/LICENSE +1 -1
  3. data/NEWS.md +23 -4
  4. data/README.md +7 -0
  5. data/lib/nanoc3/base/compilation/checksum_store.rb +17 -90
  6. data/lib/nanoc3/base/compilation/compiled_content_cache.rb +5 -0
  7. data/lib/nanoc3/base/compilation/compiler.rb +112 -175
  8. data/lib/nanoc3/base/compilation/compiler_dsl.rb +54 -11
  9. data/lib/nanoc3/base/compilation/dependency_tracker.rb +32 -65
  10. data/lib/nanoc3/base/compilation/filter.rb +4 -3
  11. data/lib/nanoc3/base/compilation/item_rep_proxy.rb +19 -4
  12. data/lib/nanoc3/base/compilation/item_rep_recorder_proxy.rb +90 -0
  13. data/lib/nanoc3/base/compilation/outdatedness_checker.rb +152 -15
  14. data/lib/nanoc3/base/compilation/outdatedness_reasons.rb +12 -9
  15. data/lib/nanoc3/base/compilation/rule.rb +3 -1
  16. data/lib/nanoc3/base/compilation/rule_memory_calculator.rb +42 -0
  17. data/lib/nanoc3/base/compilation/rule_memory_store.rb +53 -0
  18. data/lib/nanoc3/base/compilation/rules_collection.rb +205 -0
  19. data/lib/nanoc3/base/core_ext/array.rb +20 -0
  20. data/lib/nanoc3/base/core_ext/hash.rb +30 -0
  21. data/lib/nanoc3/base/core_ext/pathname.rb +26 -0
  22. data/lib/nanoc3/base/core_ext/string.rb +12 -0
  23. data/lib/nanoc3/base/core_ext.rb +1 -0
  24. data/lib/nanoc3/base/directed_graph.rb +11 -3
  25. data/lib/nanoc3/base/errors.rb +0 -4
  26. data/lib/nanoc3/base/memoization.rb +72 -0
  27. data/lib/nanoc3/base/result_data/item_rep.rb +64 -25
  28. data/lib/nanoc3/base/source_data/code_snippet.rb +9 -0
  29. data/lib/nanoc3/base/source_data/configuration.rb +20 -0
  30. data/lib/nanoc3/base/source_data/item.rb +29 -4
  31. data/lib/nanoc3/base/source_data/layout.rb +20 -1
  32. data/lib/nanoc3/base/source_data/site.rb +49 -26
  33. data/lib/nanoc3/base/store.rb +10 -1
  34. data/lib/nanoc3/base.rb +6 -1
  35. data/lib/nanoc3/cli/base.rb +20 -7
  36. data/lib/nanoc3/cli/commands/compile.rb +0 -2
  37. data/lib/nanoc3/cli/commands/create_site.rb +16 -7
  38. data/lib/nanoc3/cli/commands/debug.rb +3 -3
  39. data/lib/nanoc3/cli/commands/view.rb +1 -0
  40. data/lib/nanoc3/cli/commands/watch.rb +2 -1
  41. data/lib/nanoc3/data_sources/deprecated/delicious.rb +0 -2
  42. data/lib/nanoc3/data_sources/deprecated/last_fm.rb +0 -2
  43. data/lib/nanoc3/data_sources/deprecated/twitter.rb +0 -2
  44. data/lib/nanoc3/data_sources/filesystem.rb +17 -3
  45. data/lib/nanoc3/data_sources/filesystem_unified.rb +17 -17
  46. data/lib/nanoc3/extra/auto_compiler.rb +5 -1
  47. data/lib/nanoc3/extra/core_ext/time.rb +1 -1
  48. data/lib/nanoc3/extra/file_proxy.rb +11 -1
  49. data/lib/nanoc3/extra/validators/links.rb +1 -1
  50. data/lib/nanoc3/filters/asciidoc.rb +3 -3
  51. data/lib/nanoc3/filters/colorize_syntax.rb +106 -27
  52. data/lib/nanoc3/filters/erb.rb +16 -6
  53. data/lib/nanoc3/filters/erubis.rb +5 -1
  54. data/lib/nanoc3/filters/haml.rb +2 -1
  55. data/lib/nanoc3/filters/less.rb +3 -6
  56. data/lib/nanoc3/filters/mustache.rb +3 -0
  57. data/lib/nanoc3/filters/redcarpet.rb +27 -0
  58. data/lib/nanoc3/filters/sass.rb +1 -5
  59. data/lib/nanoc3/filters/slim.rb +25 -0
  60. data/lib/nanoc3/filters/typogruby.rb +23 -0
  61. data/lib/nanoc3/filters.rb +6 -0
  62. data/lib/nanoc3/helpers/blogging.rb +22 -26
  63. data/lib/nanoc3/helpers/rendering.rb +1 -1
  64. data/lib/nanoc3/helpers/xml_sitemap.rb +11 -2
  65. data/lib/nanoc3.rb +24 -3
  66. data/nanoc3.gemspec +4 -3
  67. data/tasks/clean.rake +11 -0
  68. data/tasks/doc.rake +14 -0
  69. data/tasks/test.rake +38 -0
  70. data/test/base/core_ext/array_spec.rb +55 -0
  71. data/test/base/core_ext/hash_spec.rb +82 -0
  72. data/test/base/core_ext/pathname_spec.rb +29 -0
  73. data/test/base/core_ext/string_spec.rb +39 -0
  74. data/test/base/test_checksum_store.rb +37 -0
  75. data/test/base/test_code_snippet.rb +33 -0
  76. data/test/base/test_compiler.rb +303 -0
  77. data/test/base/test_compiler_dsl.rb +156 -0
  78. data/test/base/test_context.rb +33 -0
  79. data/test/base/test_data_source.rb +48 -0
  80. data/test/base/test_dependency_tracker.rb +264 -0
  81. data/test/base/test_directed_graph.rb +285 -0
  82. data/test/base/test_filter.rb +85 -0
  83. data/test/base/test_item.rb +164 -0
  84. data/test/base/test_item_rep.rb +555 -0
  85. data/test/base/test_layout.rb +44 -0
  86. data/test/base/test_memoization.rb +53 -0
  87. data/test/base/test_notification_center.rb +36 -0
  88. data/test/base/test_outdatedness_checker.rb +365 -0
  89. data/test/base/test_plugin.rb +32 -0
  90. data/test/base/test_rule.rb +21 -0
  91. data/test/base/test_rule_context.rb +67 -0
  92. data/test/base/test_site.rb +144 -0
  93. data/test/cli/commands/test_compile.rb +12 -0
  94. data/test/cli/commands/test_create_item.rb +12 -0
  95. data/test/cli/commands/test_create_layout.rb +28 -0
  96. data/test/cli/commands/test_create_site.rb +24 -0
  97. data/test/cli/commands/test_help.rb +12 -0
  98. data/test/cli/commands/test_info.rb +12 -0
  99. data/test/cli/commands/test_update.rb +12 -0
  100. data/test/cli/test_logger.rb +12 -0
  101. data/test/data_sources/test_filesystem.rb +420 -0
  102. data/test/data_sources/test_filesystem_unified.rb +562 -0
  103. data/test/data_sources/test_filesystem_verbose.rb +359 -0
  104. data/test/extra/core_ext/test_enumerable.rb +32 -0
  105. data/test/extra/core_ext/test_time.rb +17 -0
  106. data/test/extra/deployers/test_rsync.rb +234 -0
  107. data/test/extra/test_auto_compiler.rb +417 -0
  108. data/test/extra/test_file_proxy.rb +21 -0
  109. data/test/extra/test_vcs.rb +24 -0
  110. data/test/extra/validators/test_links.rb +53 -0
  111. data/test/extra/validators/test_w3c.rb +49 -0
  112. data/test/filters/test_asciidoc.rb +22 -0
  113. data/test/filters/test_bluecloth.rb +20 -0
  114. data/test/filters/test_coderay.rb +46 -0
  115. data/test/filters/test_colorize_syntax.rb +149 -0
  116. data/test/filters/test_erb.rb +101 -0
  117. data/test/filters/test_erubis.rb +72 -0
  118. data/test/filters/test_haml.rb +98 -0
  119. data/test/filters/test_kramdown.rb +20 -0
  120. data/test/filters/test_less.rb +59 -0
  121. data/test/filters/test_markaby.rb +26 -0
  122. data/test/filters/test_maruku.rb +20 -0
  123. data/test/filters/test_mustache.rb +27 -0
  124. data/test/filters/test_rainpress.rb +31 -0
  125. data/test/filters/test_rdiscount.rb +33 -0
  126. data/test/filters/test_rdoc.rb +18 -0
  127. data/test/filters/test_redcarpet.rb +63 -0
  128. data/test/filters/test_redcloth.rb +35 -0
  129. data/test/filters/test_relativize_paths.rb +231 -0
  130. data/test/filters/test_rubypants.rb +20 -0
  131. data/test/filters/test_sass.rb +103 -0
  132. data/test/filters/test_slim.rb +37 -0
  133. data/test/filters/test_typogruby.rb +23 -0
  134. data/test/helper.rb +161 -0
  135. data/test/helpers/test_blogging.rb +756 -0
  136. data/test/helpers/test_breadcrumbs.rb +83 -0
  137. data/test/helpers/test_capturing.rb +43 -0
  138. data/test/helpers/test_filtering.rb +108 -0
  139. data/test/helpers/test_html_escape.rb +34 -0
  140. data/test/helpers/test_link_to.rb +251 -0
  141. data/test/helpers/test_rendering.rb +90 -0
  142. data/test/helpers/test_tagging.rb +89 -0
  143. data/test/helpers/test_text.rb +26 -0
  144. data/test/helpers/test_xml_sitemap.rb +105 -0
  145. data/test/tasks/test_clean.rb +69 -0
  146. metadata +96 -27
  147. data/lib/nanoc3/base/compilation/checksummer.rb +0 -68
@@ -0,0 +1,264 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::DependencyTrackerTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_initialize
10
+ # Mock items
11
+ items = [ mock, mock ]
12
+
13
+ # Create
14
+ tracker = Nanoc3::DependencyTracker.new(items)
15
+
16
+ # Verify no dependencies yet
17
+ assert_empty tracker.objects_causing_outdatedness_of(items[0])
18
+ assert_empty tracker.objects_causing_outdatedness_of(items[1])
19
+ end
20
+
21
+ def test_record_dependency
22
+ # Mock items
23
+ items = [ mock, mock ]
24
+
25
+ # Create
26
+ tracker = Nanoc3::DependencyTracker.new(items)
27
+
28
+ # Record some dependencies
29
+ tracker.record_dependency(items[0], items[1])
30
+
31
+ # Verify dependencies
32
+ assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
33
+ end
34
+
35
+ def test_record_dependency_no_self
36
+ # Mock items
37
+ items = [ mock, mock ]
38
+
39
+ # Create
40
+ tracker = Nanoc3::DependencyTracker.new(items)
41
+
42
+ # Record some dependencies
43
+ tracker.record_dependency(items[0], items[0])
44
+ tracker.record_dependency(items[0], items[1])
45
+
46
+ # Verify dependencies
47
+ assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
48
+ end
49
+
50
+ def test_record_dependency_no_doubles
51
+ # Mock items
52
+ items = [ mock, mock ]
53
+
54
+ # Create
55
+ tracker = Nanoc3::DependencyTracker.new(items)
56
+
57
+ # Record some dependencies
58
+ tracker.record_dependency(items[0], items[1])
59
+ tracker.record_dependency(items[0], items[1])
60
+ tracker.record_dependency(items[0], items[1])
61
+
62
+ # Verify dependencies
63
+ assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
64
+ end
65
+
66
+ def test_objects_causing_outdatedness_of
67
+ # Mock items
68
+ items = [ mock, mock, mock ]
69
+
70
+ # Create
71
+ tracker = Nanoc3::DependencyTracker.new(items)
72
+
73
+ # Record some dependencies
74
+ tracker.record_dependency(items[0], items[1])
75
+ tracker.record_dependency(items[1], items[2])
76
+
77
+ # Verify dependencies
78
+ assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
79
+ end
80
+
81
+ def test_objects_outdated_due_to
82
+ # Mock items
83
+ items = [ mock, mock, mock ]
84
+
85
+ # Create
86
+ tracker = Nanoc3::DependencyTracker.new(items)
87
+
88
+ # Record some dependencies
89
+ tracker.record_dependency(items[0], items[1])
90
+ tracker.record_dependency(items[1], items[2])
91
+
92
+ # Verify dependencies
93
+ assert_contains_exactly [ items[0] ], tracker.objects_outdated_due_to(items[1])
94
+ end
95
+
96
+ def test_start_and_stop
97
+ # Mock items
98
+ items = [ mock, mock ]
99
+
100
+ # Create
101
+ tracker = Nanoc3::DependencyTracker.new(items)
102
+
103
+ # Start, do something and stop
104
+ tracker.start
105
+ Nanoc3::NotificationCenter.post(:visit_started, items[0])
106
+ Nanoc3::NotificationCenter.post(:visit_started, items[1])
107
+ Nanoc3::NotificationCenter.post(:visit_ended, items[1])
108
+ Nanoc3::NotificationCenter.post(:visit_ended, items[0])
109
+ tracker.stop
110
+
111
+ # Verify dependencies
112
+ assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
113
+ assert_empty tracker.objects_causing_outdatedness_of(items[1])
114
+ end
115
+
116
+ def test_store_graph_and_load_graph_simple
117
+ # Mock items
118
+ items = [ mock('0'), mock('1'), mock('2'), mock('3') ]
119
+ items.each { |i| i.stubs(:type).returns(:item) }
120
+ items[0].stubs(:reference).returns([ :item, '/aaa/' ])
121
+ items[1].stubs(:reference).returns([ :item, '/bbb/' ])
122
+ items[2].stubs(:reference).returns([ :item, '/ccc/' ])
123
+ items[3].stubs(:reference).returns([ :item, '/ddd/' ])
124
+
125
+ # Create
126
+ tracker = Nanoc3::DependencyTracker.new(items)
127
+
128
+ # Record some dependencies
129
+ tracker.record_dependency(items[0], items[1])
130
+ tracker.record_dependency(items[1], items[2])
131
+ tracker.record_dependency(items[1], items[3])
132
+
133
+ # Store
134
+ tracker.store_graph
135
+ assert File.file?(tracker.filename)
136
+
137
+ # Re-create
138
+ tracker = Nanoc3::DependencyTracker.new(items)
139
+
140
+ # Load
141
+ tracker.load_graph
142
+
143
+ # Check loaded graph
144
+ assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
145
+ assert_contains_exactly [ items[2], items[3] ], tracker.objects_causing_outdatedness_of(items[1])
146
+ assert_empty tracker.objects_causing_outdatedness_of(items[2])
147
+ assert_empty tracker.objects_causing_outdatedness_of(items[3])
148
+ end
149
+
150
+ def test_store_graph_and_load_graph_with_removed_items
151
+ # Mock items
152
+ items = [ mock('0'), mock('1'), mock('2'), mock('3') ]
153
+ items.each { |i| i.stubs(:type).returns(:item) }
154
+ items[0].stubs(:reference).returns([ :item, '/aaa/' ])
155
+ items[1].stubs(:reference).returns([ :item, '/bbb/' ])
156
+ items[2].stubs(:reference).returns([ :item, '/ccc/' ])
157
+ items[3].stubs(:reference).returns([ :item, '/ddd/' ])
158
+
159
+ # Create new and old lists
160
+ old_items = [ items[0], items[1], items[2], items[3] ]
161
+ new_items = [ items[0], items[1], items[2] ]
162
+
163
+ # Create
164
+ tracker = Nanoc3::DependencyTracker.new(old_items)
165
+
166
+ # Record some dependencies
167
+ tracker.record_dependency(old_items[0], old_items[1])
168
+ tracker.record_dependency(old_items[1], old_items[2])
169
+ tracker.record_dependency(old_items[1], old_items[3])
170
+
171
+ # Store
172
+ tracker.store_graph
173
+ assert File.file?(tracker.filename)
174
+
175
+ # Re-create
176
+ tracker = Nanoc3::DependencyTracker.new(new_items)
177
+
178
+ # Load
179
+ tracker.load_graph
180
+
181
+ # Check loaded graph
182
+ assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
183
+ assert_contains_exactly [ items[2], nil ], tracker.objects_causing_outdatedness_of(items[1])
184
+ assert_empty tracker.objects_causing_outdatedness_of(items[2])
185
+ end
186
+
187
+ def test_store_graph_with_nils_in_dst
188
+ # Mock items
189
+ items = [ mock('0'), mock('1'), mock('2') ]
190
+ items.each { |i| i.stubs(:type).returns(:item) }
191
+ items[0].stubs(:reference).returns([ :item, '/aaa/' ])
192
+ items[1].stubs(:reference).returns([ :item, '/bbb/' ])
193
+ items[2].stubs(:reference).returns([ :item, '/ccc/' ])
194
+
195
+ # Create
196
+ tracker = Nanoc3::DependencyTracker.new(items)
197
+
198
+ # Record some dependencies
199
+ tracker.record_dependency(items[0], items[1])
200
+ tracker.record_dependency(items[1], nil)
201
+
202
+ # Store
203
+ tracker.store_graph
204
+ assert File.file?(tracker.filename)
205
+
206
+ # Re-create
207
+ tracker = Nanoc3::DependencyTracker.new(items)
208
+
209
+ # Load
210
+ tracker.load_graph
211
+
212
+ # Check loaded graph
213
+ assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
214
+ assert_contains_exactly [ nil ], tracker.objects_causing_outdatedness_of(items[1])
215
+ end
216
+
217
+ def test_store_graph_with_nils_in_src
218
+ # Mock items
219
+ items = [ mock('0'), mock('1'), mock('2') ]
220
+ items.each { |i| i.stubs(:type).returns(:item) }
221
+ items[0].stubs(:reference).returns([ :item, '/aaa/' ])
222
+ items[1].stubs(:reference).returns([ :item, '/bbb/' ])
223
+ items[2].stubs(:reference).returns([ :item, '/ccc/' ])
224
+
225
+ # Create
226
+ tracker = Nanoc3::DependencyTracker.new(items)
227
+
228
+ # Record some dependencies
229
+ tracker.record_dependency(items[0], items[1])
230
+ tracker.record_dependency(nil, items[2])
231
+
232
+ # Store
233
+ tracker.store_graph
234
+ assert File.file?(tracker.filename)
235
+
236
+ # Re-create
237
+ tracker = Nanoc3::DependencyTracker.new(items)
238
+
239
+ # Load
240
+ tracker.load_graph
241
+
242
+ # Check loaded graph
243
+ assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
244
+ assert_empty tracker.objects_causing_outdatedness_of(items[1])
245
+ end
246
+
247
+ def test_forget_dependencies_for
248
+ # Mock items
249
+ items = [ mock, mock, mock ]
250
+
251
+ # Create
252
+ tracker = Nanoc3::DependencyTracker.new(items)
253
+
254
+ # Record some dependencies
255
+ tracker.record_dependency(items[0], items[1])
256
+ tracker.record_dependency(items[1], items[2])
257
+ assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
258
+
259
+ # Forget dependencies
260
+ tracker.forget_dependencies_for(items[0])
261
+ assert_empty tracker.objects_causing_outdatedness_of(items[0])
262
+ end
263
+
264
+ end
@@ -0,0 +1,285 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::DirectedGraphTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_direct_predecessors
10
+ graph = Nanoc3::DirectedGraph.new([ 1, 2, 3 ])
11
+ graph.add_edge(1, 2)
12
+ graph.add_edge(2, 3)
13
+
14
+ assert_equal [], graph.direct_predecessors_of(1)
15
+ assert_equal [ 1 ], graph.direct_predecessors_of(2)
16
+ assert_equal [ 2 ], graph.direct_predecessors_of(3)
17
+ end
18
+
19
+ def test_predecessors
20
+ graph = Nanoc3::DirectedGraph.new([ 1, 2, 3 ])
21
+ graph.add_edge(1, 2)
22
+ graph.add_edge(2, 3)
23
+
24
+ assert_equal [], graph.predecessors_of(1).sort
25
+ assert_equal [ 1 ], graph.predecessors_of(2).sort
26
+ assert_equal [ 1, 2 ], graph.predecessors_of(3).sort
27
+ end
28
+
29
+ def test_direct_successors
30
+ graph = Nanoc3::DirectedGraph.new([ 1, 2, 3 ])
31
+ graph.add_edge(1, 2)
32
+ graph.add_edge(2, 3)
33
+
34
+ assert_equal [ 2 ], graph.direct_successors_of(1)
35
+ assert_equal [ 3 ], graph.direct_successors_of(2)
36
+ assert_equal [], graph.direct_successors_of(3)
37
+ end
38
+
39
+ def test_successors
40
+ graph = Nanoc3::DirectedGraph.new([ 1, 2, 3 ])
41
+ graph.add_edge(1, 2)
42
+ graph.add_edge(2, 3)
43
+
44
+ assert_equal [ 2, 3 ], graph.successors_of(1).sort
45
+ assert_equal [ 3 ], graph.successors_of(2).sort
46
+ assert_equal [], graph.successors_of(3).sort
47
+ end
48
+
49
+ def test_edges
50
+ graph = Nanoc3::DirectedGraph.new([ 1, 2, 3 ])
51
+ graph.add_edge(1, 2)
52
+ graph.add_edge(2, 3)
53
+
54
+ assert_equal [ [ 0, 1 ], [ 1, 2 ] ], graph.edges.sort
55
+ end
56
+
57
+ def test_edges_with_new_vertices
58
+ graph = Nanoc3::DirectedGraph.new([ 1 ])
59
+ graph.add_edge(1, 2)
60
+ graph.add_edge(3, 2)
61
+
62
+ assert_equal [ [ 0, 1 ], [ 2, 1 ] ], graph.edges.sort
63
+ end
64
+
65
+ def test_add_edge
66
+ graph = Nanoc3::DirectedGraph.new([ 1, 2, 3 ])
67
+
68
+ assert_equal [], graph.successors_of(1)
69
+ assert_equal [], graph.predecessors_of(2)
70
+
71
+ graph.add_edge(1, 2)
72
+
73
+ assert_equal [ 2 ], graph.successors_of(1)
74
+ assert_equal [ 1 ], graph.predecessors_of(2)
75
+ end
76
+
77
+ def test_add_edge_with_new_vertices
78
+ graph = Nanoc3::DirectedGraph.new([ 1 ])
79
+ graph.add_edge(1, 2)
80
+ graph.add_edge(3, 2)
81
+
82
+ assert graph.vertices.include?(2)
83
+ assert graph.vertices.include?(3)
84
+ end
85
+
86
+ def test_remove_edge
87
+ graph = Nanoc3::DirectedGraph.new([ 1, 2, 3 ])
88
+ graph.add_edge(1,2)
89
+
90
+ assert_equal [ 2 ], graph.successors_of(1)
91
+ assert_equal [ 1 ], graph.predecessors_of(2)
92
+
93
+ graph.remove_edge(1, 2)
94
+
95
+ assert_equal [], graph.successors_of(1)
96
+ assert_equal [], graph.predecessors_of(2)
97
+ end
98
+
99
+ def test_delete_edges_from
100
+ graph = Nanoc3::DirectedGraph.new([ 1, 2, 3 ])
101
+
102
+ graph.add_edge(1, 2)
103
+ graph.add_edge(2, 1)
104
+ graph.add_edge(2, 3)
105
+ graph.add_edge(3, 2)
106
+ graph.add_edge(1, 3)
107
+ graph.add_edge(3, 1)
108
+
109
+ assert_equal [ 2, 3 ], graph.direct_predecessors_of(1).sort
110
+ assert_equal [ 2, 3 ], graph.direct_successors_of(1).sort
111
+ assert_equal [ 1, 3 ], graph.direct_predecessors_of(2).sort
112
+ assert_equal [ 1, 3 ], graph.direct_successors_of(2).sort
113
+ assert_equal [ 1, 2 ], graph.direct_predecessors_of(3).sort
114
+ assert_equal [ 1, 2 ], graph.direct_successors_of(3).sort
115
+ assert_equal Set.new([]), graph.roots
116
+
117
+ graph.delete_edges_from(1)
118
+
119
+ assert_equal [ 2, 3 ], graph.direct_predecessors_of(1).sort
120
+ assert_equal [ ], graph.direct_successors_of(1).sort
121
+ assert_equal [ 3 ], graph.direct_predecessors_of(2).sort
122
+ assert_equal [ 1, 3 ], graph.direct_successors_of(2).sort
123
+ assert_equal [ 2 ], graph.direct_predecessors_of(3).sort
124
+ assert_equal [ 1, 2 ], graph.direct_successors_of(3).sort
125
+ assert_equal Set.new([]), graph.roots
126
+
127
+ graph.delete_edges_from(2)
128
+
129
+ assert_equal [ 3 ], graph.direct_predecessors_of(1).sort
130
+ assert_equal [ ], graph.direct_successors_of(1).sort
131
+ assert_equal [ 3 ], graph.direct_predecessors_of(2).sort
132
+ assert_equal [ ], graph.direct_successors_of(2).sort
133
+ assert_equal [ ], graph.direct_predecessors_of(3).sort
134
+ assert_equal [ 1, 2 ], graph.direct_successors_of(3).sort
135
+ assert_equal Set.new([ 3 ]), graph.roots
136
+ end
137
+
138
+ def test_delete_edges_to
139
+ graph = Nanoc3::DirectedGraph.new([ 1, 2, 3 ])
140
+
141
+ graph.add_edge(1, 2)
142
+ graph.add_edge(2, 1)
143
+ graph.add_edge(2, 3)
144
+ graph.add_edge(3, 2)
145
+ graph.add_edge(1, 3)
146
+ graph.add_edge(3, 1)
147
+
148
+ assert_equal [ 2, 3 ], graph.direct_predecessors_of(1).sort
149
+ assert_equal [ 2, 3 ], graph.direct_successors_of(1).sort
150
+ assert_equal [ 1, 3 ], graph.direct_predecessors_of(2).sort
151
+ assert_equal [ 1, 3 ], graph.direct_successors_of(2).sort
152
+ assert_equal [ 1, 2 ], graph.direct_predecessors_of(3).sort
153
+ assert_equal [ 1, 2 ], graph.direct_successors_of(3).sort
154
+ assert_equal Set.new([]), graph.roots
155
+
156
+ graph.delete_edges_to(1)
157
+
158
+ assert_equal [ ], graph.direct_predecessors_of(1).sort
159
+ assert_equal [ 2, 3 ], graph.direct_successors_of(1).sort
160
+ assert_equal [ 1, 3 ], graph.direct_predecessors_of(2).sort
161
+ assert_equal [ 3 ], graph.direct_successors_of(2).sort
162
+ assert_equal [ 1, 2 ], graph.direct_predecessors_of(3).sort
163
+ assert_equal [ 2 ], graph.direct_successors_of(3).sort
164
+ assert_equal Set.new([ 1 ]), graph.roots
165
+
166
+ graph.delete_edges_to(2)
167
+
168
+ assert_equal [ ], graph.direct_predecessors_of(1).sort
169
+ assert_equal [ 3 ], graph.direct_successors_of(1).sort
170
+ assert_equal [ ], graph.direct_predecessors_of(2).sort
171
+ assert_equal [ 3 ], graph.direct_successors_of(2).sort
172
+ assert_equal [ 1, 2 ], graph.direct_predecessors_of(3).sort
173
+ assert_equal [ ], graph.direct_successors_of(3).sort
174
+ assert_equal Set.new([ 1, 2 ]), graph.roots
175
+ end
176
+
177
+ def test_delete_vertex
178
+ graph = Nanoc3::DirectedGraph.new([ 1, 2, 3 ])
179
+
180
+ graph.add_edge(1, 2)
181
+ graph.add_edge(2, 1)
182
+ graph.add_edge(2, 3)
183
+ graph.add_edge(3, 2)
184
+ graph.add_edge(1, 3)
185
+ graph.add_edge(3, 1)
186
+
187
+ graph.delete_vertex(2)
188
+
189
+ assert_equal [ 3 ], graph.direct_predecessors_of(1).sort
190
+ assert_equal [ 3 ], graph.direct_successors_of(1).sort
191
+ assert_equal [ 1 ], graph.direct_predecessors_of(3).sort
192
+ assert_equal [ 1 ], graph.direct_successors_of(3).sort
193
+ assert_equal Set.new([]), graph.roots
194
+ end
195
+
196
+ def test_delete_vertex_resulting_roots
197
+ graph = Nanoc3::DirectedGraph.new([ 1, 2, 3 ])
198
+ assert_equal Set.new([ 1, 2, 3 ]), graph.roots
199
+
200
+ graph.add_edge(1, 2)
201
+ graph.add_edge(2, 3)
202
+ assert_equal Set.new([ 1 ]), graph.roots
203
+
204
+ graph.delete_vertex(2)
205
+ assert_equal Set.new([ 1, 3 ]), graph.roots
206
+ end
207
+
208
+ def test_should_return_empty_array_for_nonexistant_vertices
209
+ graph = Nanoc3::DirectedGraph.new([ 1, 2, 3 ])
210
+
211
+ assert_equal [], graph.direct_predecessors_of(4)
212
+ assert_equal [], graph.predecessors_of(4)
213
+ assert_equal [], graph.direct_successors_of(4)
214
+ assert_equal [], graph.successors_of(4)
215
+ end
216
+
217
+ def test_roots_after_init
218
+ graph = Nanoc3::DirectedGraph.new([ 1, 2, 3 ])
219
+
220
+ assert_equal Set.new([ 1, 2, 3 ]), graph.roots
221
+ end
222
+
223
+ def test_roots_after_adding_edge
224
+ graph = Nanoc3::DirectedGraph.new([ 1, 2, 3 ])
225
+ graph.add_edge(1, 2)
226
+ assert_equal Set.new([ 1, 3 ]), graph.roots
227
+
228
+ graph = Nanoc3::DirectedGraph.new([ 1, 2, 3 ])
229
+ graph.add_edge(1, 3)
230
+ assert_equal Set.new([ 1, 2 ]), graph.roots
231
+
232
+ graph = Nanoc3::DirectedGraph.new([ 1, 2, 3 ])
233
+ graph.add_edge(2, 1)
234
+ assert_equal Set.new([ 2, 3 ]), graph.roots
235
+
236
+ graph = Nanoc3::DirectedGraph.new([ 1, 2, 3 ])
237
+ graph.add_edge(1, 2)
238
+ graph.add_edge(2, 3)
239
+ assert_equal Set.new([ 1 ]), graph.roots
240
+
241
+ graph = Nanoc3::DirectedGraph.new([ 1, 2, 3 ])
242
+ graph.add_edge(1, 2)
243
+ graph.add_edge(2, 3)
244
+ graph.add_edge(3, 1)
245
+ assert_equal Set.new([]), graph.roots
246
+ end
247
+
248
+ def test_roots_after_removing_edge
249
+ graph = Nanoc3::DirectedGraph.new([ 1, 2, 3 ])
250
+ graph.add_edge(1, 2)
251
+ graph.remove_edge(1, 2)
252
+ assert_equal Set.new([ 1, 2, 3 ]), graph.roots
253
+
254
+ graph = Nanoc3::DirectedGraph.new([ 1, 2, 3 ])
255
+ graph.add_edge(1, 3)
256
+ assert_equal Set.new([ 1, 2 ]), graph.roots
257
+ graph.remove_edge(1, 2) # no such edge
258
+ assert_equal Set.new([ 1, 2 ]), graph.roots
259
+
260
+ graph = Nanoc3::DirectedGraph.new([ 1, 2, 3 ])
261
+ graph.add_edge(2, 1)
262
+ graph.remove_edge(2, 1)
263
+ assert_equal Set.new([ 1, 2, 3 ]), graph.roots
264
+
265
+ graph = Nanoc3::DirectedGraph.new([ 1, 2, 3 ])
266
+ graph.add_edge(1, 2)
267
+ graph.add_edge(2, 3)
268
+ graph.remove_edge(1, 2)
269
+ assert_equal Set.new([ 1, 2 ]), graph.roots
270
+ graph.remove_edge(2, 3)
271
+ assert_equal Set.new([ 1, 2, 3 ]), graph.roots
272
+
273
+ graph = Nanoc3::DirectedGraph.new([ 1, 2, 3 ])
274
+ graph.add_edge(1, 2)
275
+ graph.add_edge(2, 3)
276
+ graph.add_edge(3, 1)
277
+ graph.remove_edge(1, 2)
278
+ assert_equal Set.new([ 2 ]), graph.roots
279
+ graph.remove_edge(2, 3)
280
+ assert_equal Set.new([ 2, 3 ]), graph.roots
281
+ graph.remove_edge(3, 1)
282
+ assert_equal Set.new([ 1, 2, 3 ]), graph.roots
283
+ end
284
+
285
+ end
@@ -0,0 +1,85 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::FilterTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_initialize
10
+ # Create filter
11
+ filter = Nanoc3::Filter.new
12
+
13
+ # Test assigns
14
+ assert_equal({}, filter.instance_eval { @assigns })
15
+ end
16
+
17
+ def test_assigns
18
+ # Create filter
19
+ filter = Nanoc3::Filter.new({ :foo => 'bar' })
20
+
21
+ # Check assigns
22
+ assert_equal('bar', filter.assigns[:foo])
23
+ end
24
+
25
+ def test_assigns_with_instance_variables
26
+ # Create filter
27
+ filter = Nanoc3::Filter.new({ :foo => 'bar' })
28
+
29
+ # Check assigns
30
+ assert_equal('bar', filter.instance_eval { @foo })
31
+ end
32
+
33
+ def test_assigns_with_instance_methods
34
+ # Create filter
35
+ filter = Nanoc3::Filter.new({ :foo => 'bar' })
36
+
37
+ # Check assigns
38
+ assert_equal('bar', filter.instance_eval { foo })
39
+ end
40
+
41
+ def test_run
42
+ # Create filter
43
+ filter = Nanoc3::Filter.new
44
+
45
+ # Make sure an error is raised
46
+ assert_raises(NotImplementedError) do
47
+ filter.run(nil)
48
+ end
49
+ end
50
+
51
+ def test_filename_item
52
+ # Mock items
53
+ item = mock
54
+ item.expects(:identifier).returns('/foo/bar/baz/')
55
+ item_rep = mock
56
+ item_rep.expects(:name).returns(:quux)
57
+
58
+ # Create filter
59
+ filter = Nanoc3::Filter.new({ :item => item, :item_rep => item_rep })
60
+
61
+ # Check filename
62
+ assert_equal('item /foo/bar/baz/ (rep quux)', filter.filename)
63
+ end
64
+
65
+ def test_filename_layout
66
+ # Mock items
67
+ layout = mock
68
+ layout.expects(:identifier).returns('/wohba/')
69
+
70
+ # Create filter
71
+ filter = Nanoc3::Filter.new({ :item => mock, :item_rep => mock, :layout => layout })
72
+
73
+ # Check filename
74
+ assert_equal('layout /wohba/', filter.filename)
75
+ end
76
+
77
+ def test_filename_unknown
78
+ # Create filter
79
+ filter = Nanoc3::Filter.new({})
80
+
81
+ # Check filename
82
+ assert_equal('?', filter.filename)
83
+ end
84
+
85
+ end