nanoc3 3.1.9 → 3.2.0a1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. data/LICENSE +1 -1
  2. data/NEWS.md +0 -50
  3. data/README.md +3 -15
  4. data/bin/nanoc3 +2 -0
  5. data/lib/nanoc3/base/checksummer.rb +40 -0
  6. data/lib/nanoc3/base/code_snippet.rb +30 -12
  7. data/lib/nanoc3/base/compiled_content_cache.rb +86 -0
  8. data/lib/nanoc3/base/compiler.rb +134 -95
  9. data/lib/nanoc3/base/compiler_dsl.rb +12 -11
  10. data/lib/nanoc3/base/core_ext/string.rb +2 -2
  11. data/lib/nanoc3/base/data_source.rb +17 -16
  12. data/lib/nanoc3/base/dependency_tracker.rb +102 -121
  13. data/lib/nanoc3/base/directed_graph.rb +65 -3
  14. data/lib/nanoc3/base/errors.rb +20 -16
  15. data/lib/nanoc3/base/item.rb +58 -50
  16. data/lib/nanoc3/base/item_rep.rb +177 -150
  17. data/lib/nanoc3/base/layout.rb +51 -18
  18. data/lib/nanoc3/base/notification_center.rb +8 -8
  19. data/lib/nanoc3/base/plugin_registry.rb +9 -9
  20. data/lib/nanoc3/base/rule.rb +18 -9
  21. data/lib/nanoc3/base/rule_context.rb +5 -5
  22. data/lib/nanoc3/base/site.rb +135 -47
  23. data/lib/nanoc3/base.rb +21 -19
  24. data/lib/nanoc3/cli/base.rb +51 -74
  25. data/lib/nanoc3/cli/commands/autocompile.rb +3 -0
  26. data/lib/nanoc3/cli/commands/compile.rb +35 -74
  27. data/lib/nanoc3/cli/commands/create_site.rb +17 -5
  28. data/lib/nanoc3/cli/commands/debug.rb +11 -4
  29. data/lib/nanoc3/cli/commands/view.rb +0 -1
  30. data/lib/nanoc3/cli/commands/watch.rb +148 -0
  31. data/lib/nanoc3/cli/commands.rb +1 -0
  32. data/lib/nanoc3/cli/logger.rb +15 -21
  33. data/lib/nanoc3/data_sources/deprecated/twitter.rb +0 -1
  34. data/lib/nanoc3/data_sources/filesystem.rb +11 -40
  35. data/lib/nanoc3/data_sources/filesystem_unified.rb +22 -22
  36. data/lib/nanoc3/extra/auto_compiler.rb +1 -1
  37. data/lib/nanoc3/extra/chick.rb +8 -8
  38. data/lib/nanoc3/extra/deployers/rsync.rb +2 -3
  39. data/lib/nanoc3/extra/validators/links.rb +32 -51
  40. data/lib/nanoc3/extra/validators/w3c.rb +2 -2
  41. data/lib/nanoc3/extra/vcs.rb +1 -1
  42. data/lib/nanoc3/filters/colorize_syntax.rb +15 -19
  43. data/lib/nanoc3/filters/erb.rb +1 -5
  44. data/lib/nanoc3/filters/erubis.rb +1 -5
  45. data/lib/nanoc3/filters/haml.rb +1 -2
  46. data/lib/nanoc3/filters/less.rb +2 -51
  47. data/lib/nanoc3/filters/mustache.rb +21 -0
  48. data/lib/nanoc3/filters/rdiscount.rb +1 -2
  49. data/lib/nanoc3/filters/relativize_paths.rb +3 -2
  50. data/lib/nanoc3/filters/sass.rb +50 -56
  51. data/lib/nanoc3/filters.rb +2 -0
  52. data/lib/nanoc3/helpers/blogging.rb +22 -29
  53. data/lib/nanoc3/helpers/breadcrumbs.rb +1 -1
  54. data/lib/nanoc3/helpers/capturing.rb +1 -1
  55. data/lib/nanoc3/helpers/filtering.rb +1 -1
  56. data/lib/nanoc3/helpers/link_to.rb +10 -21
  57. data/lib/nanoc3/helpers/rendering.rb +5 -24
  58. data/lib/nanoc3/helpers/tagging.rb +6 -6
  59. data/lib/nanoc3/helpers/text.rb +2 -2
  60. data/lib/nanoc3.rb +1 -1
  61. metadata +35 -93
  62. data/.gemtest +0 -0
  63. data/doc/yardoc_templates/default/layout/html/footer.erb +0 -10
  64. data/nanoc3.gemspec +0 -41
  65. data/tasks/clean.rake +0 -11
  66. data/tasks/doc.rake +0 -14
  67. data/tasks/gem.rake +0 -13
  68. data/tasks/test.rake +0 -38
  69. data/test/base/core_ext/array_spec.rb +0 -23
  70. data/test/base/core_ext/hash_spec.rb +0 -41
  71. data/test/base/core_ext/string_spec.rb +0 -27
  72. data/test/base/test_code_snippet.rb +0 -33
  73. data/test/base/test_compiler.rb +0 -410
  74. data/test/base/test_compiler_dsl.rb +0 -121
  75. data/test/base/test_context.rb +0 -33
  76. data/test/base/test_data_source.rb +0 -48
  77. data/test/base/test_dependency_tracker.rb +0 -510
  78. data/test/base/test_directed_graph.rb +0 -91
  79. data/test/base/test_filter.rb +0 -85
  80. data/test/base/test_item.rb +0 -141
  81. data/test/base/test_item_rep.rb +0 -953
  82. data/test/base/test_layout.rb +0 -44
  83. data/test/base/test_notification_center.rb +0 -36
  84. data/test/base/test_plugin.rb +0 -32
  85. data/test/base/test_rule.rb +0 -21
  86. data/test/base/test_rule_context.rb +0 -63
  87. data/test/base/test_site.rb +0 -366
  88. data/test/cli/commands/test_compile.rb +0 -12
  89. data/test/cli/commands/test_create_item.rb +0 -12
  90. data/test/cli/commands/test_create_layout.rb +0 -28
  91. data/test/cli/commands/test_create_site.rb +0 -24
  92. data/test/cli/commands/test_help.rb +0 -12
  93. data/test/cli/commands/test_info.rb +0 -12
  94. data/test/cli/commands/test_update.rb +0 -12
  95. data/test/cli/test_logger.rb +0 -12
  96. data/test/data_sources/test_filesystem.rb +0 -420
  97. data/test/data_sources/test_filesystem_unified.rb +0 -538
  98. data/test/data_sources/test_filesystem_verbose.rb +0 -359
  99. data/test/extra/core_ext/test_enumerable.rb +0 -32
  100. data/test/extra/core_ext/test_time.rb +0 -17
  101. data/test/extra/deployers/test_rsync.rb +0 -234
  102. data/test/extra/test_auto_compiler.rb +0 -482
  103. data/test/extra/test_file_proxy.rb +0 -21
  104. data/test/extra/test_vcs.rb +0 -24
  105. data/test/extra/validators/test_links.rb +0 -53
  106. data/test/extra/validators/test_w3c.rb +0 -49
  107. data/test/filters/test_bluecloth.rb +0 -20
  108. data/test/filters/test_coderay.rb +0 -46
  109. data/test/filters/test_colorize_syntax.rb +0 -84
  110. data/test/filters/test_erb.rb +0 -72
  111. data/test/filters/test_erubis.rb +0 -72
  112. data/test/filters/test_haml.rb +0 -98
  113. data/test/filters/test_kramdown.rb +0 -20
  114. data/test/filters/test_less.rb +0 -118
  115. data/test/filters/test_markaby.rb +0 -26
  116. data/test/filters/test_maruku.rb +0 -20
  117. data/test/filters/test_rainpress.rb +0 -31
  118. data/test/filters/test_rdiscount.rb +0 -33
  119. data/test/filters/test_rdoc.rb +0 -18
  120. data/test/filters/test_redcloth.rb +0 -20
  121. data/test/filters/test_relativize_paths.rb +0 -231
  122. data/test/filters/test_rubypants.rb +0 -20
  123. data/test/filters/test_sass.rb +0 -235
  124. data/test/gem_loader.rb +0 -11
  125. data/test/helper.rb +0 -99
  126. data/test/helpers/test_blogging.rb +0 -808
  127. data/test/helpers/test_breadcrumbs.rb +0 -83
  128. data/test/helpers/test_capturing.rb +0 -42
  129. data/test/helpers/test_filtering.rb +0 -108
  130. data/test/helpers/test_html_escape.rb +0 -18
  131. data/test/helpers/test_link_to.rb +0 -251
  132. data/test/helpers/test_rendering.rb +0 -109
  133. data/test/helpers/test_tagging.rb +0 -89
  134. data/test/helpers/test_text.rb +0 -26
  135. data/test/helpers/test_xml_sitemap.rb +0 -69
  136. data/test/tasks/test_clean.rb +0 -71
@@ -1,510 +0,0 @@
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_equal [], tracker.direct_predecessors_of(items[0])
18
- assert_equal [], tracker.direct_predecessors_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_equal [ items[1] ], tracker.direct_predecessors_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_equal [ items[1] ], tracker.direct_predecessors_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_equal [ items[1] ], tracker.direct_predecessors_of(items[0])
64
- end
65
-
66
- def test_direct_predecessors_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_equal [ items[1] ], tracker.direct_predecessors_of(items[0])
79
- end
80
-
81
- def test_predecessors_of
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
- all_dependencies = tracker.predecessors_of(items[0])
94
- assert_equal 2, all_dependencies.size
95
- assert all_dependencies.include?(items[1])
96
- assert all_dependencies.include?(items[2])
97
- end
98
-
99
- def test_direct_successors_of
100
- # Mock items
101
- items = [ mock, mock, mock ]
102
-
103
- # Create
104
- tracker = Nanoc3::DependencyTracker.new(items)
105
-
106
- # Record some dependencies
107
- tracker.record_dependency(items[0], items[1])
108
- tracker.record_dependency(items[1], items[2])
109
-
110
- # Verify dependencies
111
- assert_equal [ items[0] ], tracker.direct_successors_of(items[1])
112
- end
113
-
114
- def test_successors_of
115
- # Mock items
116
- items = [ mock, mock, mock ]
117
-
118
- # Create
119
- tracker = Nanoc3::DependencyTracker.new(items)
120
-
121
- # Record some dependencies
122
- tracker.record_dependency(items[0], items[1])
123
- tracker.record_dependency(items[1], items[2])
124
-
125
- # Verify dependencies
126
- all_dependencies = tracker.successors_of(items[2])
127
- assert_equal 2, all_dependencies.size
128
- assert all_dependencies.include?(items[0])
129
- assert all_dependencies.include?(items[1])
130
- end
131
-
132
- def test_start_and_stop
133
- # Mock items
134
- items = [ mock, mock ]
135
-
136
- # Create
137
- tracker = Nanoc3::DependencyTracker.new(items)
138
-
139
- # Start, do something and stop
140
- tracker.start
141
- Nanoc3::NotificationCenter.post(:visit_started, items[0])
142
- Nanoc3::NotificationCenter.post(:visit_started, items[1])
143
- Nanoc3::NotificationCenter.post(:visit_ended, items[1])
144
- Nanoc3::NotificationCenter.post(:visit_ended, items[0])
145
- tracker.stop
146
-
147
- # Verify dependencies
148
- assert_equal [ items[1] ], tracker.direct_predecessors_of(items[0])
149
- assert_equal [], tracker.direct_predecessors_of(items[1])
150
- end
151
-
152
- def test_store_graph_and_load_graph_simple
153
- # Mock items
154
- items = [ mock, mock, mock, mock ]
155
- items[0].stubs(:identifier).returns('/aaa/')
156
- items[1].stubs(:identifier).returns('/bbb/')
157
- items[2].stubs(:identifier).returns('/ccc/')
158
- items[3].stubs(:identifier).returns('/ddd/')
159
-
160
- # Create
161
- tracker = Nanoc3::DependencyTracker.new(items)
162
-
163
- # Record some dependencies
164
- tracker.record_dependency(items[0], items[1])
165
- tracker.record_dependency(items[1], items[2])
166
- tracker.record_dependency(items[1], items[3])
167
-
168
- # Store
169
- tracker.store_graph
170
- assert File.file?(tracker.filename)
171
-
172
- # Re-create
173
- tracker = Nanoc3::DependencyTracker.new(items)
174
-
175
- # Load
176
- tracker.load_graph
177
-
178
- # Check loaded graph
179
- assert_equal Set.new([ items[1] ]), Set.new(tracker.direct_predecessors_of(items[0]))
180
- assert_equal Set.new([ items[2], items[3] ]), Set.new(tracker.direct_predecessors_of(items[1]))
181
- assert_equal Set.new([]), Set.new(tracker.direct_predecessors_of(items[2]))
182
- assert_equal Set.new([]), Set.new(tracker.direct_predecessors_of(items[3]))
183
- end
184
-
185
- def test_store_graph_with_custom_filename
186
- # Mock items
187
- items = [ mock, mock, mock, mock ]
188
- items[0].stubs(:identifier).returns('/aaa/')
189
- items[1].stubs(:identifier).returns('/bbb/')
190
- items[2].stubs(:identifier).returns('/ccc/')
191
- items[3].stubs(:identifier).returns('/ddd/')
192
-
193
- # Create
194
- tracker = Nanoc3::DependencyTracker.new(items)
195
- tracker.filename = 'tmp/bob/iguana/bits'
196
-
197
- # Record some dependencies
198
- tracker.record_dependency(items[0], items[1])
199
- tracker.record_dependency(items[1], items[2])
200
- tracker.record_dependency(items[1], items[3])
201
-
202
- # Store
203
- tracker.store_graph
204
- assert File.file?(tracker.filename)
205
- assert File.file?('tmp/bob/iguana/bits')
206
- end
207
-
208
- def test_store_graph_and_load_graph_with_removed_items
209
- # Mock items
210
- items = [ mock, mock, mock, mock ]
211
- items[0].stubs(:identifier).returns('/aaa/')
212
- items[1].stubs(:identifier).returns('/bbb/')
213
- items[2].stubs(:identifier).returns('/ccc/')
214
- items[3].stubs(:identifier).returns('/ddd/')
215
-
216
- # Create new and old lists
217
- old_items = [ items[0], items[1], items[2], items[3] ]
218
- new_items = [ items[0], items[1], items[2] ]
219
-
220
- # Create
221
- tracker = Nanoc3::DependencyTracker.new(old_items)
222
-
223
- # Record some dependencies
224
- tracker.record_dependency(old_items[0], old_items[1])
225
- tracker.record_dependency(old_items[1], old_items[2])
226
- tracker.record_dependency(old_items[1], old_items[3])
227
-
228
- # Store
229
- tracker.store_graph
230
- assert File.file?(tracker.filename)
231
-
232
- # Re-create
233
- tracker = Nanoc3::DependencyTracker.new(new_items)
234
-
235
- # Load
236
- tracker.load_graph
237
-
238
- # Check loaded graph
239
- assert_equal [ items[1] ], tracker.direct_predecessors_of(items[0])
240
- assert_equal [ items[2] ], tracker.direct_predecessors_of(items[1])
241
- assert_equal [], tracker.direct_predecessors_of(items[2])
242
- end
243
-
244
- def test_store_graph_with_nils_in_dst
245
- # Mock items
246
- items = [ mock, mock, mock ]
247
- items[0].stubs(:identifier).returns('/aaa/')
248
- items[1].stubs(:identifier).returns('/bbb/')
249
- items[2].stubs(:identifier).returns('/ccc/')
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], nil)
257
-
258
- # Store
259
- tracker.store_graph
260
- assert File.file?(tracker.filename)
261
-
262
- # Re-create
263
- tracker = Nanoc3::DependencyTracker.new(items)
264
-
265
- # Load
266
- tracker.load_graph
267
-
268
- # Check loaded graph
269
- assert_equal [ items[1] ], tracker.direct_predecessors_of(items[0])
270
- assert_equal [ ], tracker.direct_predecessors_of(items[1])
271
- end
272
-
273
- def test_store_graph_with_nils_in_src
274
- # Mock items
275
- items = [ mock, mock, mock ]
276
- items[0].stubs(:identifier).returns('/aaa/')
277
- items[1].stubs(:identifier).returns('/bbb/')
278
- items[2].stubs(:identifier).returns('/ccc/')
279
-
280
- # Create
281
- tracker = Nanoc3::DependencyTracker.new(items)
282
-
283
- # Record some dependencies
284
- tracker.record_dependency(items[0], items[1])
285
- tracker.record_dependency(nil, items[2])
286
-
287
- # Store
288
- tracker.store_graph
289
- assert File.file?(tracker.filename)
290
-
291
- # Re-create
292
- tracker = Nanoc3::DependencyTracker.new(items)
293
-
294
- # Load
295
- tracker.load_graph
296
-
297
- # Check loaded graph
298
- assert_equal [ items[1] ], tracker.direct_predecessors_of(items[0])
299
- assert_equal [ ], tracker.direct_predecessors_of(items[1])
300
- end
301
-
302
- def test_load_graph_without_file
303
- # Mock items
304
- item_0 = Object.new
305
- def item_0.outdated? ; false ; end
306
- def item_0.outdated_due_to_dependencies? ; @outdated_due_to_dependencies ; end
307
- def item_0.outdated_due_to_dependencies=(b) ; @outdated_due_to_dependencies = b ; end
308
- item_1 = Object.new
309
- def item_1.outdated? ; true ; end
310
- def item_1.outdated_due_to_dependencies? ; @outdated_due_to_dependencies ; end
311
- def item_1.outdated_due_to_dependencies=(b) ; @outdated_due_to_dependencies = b ; end
312
- items = [ item_0, item_1 ]
313
-
314
- # Create
315
- tracker = Nanoc3::DependencyTracker.new([ item_0, item_1 ])
316
-
317
- # Load
318
- tracker.load_graph
319
- graph = tracker.instance_eval { @graph }
320
-
321
- # Check
322
- refute tracker.nil?
323
- refute graph.nil?
324
- assert_equal [ nil ] + items, graph.vertices
325
- assert_equal [], tracker.direct_predecessors_of(items[0])
326
- assert_equal [], tracker.direct_predecessors_of(items[1])
327
-
328
- # Mark as outdated
329
- tracker.propagate_outdatedness
330
-
331
- # Check outdatedness
332
- assert item_0.outdated_due_to_dependencies?
333
- assert item_1.outdated_due_to_dependencies?
334
- end
335
-
336
- def test_item_with_identifier
337
- # Mock items
338
- items = [ mock, mock, mock, mock ]
339
- items[0].stubs(:identifier).returns('/aaa/')
340
- items[1].stubs(:identifier).returns('/bbb/')
341
- items[2].stubs(:identifier).returns('/ccc/')
342
- items[3].stubs(:identifier).returns('/ddd/')
343
-
344
- # Create
345
- tracker = Nanoc3::DependencyTracker.new(items)
346
-
347
- # Test
348
- assert_equal items[0], tracker.send(:item_with_identifier, '/aaa/')
349
- assert_equal items[1], tracker.send(:item_with_identifier, '/bbb/')
350
- assert_equal items[2], tracker.send(:item_with_identifier, '/ccc/')
351
- assert_equal items[3], tracker.send(:item_with_identifier, '/ddd/')
352
- assert_equal nil, tracker.send(:item_with_identifier, '/123/')
353
- end
354
-
355
- def test_propagate_outdatedness_simple
356
- # Mock items
357
- item_0 = Object.new
358
- def item_0.outdated? ; false ; end
359
- def item_0.outdated_due_to_dependencies? ; @outdated_due_to_dependencies ; end
360
- def item_0.outdated_due_to_dependencies=(b) ; @outdated_due_to_dependencies = b ; end
361
- item_1 = Object.new
362
- def item_1.outdated? ; true ; end
363
- def item_1.outdated_due_to_dependencies? ; @outdated_due_to_dependencies ; end
364
- def item_1.outdated_due_to_dependencies=(b) ; @outdated_due_to_dependencies = b ; end
365
- items = [ item_0, item_1 ]
366
-
367
- # Create
368
- tracker = Nanoc3::DependencyTracker.new(items)
369
- tracker.instance_eval { @previous_items = items }
370
-
371
- # Record some dependencies
372
- tracker.record_dependency(items[0], items[1])
373
-
374
- # Mark as outdated
375
- tracker.propagate_outdatedness
376
-
377
- # Check outdatedness
378
- assert !items[0].outdated?
379
- assert items[0].outdated_due_to_dependencies?
380
- assert items[1].outdated?
381
- assert !items[1].outdated_due_to_dependencies?
382
- end
383
-
384
- def test_propagate_outdatedness_chained
385
- # Mock items
386
- item_0 = Object.new
387
- def item_0.outdated? ; false ; end
388
- def item_0.outdated_due_to_dependencies? ; @outdated_due_to_dependencies ; end
389
- def item_0.outdated_due_to_dependencies=(b) ; @outdated_due_to_dependencies = b ; end
390
- item_1 = Object.new
391
- def item_1.outdated? ; false ; end
392
- def item_1.outdated_due_to_dependencies? ; @outdated_due_to_dependencies ; end
393
- def item_1.outdated_due_to_dependencies=(b) ; @outdated_due_to_dependencies = b ; end
394
- item_2 = Object.new
395
- def item_2.outdated? ; true ; end
396
- def item_2.outdated_due_to_dependencies? ; @outdated_due_to_dependencies ; end
397
- def item_2.outdated_due_to_dependencies=(b) ; @outdated_due_to_dependencies = b ; end
398
- items = [ item_0, item_1, item_2 ]
399
-
400
- # Create
401
- tracker = Nanoc3::DependencyTracker.new(items)
402
- tracker.instance_eval { @previous_items = items }
403
-
404
- # Record some dependencies
405
- tracker.record_dependency(items[0], items[1])
406
- tracker.record_dependency(items[1], items[2])
407
-
408
- # Mark as outdated
409
- tracker.propagate_outdatedness
410
-
411
- # Check outdatedness
412
- assert !items[0].outdated?
413
- assert items[0].outdated_due_to_dependencies?
414
- assert !items[1].outdated?
415
- assert items[1].outdated_due_to_dependencies?
416
- assert items[2].outdated?
417
- assert !items[2].outdated_due_to_dependencies?
418
- end
419
-
420
- def test_propagate_outdatedness_with_removed_items_forward
421
- # A removed item (nil) that appears as a value marks all dependent items as outdated.
422
-
423
- # Mock items
424
- item = Object.new
425
- def item.outdated? ; false ; end
426
- def item.outdated_due_to_dependencies? ; @outdated_due_to_dependencies ; end
427
- def item.outdated_due_to_dependencies=(b) ; @outdated_due_to_dependencies = b ; end
428
-
429
- # Create
430
- tracker = Nanoc3::DependencyTracker.new([ item ])
431
- tracker.instance_eval { @previous_items = [ item ] }
432
-
433
- # Record some dependencies
434
- tracker.record_dependency(item, nil)
435
-
436
- # Mark as outdated
437
- tracker.propagate_outdatedness
438
-
439
- # Check outdatedness
440
- assert !item.outdated?
441
- assert item.outdated_due_to_dependencies?
442
- end
443
-
444
- def test_propagate_outdatedness_with_removed_items_backward
445
- # A removed item (nil) that appears as a key can be ignored safely.
446
-
447
- # Mock items
448
- item = Object.new
449
- def item.outdated? ; true ; end
450
- def item.outdated_due_to_dependencies? ; @outdated_due_to_dependencies ; end
451
- def item.outdated_due_to_dependencies=(b) ; @outdated_due_to_dependencies = b ; end
452
-
453
- # Create
454
- tracker = Nanoc3::DependencyTracker.new([ item ])
455
- tracker.instance_eval { @previous_items = [ item ] }
456
-
457
- # Record some dependencies
458
- tracker.record_dependency(nil, item)
459
-
460
- # Mark as outdated
461
- tracker.propagate_outdatedness
462
-
463
- # Check outdatedness
464
- assert item.outdated?
465
- assert !item.outdated_due_to_dependencies?
466
- end
467
-
468
- def test_propagate_outdatedness_with_added_items
469
- # An added item (with no entry in the dependency graph) depends on all other items.
470
-
471
- # Mock items
472
- item_0 = Object.new
473
- def item_0.outdated? ; false ; end
474
- def item_0.outdated_due_to_dependencies? ; @outdated_due_to_dependencies ; end
475
- def item_0.outdated_due_to_dependencies=(b) ; @outdated_due_to_dependencies = b ; end
476
- item_1 = Object.new
477
- def item_1.outdated? ; false ; end
478
- def item_1.outdated_due_to_dependencies? ; @outdated_due_to_dependencies ; end
479
- def item_1.outdated_due_to_dependencies=(b) ; @outdated_due_to_dependencies = b ; end
480
-
481
- # Create
482
- tracker = Nanoc3::DependencyTracker.new([ item_0, item_1 ])
483
- tracker.instance_eval { @previous_items = [ item_0 ] }
484
-
485
- # Mark as outdated
486
- tracker.propagate_outdatedness
487
-
488
- # Check outdatedness
489
- assert !item_0.outdated_due_to_dependencies?
490
- assert item_1.outdated_due_to_dependencies?
491
- end
492
-
493
- def test_forget_dependencies_for
494
- # Mock items
495
- items = [ mock, mock, mock ]
496
-
497
- # Create
498
- tracker = Nanoc3::DependencyTracker.new(items)
499
-
500
- # Record some dependencies
501
- tracker.record_dependency(items[0], items[1])
502
- tracker.record_dependency(items[1], items[2])
503
- assert_equal [ items[1] ], tracker.direct_predecessors_of(items[0])
504
-
505
- # Forget dependencies
506
- tracker.forget_dependencies_for(items[0])
507
- assert_equal [], tracker.direct_predecessors_of(items[0])
508
- end
509
-
510
- end
@@ -1,91 +0,0 @@
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_add_edge
58
- graph = Nanoc3::DirectedGraph.new([ 1, 2, 3 ])
59
-
60
- assert_equal [], graph.successors_of(1)
61
- assert_equal [], graph.predecessors_of(2)
62
-
63
- graph.add_edge(1, 2)
64
-
65
- assert_equal [ 2 ], graph.successors_of(1)
66
- assert_equal [ 1 ], graph.predecessors_of(2)
67
- end
68
-
69
- def test_remove_edge
70
- graph = Nanoc3::DirectedGraph.new([ 1, 2, 3 ])
71
- graph.add_edge(1,2)
72
-
73
- assert_equal [ 2 ], graph.successors_of(1)
74
- assert_equal [ 1 ], graph.predecessors_of(2)
75
-
76
- graph.remove_edge(1, 2)
77
-
78
- assert_equal [], graph.successors_of(1)
79
- assert_equal [], graph.predecessors_of(2)
80
- end
81
-
82
- def test_should_return_empty_array_for_nonexistant_vertices
83
- graph = Nanoc3::DirectedGraph.new([ 1, 2, 3 ])
84
-
85
- assert_equal [], graph.direct_predecessors_of(4)
86
- assert_equal [], graph.predecessors_of(4)
87
- assert_equal [], graph.direct_successors_of(4)
88
- assert_equal [], graph.successors_of(4)
89
- end
90
-
91
- end
@@ -1,85 +0,0 @@
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