nanoc3 3.1.7 → 3.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/.gemtest +0 -0
  2. data/LICENSE +1 -1
  3. data/NEWS.md +9 -0
  4. data/doc/yardoc_templates/default/layout/html/footer.erb +10 -0
  5. data/lib/nanoc3/base/item.rb +1 -1
  6. data/lib/nanoc3/base/item_rep.rb +1 -0
  7. data/lib/nanoc3/base/layout.rb +1 -1
  8. data/lib/nanoc3/cli/base.rb +4 -2
  9. data/lib/nanoc3/cli/commands/view.rb +1 -0
  10. data/lib/nanoc3/data_sources/filesystem.rb +25 -6
  11. data/lib/nanoc3/data_sources/filesystem_unified.rb +5 -5
  12. data/lib/nanoc3/extra/validators/links.rb +1 -1
  13. data/lib/nanoc3/filters/rdiscount.rb +2 -1
  14. data/lib/nanoc3/filters/sass.rb +20 -8
  15. data/lib/nanoc3/filters/sass.rb.orig +75 -0
  16. data/lib/nanoc3.rb +1 -1
  17. data/nanoc3.gemspec +41 -0
  18. data/tasks/clean.rake +11 -0
  19. data/tasks/doc.rake +14 -0
  20. data/tasks/gem.rake +13 -0
  21. data/tasks/test.rake +38 -0
  22. data/test/base/core_ext/array_spec.rb +23 -0
  23. data/test/base/core_ext/hash_spec.rb +41 -0
  24. data/test/base/core_ext/string_spec.rb +27 -0
  25. data/test/base/test_code_snippet.rb +33 -0
  26. data/test/base/test_compiler.rb +410 -0
  27. data/test/base/test_compiler_dsl.rb +121 -0
  28. data/test/base/test_context.rb +33 -0
  29. data/test/base/test_data_source.rb +48 -0
  30. data/test/base/test_dependency_tracker.rb +510 -0
  31. data/test/base/test_directed_graph.rb +91 -0
  32. data/test/base/test_filter.rb +85 -0
  33. data/test/base/test_item.rb +141 -0
  34. data/test/base/test_item_rep.rb +953 -0
  35. data/test/base/test_layout.rb +44 -0
  36. data/test/base/test_notification_center.rb +36 -0
  37. data/test/base/test_plugin.rb +32 -0
  38. data/test/base/test_rule.rb +21 -0
  39. data/test/base/test_rule_context.rb +63 -0
  40. data/test/base/test_site.rb +366 -0
  41. data/test/cli/commands/test_compile.rb +12 -0
  42. data/test/cli/commands/test_create_item.rb +12 -0
  43. data/test/cli/commands/test_create_layout.rb +28 -0
  44. data/test/cli/commands/test_create_site.rb +24 -0
  45. data/test/cli/commands/test_help.rb +12 -0
  46. data/test/cli/commands/test_info.rb +12 -0
  47. data/test/cli/commands/test_update.rb +12 -0
  48. data/test/cli/test_logger.rb +12 -0
  49. data/test/data_sources/test_filesystem.rb +420 -0
  50. data/test/data_sources/test_filesystem_unified.rb +538 -0
  51. data/test/data_sources/test_filesystem_verbose.rb +359 -0
  52. data/test/extra/core_ext/test_enumerable.rb +32 -0
  53. data/test/extra/core_ext/test_time.rb +17 -0
  54. data/test/extra/deployers/test_rsync.rb +234 -0
  55. data/test/extra/test_auto_compiler.rb +482 -0
  56. data/test/extra/test_file_proxy.rb +21 -0
  57. data/test/extra/test_vcs.rb +24 -0
  58. data/test/extra/validators/test_links.rb +53 -0
  59. data/test/extra/validators/test_w3c.rb +49 -0
  60. data/test/filters/test_bluecloth.rb +20 -0
  61. data/test/filters/test_coderay.rb +46 -0
  62. data/test/filters/test_colorize_syntax.rb +56 -0
  63. data/test/filters/test_erb.rb +72 -0
  64. data/test/filters/test_erubis.rb +72 -0
  65. data/test/filters/test_haml.rb +98 -0
  66. data/test/filters/test_kramdown.rb +20 -0
  67. data/test/filters/test_less.rb +59 -0
  68. data/test/filters/test_markaby.rb +26 -0
  69. data/test/filters/test_maruku.rb +20 -0
  70. data/test/filters/test_rainpress.rb +31 -0
  71. data/test/filters/test_rdiscount.rb +33 -0
  72. data/test/filters/test_rdoc.rb +18 -0
  73. data/test/filters/test_redcloth.rb +20 -0
  74. data/test/filters/test_relativize_paths.rb +231 -0
  75. data/test/filters/test_rubypants.rb +20 -0
  76. data/test/filters/test_sass.rb +170 -0
  77. data/test/filters/test_sass.rb.orig +103 -0
  78. data/test/gem_loader.rb +11 -0
  79. data/test/helper.rb +99 -0
  80. data/test/helpers/test_blogging.rb +808 -0
  81. data/test/helpers/test_breadcrumbs.rb +83 -0
  82. data/test/helpers/test_capturing.rb +42 -0
  83. data/test/helpers/test_filtering.rb +108 -0
  84. data/test/helpers/test_html_escape.rb +18 -0
  85. data/test/helpers/test_link_to.rb +251 -0
  86. data/test/helpers/test_rendering.rb +109 -0
  87. data/test/helpers/test_tagging.rb +89 -0
  88. data/test/helpers/test_text.rb +26 -0
  89. data/test/helpers/test_xml_sitemap.rb +69 -0
  90. data/test/tasks/test_clean.rb +71 -0
  91. metadata +83 -8
@@ -0,0 +1,510 @@
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
@@ -0,0 +1,91 @@
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
@@ -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