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,303 @@
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_compilation_rule_for
10
+ # Mock rules
11
+ rules = [ mock, mock, mock ]
12
+ rules[0].expects(:applicable_to?).returns(false)
13
+ rules[1].expects(:applicable_to?).returns(true)
14
+ rules[1].expects(:rep_name).returns('wrong')
15
+ rules[2].expects(:applicable_to?).returns(true)
16
+ rules[2].expects(:rep_name).returns('right')
17
+
18
+ # Create compiler
19
+ compiler = Nanoc3::Compiler.new(nil)
20
+ compiler.rules_collection.instance_eval { @item_compilation_rules = rules }
21
+
22
+ # Mock rep
23
+ rep = mock
24
+ rep.stubs(:name).returns('right')
25
+ item = mock
26
+ rep.stubs(:item).returns(item)
27
+
28
+ # Test
29
+ assert_equal rules[2], compiler.rules_collection.compilation_rule_for(rep)
30
+ end
31
+
32
+ def test_routing_rule_for
33
+ # Mock rules
34
+ rules = [ mock, mock, mock ]
35
+ rules[0].expects(:applicable_to?).returns(false)
36
+ rules[1].expects(:applicable_to?).returns(true)
37
+ rules[1].expects(:rep_name).returns('wrong')
38
+ rules[2].expects(:applicable_to?).returns(true)
39
+ rules[2].expects(:rep_name).returns('right')
40
+
41
+ # Create compiler
42
+ compiler = Nanoc3::Compiler.new(nil)
43
+ compiler.rules_collection.instance_eval { @item_routing_rules = rules }
44
+
45
+ # Mock rep
46
+ rep = mock
47
+ rep.stubs(:name).returns('right')
48
+ item = mock
49
+ rep.stubs(:item).returns(item)
50
+
51
+ # Test
52
+ assert_equal rules[2], compiler.rules_collection.routing_rule_for(rep)
53
+ end
54
+
55
+ def test_filter_for_layout_with_existant_layout
56
+ # Mock site
57
+ site = mock
58
+
59
+ # Create compiler
60
+ compiler = Nanoc3::Compiler.new(site)
61
+ compiler.rules_collection.layout_filter_mapping[/.*/] = [ :erb, { :foo => 'bar' } ]
62
+
63
+ # Mock layout
64
+ layout = MiniTest::Mock.new
65
+ layout.expect(:identifier, '/some_layout/')
66
+
67
+ # Check
68
+ assert_equal([ :erb, { :foo => 'bar' } ], compiler.rules_collection.filter_for_layout(layout))
69
+ end
70
+
71
+ def test_filter_for_layout_with_existant_layout_and_unknown_filter
72
+ # Mock site
73
+ site = mock
74
+
75
+ # Create compiler
76
+ compiler = Nanoc3::Compiler.new(site)
77
+ compiler.rules_collection.layout_filter_mapping[/.*/] = [ :some_unknown_filter, { :foo => 'bar' } ]
78
+
79
+ # Mock layout
80
+ layout = MiniTest::Mock.new
81
+ layout.expect(:identifier, '/some_layout/')
82
+
83
+ # Check
84
+ assert_equal([ :some_unknown_filter, { :foo => 'bar' } ], compiler.rules_collection.filter_for_layout(layout))
85
+ end
86
+
87
+ def test_filter_for_layout_with_nonexistant_layout
88
+ # Mock site
89
+ site = mock
90
+
91
+ # Create compiler
92
+ compiler = Nanoc3::Compiler.new(site)
93
+ compiler.rules_collection.layout_filter_mapping[%r{^/foo/$}] = [ :erb, { :foo => 'bar' } ]
94
+
95
+ # Mock layout
96
+ layout = MiniTest::Mock.new
97
+ layout.expect(:identifier, '/bar/')
98
+
99
+ # Check
100
+ assert_equal(nil, compiler.rules_collection.filter_for_layout(layout))
101
+ end
102
+
103
+ def test_filter_for_layout_with_many_layouts
104
+ # Mock site
105
+ site = mock
106
+
107
+ # Create compiler
108
+ compiler = Nanoc3::Compiler.new(site)
109
+ compiler.rules_collection.layout_filter_mapping[%r{^/a/b/c/.*/$}] = [ :erb, { :char => 'd' } ]
110
+ compiler.rules_collection.layout_filter_mapping[%r{^/a/.*/$}] = [ :erb, { :char => 'b' } ]
111
+ compiler.rules_collection.layout_filter_mapping[%r{^/a/b/.*/$}] = [ :erb, { :char => 'c' } ] # never used!
112
+ compiler.rules_collection.layout_filter_mapping[%r{^/.*/$}] = [ :erb, { :char => 'a' } ]
113
+
114
+ # Mock layout
115
+ layouts = [ mock, mock, mock, mock ]
116
+ layouts[0].stubs(:identifier).returns('/a/b/c/d/')
117
+ layouts[1].stubs(:identifier).returns('/a/b/c/')
118
+ layouts[2].stubs(:identifier).returns('/a/b/')
119
+ layouts[3].stubs(:identifier).returns('/a/')
120
+
121
+ # Get expectations
122
+ expectations = {
123
+ 0 => 'd',
124
+ 1 => 'b', # never used! not c, because b takes priority
125
+ 2 => 'b',
126
+ 3 => 'a'
127
+ }
128
+
129
+ # Check
130
+ expectations.each_pair do |num, char|
131
+ filter_and_args = compiler.rules_collection.filter_for_layout(layouts[num])
132
+ refute_nil(filter_and_args)
133
+ assert_equal(char, filter_and_args[1][:char])
134
+ end
135
+ end
136
+
137
+ def test_compile_rep_should_write_proper_snapshots
138
+ # Mock rep
139
+ item = Nanoc3::Item.new('<%= 1 %> <%%= 2 %> <%%%= 3 %>', {}, '/moo/')
140
+ rep = Nanoc3::ItemRep.new(item, :blah)
141
+
142
+ # Set snapshot filenames
143
+ rep.raw_paths = {
144
+ :raw => 'raw.txt',
145
+ :pre => 'pre.txt',
146
+ :post => 'post.txt',
147
+ :last => 'last.txt'
148
+ }
149
+
150
+ # Create rule
151
+ rule_block = proc do
152
+ filter :erb
153
+ filter :erb
154
+ layout '/blah/'
155
+ filter :erb
156
+ end
157
+ rule = Nanoc3::Rule.new(/blah/, :meh, rule_block)
158
+
159
+ # Create layout
160
+ layout = Nanoc3::Layout.new('head <%= yield %> foot', {}, '/blah/')
161
+
162
+ # Create site
163
+ site = mock
164
+ site.stubs(:config).returns({})
165
+ site.stubs(:items).returns([])
166
+ site.stubs(:layouts).returns([ layout ])
167
+
168
+ # Create compiler
169
+ compiler = Nanoc3::Compiler.new(site)
170
+ compiler.rules_collection.expects(:compilation_rule_for).times(2).with(rep).returns(rule)
171
+ compiler.rules_collection.layout_filter_mapping[%r{^/blah/$}] = [ :erb, {} ]
172
+ site.stubs(:compiler).returns(compiler)
173
+
174
+ # Compile
175
+ compiler.send(:compile_rep, rep)
176
+
177
+ # Test
178
+ assert File.file?('raw.txt')
179
+ assert File.file?('pre.txt')
180
+ assert File.file?('post.txt')
181
+ assert File.file?('last.txt')
182
+ assert_equal '<%= 1 %> <%%= 2 %> <%%%= 3 %>', File.read('raw.txt')
183
+ assert_equal '1 2 <%= 3 %>', File.read('pre.txt')
184
+ assert_equal 'head 1 2 3 foot', File.read('post.txt')
185
+ assert_equal 'head 1 2 3 foot', File.read('last.txt')
186
+ end
187
+
188
+ def test_compile_with_no_reps
189
+ with_site do |site|
190
+ site.compile
191
+
192
+ assert Dir['output/*'].empty?
193
+ end
194
+ end
195
+
196
+ def test_compile_with_one_rep
197
+ with_site do |site|
198
+ File.open('content/index.html', 'w') { |io| io.write('o hello') }
199
+
200
+ site.compile
201
+
202
+ assert Dir['output/*'].size == 1
203
+ assert File.file?('output/index.html')
204
+ assert File.read('output/index.html') == 'o hello'
205
+ end
206
+ end
207
+
208
+ def test_compile_with_two_independent_reps
209
+ with_site do |site|
210
+ File.open('content/foo.html', 'w') { |io| io.write('o hai') }
211
+ File.open('content/bar.html', 'w') { |io| io.write('o bai') }
212
+
213
+ site.compile
214
+
215
+ assert Dir['output/*'].size == 2
216
+ assert File.file?('output/foo/index.html')
217
+ assert File.file?('output/bar/index.html')
218
+ assert File.read('output/foo/index.html') == 'o hai'
219
+ assert File.read('output/bar/index.html') == 'o bai'
220
+ end
221
+ end
222
+
223
+ def test_compile_with_two_dependent_reps
224
+ with_site(:compilation_rule_content => 'filter :erb') do |site|
225
+ File.open('content/foo.html', 'w') do |io|
226
+ io.write('<%= @items.find { |i| i.identifier == "/bar/" }.compiled_content %>!!!')
227
+ end
228
+ File.open('content/bar.html', 'w') do |io|
229
+ io.write('manatee')
230
+ end
231
+
232
+ site.compile
233
+
234
+ assert Dir['output/*'].size == 2
235
+ assert File.file?('output/foo/index.html')
236
+ assert File.file?('output/bar/index.html')
237
+ assert File.read('output/foo/index.html') == 'manatee!!!'
238
+ assert File.read('output/bar/index.html') == 'manatee'
239
+ end
240
+ end
241
+
242
+ def test_compile_with_two_mutually_dependent_reps
243
+ with_site(:compilation_rule_content => 'filter :erb') do |site|
244
+ File.open('content/foo.html', 'w') do |io|
245
+ io.write('<%= @items.find { |i| i.identifier == "/bar/" }.compiled_content %>')
246
+ end
247
+ File.open('content/bar.html', 'w') do |io|
248
+ io.write('<%= @items.find { |i| i.identifier == "/foo/" }.compiled_content %>')
249
+ end
250
+
251
+ assert_raises Nanoc3::Errors::RecursiveCompilation do
252
+ site.compile
253
+ end
254
+ end
255
+ end
256
+
257
+ def test_disallow_routes_not_starting_with_slash
258
+ # Create site
259
+ Nanoc3::CLI::Base.new.run([ 'create_site', 'bar' ])
260
+
261
+ FileUtils.cd('bar') do
262
+ # Create routes
263
+ File.open('Rules', 'w') do |io|
264
+ io.write "compile '*' do\n"
265
+ io.write " layout 'default'\n"
266
+ io.write "end\n"
267
+ io.write "\n"
268
+ io.write "route '*' do\n"
269
+ io.write " 'index.html'\n"
270
+ io.write "end\n"
271
+ io.write "\n"
272
+ io.write "layout '*', :erb\n"
273
+ end
274
+
275
+ # Create site
276
+ site = Nanoc3::Site.new('.')
277
+ error = assert_raises(RuntimeError) do
278
+ site.compile
279
+ end
280
+ assert_match /^The path returned for the.*does not start with a slash. Please ensure that all routing rules return a path that starts with a slash./, error.message
281
+ end
282
+ end
283
+
284
+ def test_load_should_be_idempotent
285
+ # Create site
286
+ Nanoc3::CLI::Base.new.run([ 'create_site', 'bar' ])
287
+
288
+ FileUtils.cd('bar') do
289
+ site = Nanoc3::Site.new('.')
290
+
291
+ compiler = Nanoc3::Compiler.new(site)
292
+ def compiler.route_reps
293
+ raise 'oh my gosh it is borken'
294
+ end
295
+
296
+ assert site.instance_eval { !@loaded }
297
+ assert_raises(RuntimeError) { compiler.load }
298
+ assert site.instance_eval { !@loaded }
299
+ assert_raises(RuntimeError) { compiler.load }
300
+ end
301
+ end
302
+
303
+ end
@@ -0,0 +1,156 @@
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_passthrough
22
+ # Create site
23
+ Nanoc3::CLI::Base.new.run([ 'create_site', 'bar' ])
24
+ FileUtils.cd('bar') do
25
+ # Create rep
26
+ item = Nanoc3::Item.new('foo', { :extension => 'bar' }, '/foo/')
27
+ rep = Nanoc3::ItemRep.new(item, :default)
28
+
29
+ # Create other necessary stuff
30
+ site = Nanoc3::Site.new('.')
31
+ site.items << item
32
+ compiler = site.compiler
33
+ dsl = site.compiler.rules_collection.dsl
34
+
35
+ # Create rule
36
+ dsl.passthrough '/foo/'
37
+
38
+ # Route and compile
39
+ rule = compiler.rules_collection.routing_rule_for(rep)
40
+ path = rule.apply_to(rep, :compiler => compiler)
41
+ compiler.send :compile_rep, rep
42
+
43
+ # Check result
44
+ assert_equal 'foo', rep.compiled_content
45
+ assert_equal '/foo.bar', path
46
+ end
47
+ end
48
+
49
+ def test_identifier_to_regex_without_wildcards
50
+ # Create compiler DSL
51
+ compiler_dsl = Nanoc3::CompilerDSL.new(nil)
52
+
53
+ actual = compiler_dsl.instance_eval { identifier_to_regex('foo') }
54
+ expected = %r{^/foo/$}
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_one_wildcard
64
+ # Create compiler DSL
65
+ compiler_dsl = Nanoc3::CompilerDSL.new(nil)
66
+
67
+ actual = compiler_dsl.instance_eval { identifier_to_regex('foo/*/bar') }
68
+ expected = %r{^/foo/(.*?)/bar/$}
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_two_wildcards
78
+ # Create compiler DSL
79
+ compiler_dsl = Nanoc3::CompilerDSL.new(nil)
80
+
81
+ actual = compiler_dsl.instance_eval { identifier_to_regex('foo/*/bar/*/qux') }
82
+ expected = %r{^/foo/(.*?)/bar/(.*?)/qux/$}
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_just_one_wildcard
92
+ # Create compiler DSL
93
+ compiler_dsl = Nanoc3::CompilerDSL.new(nil)
94
+
95
+ actual = compiler_dsl.instance_eval { identifier_to_regex('*') }
96
+ expected = %r{^/(.*?)$}
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_root
106
+ # Create compiler DSL
107
+ compiler_dsl = Nanoc3::CompilerDSL.new(nil)
108
+
109
+ actual = compiler_dsl.instance_eval { identifier_to_regex('/') }
110
+ expected = %r{^/$}
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
+ end
118
+
119
+ def test_identifier_to_regex_with_only_children
120
+ # Create compiler DSL
121
+ compiler_dsl = Nanoc3::CompilerDSL.new(nil)
122
+
123
+ actual = compiler_dsl.instance_eval { identifier_to_regex('/foo/*/') }
124
+ expected = %r{^/foo/(.*?)/$}
125
+
126
+ assert_equal(expected.to_s, actual.to_s)
127
+ assert_equal(expected.source, actual.source)
128
+ assert_equal(expected.kcode, actual.kcode) if expected.respond_to?(:kcode)
129
+ assert_equal(expected.casefold?, actual.casefold?)
130
+ assert_equal(expected.options, actual.options)
131
+ end
132
+
133
+ def test_identifier_to_regex_with_plus_wildcard
134
+ # Create compiler DSL
135
+ compiler_dsl = Nanoc3::CompilerDSL.new(nil)
136
+
137
+ actual = compiler_dsl.instance_eval { identifier_to_regex('/foo/+') }
138
+ expected = %r{^/foo/(.+?)/$}
139
+
140
+ assert_equal(expected.to_s, actual.to_s)
141
+ assert_equal(expected.source, actual.source)
142
+ assert_equal(expected.kcode, actual.kcode) if expected.respond_to?(:kcode)
143
+ assert_equal(expected.casefold?, actual.casefold?)
144
+ assert_equal(expected.options, actual.options)
145
+ assert('/foo/bar/' =~ actual)
146
+ refute('/foo/' =~ actual)
147
+ end
148
+
149
+ def test_dsl_has_no_access_to_compiler
150
+ compiler_dsl = Nanoc3::CompilerDSL.new(nil)
151
+ assert_raises(NameError) do
152
+ compiler_dsl.instance_eval { compiler }
153
+ end
154
+ end
155
+
156
+ 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