test/base/test_compiler.rb in nanoc-4.0.0a1 vs test/base/test_compiler.rb in nanoc-4.0.0a2

- old
+ new

@@ -51,11 +51,11 @@ # Mock site site = mock # Create compiler compiler = Nanoc::Int::Compiler.new(site) - compiler.rules_collection.layout_filter_mapping[/.*/] = [:erb, { foo: 'bar' }] + compiler.rules_collection.layout_filter_mapping[Nanoc::Int::Pattern.from(/.*/)] = [:erb, { foo: 'bar' }] # Mock layout layout = MiniTest::Mock.new layout.expect(:identifier, '/some_layout/') @@ -67,11 +67,11 @@ # Mock site site = mock # Create compiler compiler = Nanoc::Int::Compiler.new(site) - compiler.rules_collection.layout_filter_mapping[/.*/] = [:some_unknown_filter, { foo: 'bar' }] + compiler.rules_collection.layout_filter_mapping[Nanoc::Int::Pattern.from(/.*/)] = [:some_unknown_filter, { foo: 'bar' }] # Mock layout layout = MiniTest::Mock.new layout.expect(:identifier, '/some_layout/') @@ -83,11 +83,11 @@ # Mock site site = mock # Create compiler compiler = Nanoc::Int::Compiler.new(site) - compiler.rules_collection.layout_filter_mapping[%r{^/foo/$}] = [:erb, { foo: 'bar' }] + compiler.rules_collection.layout_filter_mapping[Nanoc::Int::Pattern.from(%r{^/foo/$})] = [:erb, { foo: 'bar' }] # Mock layout layout = MiniTest::Mock.new layout.expect(:identifier, '/bar/') @@ -99,14 +99,14 @@ # Mock site site = mock # Create compiler compiler = Nanoc::Int::Compiler.new(site) - compiler.rules_collection.layout_filter_mapping[%r{^/a/b/c/.*/$}] = [:erb, { char: 'd' }] - compiler.rules_collection.layout_filter_mapping[%r{^/a/.*/$}] = [:erb, { char: 'b' }] - compiler.rules_collection.layout_filter_mapping[%r{^/a/b/.*/$}] = [:erb, { char: 'c' }] # never used! - compiler.rules_collection.layout_filter_mapping[%r{^/.*/$}] = [:erb, { char: 'a' }] + compiler.rules_collection.layout_filter_mapping[Nanoc::Int::Pattern.from(%r{^/a/b/c/.*/$})] = [:erb, { char: 'd' }] + compiler.rules_collection.layout_filter_mapping[Nanoc::Int::Pattern.from(%r{^/a/.*/$})] = [:erb, { char: 'b' }] + compiler.rules_collection.layout_filter_mapping[Nanoc::Int::Pattern.from(%r{^/a/b/.*/$})] = [:erb, { char: 'c' }] # never used! + compiler.rules_collection.layout_filter_mapping[Nanoc::Int::Pattern.from(%r{^/.*/$})] = [:erb, { char: 'a' }] # Mock layout layouts = [mock, mock, mock, mock] layouts[0].stubs(:identifier).returns('/a/b/c/d/') layouts[1].stubs(:identifier).returns('/a/b/c/') @@ -147,11 +147,11 @@ filter :erb filter :erb layout '/blah/' filter :erb end - rule = Nanoc::Int::Rule.new(/blah/, :meh, rule_block) + rule = Nanoc::Int::Rule.new(Nanoc::Int::Pattern.from(/blah/), :meh, rule_block) # Create layout layout = Nanoc::Int::Layout.new('head <%= yield %> foot', {}, '/blah/') # Create site @@ -161,11 +161,11 @@ site.stubs(:layouts).returns([layout]) # Create compiler compiler = Nanoc::Int::Compiler.new(site) compiler.rules_collection.expects(:compilation_rule_for).times(2).with(rep).returns(rule) - compiler.rules_collection.layout_filter_mapping[%r{^/blah/$}] = [:erb, {}] + compiler.rules_collection.layout_filter_mapping[Nanoc::Int::Pattern.from(%r{^/blah/$})] = [:erb, {}] site.stubs(:compiler).returns(compiler) # Compile compiler.send(:compile_rep, rep) @@ -254,19 +254,19 @@ Nanoc::CLI.run %w( create_site bar) FileUtils.cd('bar') do # Create routes File.open('Rules', 'w') do |io| - io.write "compile '*' do\n" + io.write "compile '/**/*' do\n" io.write " layout 'default'\n" io.write "end\n" io.write "\n" - io.write "route '*' do\n" + io.write "route '/**/*' do\n" io.write " 'index.html'\n" io.write "end\n" io.write "\n" - io.write "layout '*', :erb\n" + io.write "layout '/**/*', :erb\n" end # Create site site = Nanoc::Int::Site.new('.') error = assert_raises(RuntimeError) do @@ -315,20 +315,20 @@ Nanoc::CLI.run %w( create_site bar ) FileUtils.cd('bar') do # Create routes File.open('Rules', 'w') do |io| - io.write "compile '*' do\n" + io.write "compile '/**/*' do\n" io.write " snapshot :aaa\n" io.write " snapshot :aaa\n" io.write "end\n" io.write "\n" - io.write "route '*' do\n" + io.write "route '/**/*' do\n" io.write " '/index.html'\n" io.write "end\n" io.write "\n" - io.write "layout '*', :erb\n" + io.write "layout '/**/*', :erb\n" end # Compile site = Nanoc::Int::Site.new('.') assert_raises Nanoc::Int::Errors::CannotCreateMultipleSnapshotsWithSameName do @@ -584,8 +584,28 @@ end dt.stop stack = dt.instance_eval { @stack } assert_empty stack + end + end + + def test_find_layouts_by_glob + Nanoc::CLI.run %w( create_site bar ) + FileUtils.cd('bar') do + File.open('Rules', 'w') do |io| + io.write "compile '/**/*' do\n" + io.write " layout '/default.*'\n" + io.write "end\n" + io.write "\n" + io.write "route '/**/*' do\n" + io.write " '/index.html'\n" + io.write "end\n" + io.write "\n" + io.write "layout '/**/*', :erb\n" + end + + site = Nanoc::Int::Site.new('.') + site.compile end end end