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,410 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::CompilerTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_run_without_item
10
+ # Mock items
11
+ items = [ mock('Nanoc3::Item 1'), mock('Nanoc3::Item 2') ]
12
+ items[0]
13
+ items[1]
14
+
15
+ # Mock reps
16
+ items[0].stubs(:reps).returns([ mock('Nanoc3::ItemRep 1.1') ])
17
+ items[1].stubs(:reps).returns([ mock('Nanoc3::ItemRep 2.1'), mock('Nanoc3::ItemRep 2.2') ])
18
+ reps = items[0].reps + items[1].reps
19
+ reps.each { |r| r.quacks_like(Object.new) }
20
+
21
+ # Mock site
22
+ site = mock
23
+ site.stubs(:config).returns({ :output_dir => 'foo/bar/baz' })
24
+ site.stubs(:items).returns(items)
25
+
26
+ # Create compiler
27
+ compiler = Nanoc3::Compiler.new(site)
28
+ compiler.expects(:compile_reps).with(reps)
29
+ compiler.expects(:forget_dependencies_if_outdated).with(items)
30
+
31
+ # Mock dependency tracker
32
+ dependency_tracker = mock('Nanoc3::DependencyTracker')
33
+ dependency_tracker.expects(:load_graph)
34
+ dependency_tracker.expects(:store_graph)
35
+ dependency_tracker.expects(:start)
36
+ dependency_tracker.expects(:stop)
37
+ dependency_tracker.expects(:propagate_outdatedness)
38
+ compiler.stubs(:dependency_tracker).returns(dependency_tracker)
39
+
40
+ # Run
41
+ compiler.run
42
+
43
+ # Make sure output dir is created
44
+ assert(File.directory?('foo/bar/baz'))
45
+ end
46
+
47
+ def test_run_with_item
48
+ # Mock items
49
+ item = mock
50
+ other_items = [ mock, mock ]
51
+
52
+ # Mock reps
53
+ item.stubs(:reps).returns([ mock, mock, mock ])
54
+ other_items.each { |i| i.stubs(:reps).returns([ mock ]) }
55
+ reps = item.reps + other_items[0].reps
56
+ reps.each { |r| r.quacks_like(Object.new) }
57
+
58
+ # Mock site
59
+ site = mock
60
+ site.expects(:config).returns({ :output_dir => 'foo/bar/baz' })
61
+
62
+ # Create compiler
63
+ compiler = Nanoc3::Compiler.new(site)
64
+ compiler.expects(:compile_reps).with(reps)
65
+ compiler.expects(:forget_dependencies_if_outdated).with([ item, other_items[0] ])
66
+
67
+ # Mock dependency tracker
68
+ dependency_tracker = mock
69
+ dependency_tracker.expects(:load_graph)
70
+ dependency_tracker.expects(:store_graph)
71
+ dependency_tracker.expects(:start)
72
+ dependency_tracker.expects(:stop)
73
+ dependency_tracker.expects(:propagate_outdatedness)
74
+ dependency_tracker.expects(:successors_of).with(item).returns([ other_items[0] ])
75
+ compiler.stubs(:dependency_tracker).returns(dependency_tracker)
76
+
77
+ # Run
78
+ compiler.run(item)
79
+
80
+ # Make sure output dir is created
81
+ assert(File.directory?('foo/bar/baz'))
82
+ end
83
+
84
+ def test_run_with_force
85
+ # Mock items
86
+ items = [
87
+ Nanoc3::Item.new('content 0', {}, '/item0/'),
88
+ Nanoc3::Item.new('content 1', {}, '/item1/')
89
+ ]
90
+
91
+ # Mock reps
92
+ items[0].reps << Nanoc3::ItemRep.new(items[0], :rep00)
93
+ items[1].reps << Nanoc3::ItemRep.new(items[1], :rep10)
94
+ items[1].reps << Nanoc3::ItemRep.new(items[1], :rep11)
95
+ reps = items[0].reps + items[1].reps
96
+ reps.each { |r| r.expects(:force_outdated=).with(true) }
97
+
98
+ # Mock site
99
+ site = mock
100
+ site.stubs(:config).returns({ :output_dir => 'foo/bar/baz' })
101
+ site.stubs(:items).returns(items)
102
+
103
+ # Create compiler
104
+ compiler = Nanoc3::Compiler.new(site)
105
+ compiler.expects(:compile_reps).with(reps)
106
+ compiler.expects(:forget_dependencies_if_outdated).with(items)
107
+
108
+ # Mock dependency tracker
109
+ dependency_tracker = mock
110
+ dependency_tracker.expects(:load_graph)
111
+ dependency_tracker.expects(:store_graph)
112
+ dependency_tracker.expects(:start)
113
+ dependency_tracker.expects(:stop)
114
+ compiler.stubs(:dependency_tracker).returns(dependency_tracker)
115
+
116
+ # Run
117
+ compiler.run(nil, :force => true)
118
+
119
+ # Make sure output dir is created
120
+ assert(File.directory?('foo/bar/baz'))
121
+ end
122
+
123
+ def test_compilation_rule_for
124
+ # Mock rules
125
+ rules = [ mock, mock, mock ]
126
+ rules[0].expects(:applicable_to?).returns(false)
127
+ rules[1].expects(:applicable_to?).returns(true)
128
+ rules[1].expects(:rep_name).returns('wrong')
129
+ rules[2].expects(:applicable_to?).returns(true)
130
+ rules[2].expects(:rep_name).returns('right')
131
+
132
+ # Create compiler
133
+ compiler = Nanoc3::Compiler.new(nil)
134
+ compiler.instance_eval { @item_compilation_rules = rules }
135
+
136
+ # Mock rep
137
+ rep = mock
138
+ rep.stubs(:name).returns('right')
139
+ item = mock
140
+ rep.stubs(:item).returns(item)
141
+
142
+ # Test
143
+ assert_equal rules[2], compiler.compilation_rule_for(rep)
144
+ end
145
+
146
+ def test_routing_rule_for
147
+ # Mock rules
148
+ rules = [ mock, mock, mock ]
149
+ rules[0].expects(:applicable_to?).returns(false)
150
+ rules[1].expects(:applicable_to?).returns(true)
151
+ rules[1].expects(:rep_name).returns('wrong')
152
+ rules[2].expects(:applicable_to?).returns(true)
153
+ rules[2].expects(:rep_name).returns('right')
154
+
155
+ # Create compiler
156
+ compiler = Nanoc3::Compiler.new(nil)
157
+ compiler.instance_eval { @item_routing_rules = rules }
158
+
159
+ # Mock rep
160
+ rep = mock
161
+ rep.stubs(:name).returns('right')
162
+ item = mock
163
+ rep.stubs(:item).returns(item)
164
+
165
+ # Test
166
+ assert_equal rules[2], compiler.routing_rule_for(rep)
167
+ end
168
+
169
+ def test_filter_for_layout_with_existant_layout
170
+ # Mock site
171
+ site = mock
172
+
173
+ # Create compiler
174
+ compiler = Nanoc3::Compiler.new(site)
175
+ compiler.layout_filter_mapping[/.*/] = [ :erb, { :foo => 'bar' } ]
176
+
177
+ # Mock layout
178
+ layout = MiniTest::Mock.new
179
+ layout.expect(:identifier, '/some_layout/')
180
+
181
+ # Check
182
+ assert_equal([ :erb, { :foo => 'bar' } ], compiler.filter_for_layout(layout))
183
+ end
184
+
185
+ def test_filter_for_layout_with_existant_layout_and_unknown_filter
186
+ # Mock site
187
+ site = mock
188
+
189
+ # Create compiler
190
+ compiler = Nanoc3::Compiler.new(site)
191
+ compiler.layout_filter_mapping[/.*/] = [ :some_unknown_filter, { :foo => 'bar' } ]
192
+
193
+ # Mock layout
194
+ layout = MiniTest::Mock.new
195
+ layout.expect(:identifier, '/some_layout/')
196
+
197
+ # Check
198
+ assert_equal([ :some_unknown_filter, { :foo => 'bar' } ], compiler.filter_for_layout(layout))
199
+ end
200
+
201
+ def test_filter_for_layout_with_nonexistant_layout
202
+ # Mock site
203
+ site = mock
204
+
205
+ # Create compiler
206
+ compiler = Nanoc3::Compiler.new(site)
207
+ compiler.layout_filter_mapping[%r{^/foo/$}] = [ :erb, { :foo => 'bar' } ]
208
+
209
+ # Mock layout
210
+ layout = MiniTest::Mock.new
211
+ layout.expect(:identifier, '/bar/')
212
+
213
+ # Check
214
+ assert_equal(nil, compiler.filter_for_layout(layout))
215
+ end
216
+
217
+ def test_filter_for_layout_with_many_layouts
218
+ # Mock site
219
+ site = mock
220
+
221
+ # Create compiler
222
+ compiler = Nanoc3::Compiler.new(site)
223
+ compiler.layout_filter_mapping[%r{^/a/b/c/.*/$}] = [ :erb, { :char => 'd' } ]
224
+ compiler.layout_filter_mapping[%r{^/a/.*/$}] = [ :erb, { :char => 'b' } ]
225
+ compiler.layout_filter_mapping[%r{^/a/b/.*/$}] = [ :erb, { :char => 'c' } ] # never used!
226
+ compiler.layout_filter_mapping[%r{^/.*/$}] = [ :erb, { :char => 'a' } ]
227
+
228
+ # Mock layout
229
+ layouts = [ mock, mock, mock, mock ]
230
+ layouts[0].stubs(:identifier).returns('/a/b/c/d/')
231
+ layouts[1].stubs(:identifier).returns('/a/b/c/')
232
+ layouts[2].stubs(:identifier).returns('/a/b/')
233
+ layouts[3].stubs(:identifier).returns('/a/')
234
+
235
+ # Get expectations
236
+ expectations = {
237
+ 0 => 'd',
238
+ 1 => 'b', # never used! not c, because b takes priority
239
+ 2 => 'b',
240
+ 3 => 'a'
241
+ }
242
+
243
+ # Check
244
+ expectations.each_pair do |num, char|
245
+ filter_and_args = compiler.filter_for_layout(layouts[num])
246
+ refute_nil(filter_and_args)
247
+ assert_equal(char, filter_and_args[1][:char])
248
+ end
249
+ end
250
+
251
+ def test_compile_rep
252
+ # Mock rep
253
+ item = mock
254
+ rep = mock
255
+ rep.expects(:compiled=).with(true)
256
+ rep.expects(:raw_path).returns('output/foo.html')
257
+ rep.expects(:write)
258
+ rep.stubs(:item).returns(item)
259
+
260
+ # Create compiler
261
+ compiler = Nanoc3::Compiler.new(nil)
262
+ compilation_rule = mock
263
+ compilation_rule.expects(:apply_to).with(rep)
264
+ compiler.expects(:compilation_rule_for).returns(compilation_rule)
265
+
266
+ # Compile
267
+ compiler.send :compile_rep, rep
268
+ end
269
+
270
+ def test_compile_reps_with_no_reps
271
+ # Create compiler
272
+ compiler = Nanoc3::Compiler.new(nil)
273
+ compiler.expects(:compile_rep).never
274
+
275
+ # Compile
276
+ compiler.send :compile_reps, []
277
+ end
278
+
279
+ def test_compile_reps_with_one_rep
280
+ # Mock rep
281
+ rep = mock
282
+ rep.expects(:outdated?).returns(true)
283
+
284
+ # Create compiler
285
+ compiler = Nanoc3::Compiler.new(nil)
286
+ compiler.expects(:compile_rep).with(rep)
287
+
288
+ # Compile
289
+ compiler.send :compile_reps, [ rep ]
290
+ end
291
+
292
+ def test_compile_reps_with_two_independent_reps
293
+ # Mock reps
294
+ reps = [ mock, mock ]
295
+ reps[0].expects(:outdated?).returns(true)
296
+ reps[1].expects(:outdated?).returns(true)
297
+
298
+ # Create compiler
299
+ compiler = Nanoc3::Compiler.new(nil)
300
+ compiler.expects(:compile_rep).times(2)
301
+
302
+ # Compile
303
+ compiler.send :compile_reps, reps
304
+
305
+ # Check size of reps array
306
+ assert_equal 2, reps.size
307
+ end
308
+
309
+ def test_compile_reps_with_two_dependent_reps
310
+ # Mock items
311
+ items = [ mock, mock ]
312
+ items[1].expects(:identifier).returns('/foo/bar/')
313
+
314
+ # Mock reps
315
+ reps = [ mock, mock ]
316
+ reps[0].expects(:outdated?).returns(true)
317
+ reps[0].expects(:forget_progress)
318
+ reps[1].expects(:item).returns(items[1])
319
+ reps[1].expects(:name).returns('somerepname')
320
+ reps[1].expects(:outdated?).returns(true)
321
+
322
+ # Create compiler
323
+ compiler = Nanoc3::Compiler.new(nil)
324
+ compiler.instance_eval { @_reps = reps }
325
+ def compiler.compile_rep(rep)
326
+ @_invocation_id ||= 0
327
+ @_called_reps ||= []
328
+
329
+ case @_invocation_id
330
+ when 0
331
+ @_invocation_id = 1
332
+ @_called_reps[0] = rep
333
+ raise Nanoc3::Errors::UnmetDependency.new(@_reps[1])
334
+ when 1
335
+ @_invocation_id = 2
336
+ @_called_reps[1] = rep
337
+ when 2
338
+ @_invocation_id = 3
339
+ @_called_reps[2] = rep
340
+ end
341
+ end
342
+
343
+ # Compile
344
+ compiler.send :compile_reps, reps
345
+
346
+ # Check
347
+ assert_equal reps[0], compiler.instance_eval { @_called_reps[0] }
348
+ assert_equal reps[1], compiler.instance_eval { @_called_reps[1] }
349
+ assert_equal reps[0], compiler.instance_eval { @_called_reps[2] }
350
+ end
351
+
352
+ def test_compile_reps_with_two_mutually_dependent_reps
353
+ # Mock items
354
+ items = [ mock, mock ]
355
+ items[0].expects(:identifier).returns('/first/')
356
+ items[1].expects(:identifier).returns('/second/')
357
+
358
+ # Mock reps
359
+ reps = [ mock, mock ]
360
+ reps[0].expects(:item).returns(items[0])
361
+ reps[0].expects(:name).returns('firstrep')
362
+ reps[0].expects(:outdated?).returns(true)
363
+ reps[0].expects(:forget_progress)
364
+ reps[1].expects(:item).returns(items[1])
365
+ reps[1].expects(:name).returns('secondrep')
366
+ reps[1].expects(:outdated?).returns(true)
367
+ reps[1].expects(:forget_progress)
368
+
369
+ # Create compiler
370
+ compiler = Nanoc3::Compiler.new(nil)
371
+ compiler.instance_eval { @_reps = reps }
372
+ def compiler.compile_rep(rep)
373
+ if rep == @_reps[0]
374
+ raise Nanoc3::Errors::UnmetDependency.new(@_reps[1])
375
+ elsif rep == @_reps[1]
376
+ raise Nanoc3::Errors::UnmetDependency.new(@_reps[0])
377
+ else
378
+ raise RuntimeError.new("this shouldn't have happened")
379
+ end
380
+ end
381
+
382
+ # Compile
383
+ assert_raises Nanoc3::Errors::RecursiveCompilation do
384
+ compiler.send :compile_reps, reps
385
+ end
386
+ end
387
+
388
+ def test_forget_dependencies_if_outdated
389
+ # Mock items
390
+ items = [ mock, mock, mock, mock ]
391
+ items[0].stubs(:outdated?).returns(false)
392
+ items[0].stubs(:outdated_due_to_dependencies?).returns(false)
393
+ items[1].stubs(:outdated?).returns(true)
394
+ items[1].stubs(:outdated_due_to_dependencies?).returns(false)
395
+ items[2].stubs(:outdated?).returns(false)
396
+ items[2].stubs(:outdated_due_to_dependencies?).returns(true)
397
+ items[3].stubs(:outdated?).returns(true)
398
+ items[3].stubs(:outdated_due_to_dependencies?).returns(true)
399
+
400
+ # Mock dependency tracker
401
+ dependency_tracker = mock
402
+ dependency_tracker.expects(:forget_dependencies_for).times(3)
403
+
404
+ # Create compiler
405
+ compiler = Nanoc3::Compiler.new(nil)
406
+ compiler.stubs(:dependency_tracker).returns(dependency_tracker)
407
+ compiler.send :forget_dependencies_if_outdated, items
408
+ end
409
+
410
+ end
@@ -0,0 +1,121 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::CompilerDSLTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_compile
10
+ # TODO implement
11
+ end
12
+
13
+ def test_route
14
+ # TODO implement
15
+ end
16
+
17
+ def test_layout
18
+ # TODO implement
19
+ end
20
+
21
+ def test_identifier_to_regex_without_wildcards
22
+ # Create compiler DSL
23
+ compiler_dsl = Nanoc3::CompilerDSL.new(nil)
24
+
25
+ actual = compiler_dsl.instance_eval { identifier_to_regex('foo') }
26
+ expected = %r{^/foo/$}
27
+
28
+ assert_equal(expected.to_s, actual.to_s)
29
+ assert_equal(expected.source, actual.source)
30
+ assert_equal(expected.kcode, actual.kcode) if expected.respond_to?(:kcode)
31
+ assert_equal(expected.casefold?, actual.casefold?)
32
+ assert_equal(expected.options, actual.options)
33
+ end
34
+
35
+ def test_identifier_to_regex_with_one_wildcard
36
+ # Create compiler DSL
37
+ compiler_dsl = Nanoc3::CompilerDSL.new(nil)
38
+
39
+ actual = compiler_dsl.instance_eval { identifier_to_regex('foo/*/bar') }
40
+ expected = %r{^/foo/(.*?)/bar/$}
41
+
42
+ assert_equal(expected.to_s, actual.to_s)
43
+ assert_equal(expected.source, actual.source)
44
+ assert_equal(expected.kcode, actual.kcode) if expected.respond_to?(:kcode)
45
+ assert_equal(expected.casefold?, actual.casefold?)
46
+ assert_equal(expected.options, actual.options)
47
+ end
48
+
49
+ def test_identifier_to_regex_with_two_wildcards
50
+ # Create compiler DSL
51
+ compiler_dsl = Nanoc3::CompilerDSL.new(nil)
52
+
53
+ actual = compiler_dsl.instance_eval { identifier_to_regex('foo/*/bar/*/qux') }
54
+ expected = %r{^/foo/(.*?)/bar/(.*?)/qux/$}
55
+
56
+ assert_equal(expected.to_s, actual.to_s)
57
+ assert_equal(expected.source, actual.source)
58
+ assert_equal(expected.kcode, actual.kcode) if expected.respond_to?(:kcode)
59
+ assert_equal(expected.casefold?, actual.casefold?)
60
+ assert_equal(expected.options, actual.options)
61
+ end
62
+
63
+ def test_identifier_to_regex_with_just_one_wildcard
64
+ # Create compiler DSL
65
+ compiler_dsl = Nanoc3::CompilerDSL.new(nil)
66
+
67
+ actual = compiler_dsl.instance_eval { identifier_to_regex('*') }
68
+ expected = %r{^/(.*?)$}
69
+
70
+ assert_equal(expected.to_s, actual.to_s)
71
+ assert_equal(expected.source, actual.source)
72
+ assert_equal(expected.kcode, actual.kcode) if expected.respond_to?(:kcode)
73
+ assert_equal(expected.casefold?, actual.casefold?)
74
+ assert_equal(expected.options, actual.options)
75
+ end
76
+
77
+ def test_identifier_to_regex_with_root
78
+ # Create compiler DSL
79
+ compiler_dsl = Nanoc3::CompilerDSL.new(nil)
80
+
81
+ actual = compiler_dsl.instance_eval { identifier_to_regex('/') }
82
+ expected = %r{^/$}
83
+
84
+ assert_equal(expected.to_s, actual.to_s)
85
+ assert_equal(expected.source, actual.source)
86
+ assert_equal(expected.kcode, actual.kcode) if expected.respond_to?(:kcode)
87
+ assert_equal(expected.casefold?, actual.casefold?)
88
+ assert_equal(expected.options, actual.options)
89
+ end
90
+
91
+ def test_identifier_to_regex_with_only_children
92
+ # Create compiler DSL
93
+ compiler_dsl = Nanoc3::CompilerDSL.new(nil)
94
+
95
+ actual = compiler_dsl.instance_eval { identifier_to_regex('/foo/*/') }
96
+ expected = %r{^/foo/(.*?)/$}
97
+
98
+ assert_equal(expected.to_s, actual.to_s)
99
+ assert_equal(expected.source, actual.source)
100
+ assert_equal(expected.kcode, actual.kcode) if expected.respond_to?(:kcode)
101
+ assert_equal(expected.casefold?, actual.casefold?)
102
+ assert_equal(expected.options, actual.options)
103
+ end
104
+
105
+ def test_identifier_to_regex_with_plus_wildcard
106
+ # Create compiler DSL
107
+ compiler_dsl = Nanoc3::CompilerDSL.new(nil)
108
+
109
+ actual = compiler_dsl.instance_eval { identifier_to_regex('/foo/+') }
110
+ expected = %r{^/foo/(.+?)/$}
111
+
112
+ assert_equal(expected.to_s, actual.to_s)
113
+ assert_equal(expected.source, actual.source)
114
+ assert_equal(expected.kcode, actual.kcode) if expected.respond_to?(:kcode)
115
+ assert_equal(expected.casefold?, actual.casefold?)
116
+ assert_equal(expected.options, actual.options)
117
+ assert('/foo/bar/' =~ actual)
118
+ refute('/foo/' =~ actual)
119
+ end
120
+
121
+ end
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::ContextTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_context_with_instance_variable
10
+ # Create context
11
+ context = Nanoc3::Context.new({ :foo => 'bar', :baz => 'quux' })
12
+
13
+ # Ensure correct evaluation
14
+ assert_equal('bar', eval("@foo", context.get_binding))
15
+ end
16
+
17
+ def test_context_with_instance_method
18
+ # Create context
19
+ context = Nanoc3::Context.new({ :foo => 'bar', :baz => 'quux' })
20
+
21
+ # Ensure correct evaluation
22
+ assert_equal('bar', eval("foo", context.get_binding))
23
+ end
24
+
25
+ def test_example
26
+ # Parse
27
+ YARD.parse('../lib/nanoc3/base/context.rb')
28
+
29
+ # Run
30
+ assert_examples_correct 'Nanoc3::Context#initialize'
31
+ end
32
+
33
+ end
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::DataSourceTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_loading
10
+ # Create data source
11
+ data_source = Nanoc3::DataSource.new(nil, nil, nil, nil)
12
+ data_source.expects(:up).times(1)
13
+ data_source.expects(:down).times(1)
14
+
15
+ # Test nested loading
16
+ assert_equal(0, data_source.instance_eval { @references })
17
+ data_source.loading do
18
+ assert_equal(1, data_source.instance_eval { @references })
19
+ data_source.loading do
20
+ assert_equal(2, data_source.instance_eval { @references })
21
+ end
22
+ assert_equal(1, data_source.instance_eval { @references })
23
+ end
24
+ assert_equal(0, data_source.instance_eval { @references })
25
+ end
26
+
27
+ def test_not_implemented
28
+ # Create data source
29
+ data_source = Nanoc3::DataSource.new(nil, nil, nil, nil)
30
+
31
+ # Test optional methods
32
+ data_source.up
33
+ data_source.down
34
+ data_source.update
35
+
36
+ # Test required methods - general
37
+ assert_raises(NotImplementedError) { data_source.setup }
38
+
39
+ # Test methods - loading data
40
+ assert_equal [], data_source.items
41
+ assert_equal [], data_source.layouts
42
+
43
+ # Test required method - creating data
44
+ assert_raises(NotImplementedError) { data_source.create_item(nil, nil, nil) }
45
+ assert_raises(NotImplementedError) { data_source.create_layout(nil, nil, nil) }
46
+ end
47
+
48
+ end