# -*- encoding: utf-8 -*- require 'test/unit' require 'webgen/tree' require 'webgen/page' require 'webgen/contentprocessor' class TestContentProcessorBlocks < Test::Unit::TestCase def test_process obj = Webgen::ContentProcessor::Blocks.new root = Webgen::Node.new(Webgen::Tree.new.dummy_root, '/', '/') node = Webgen::Node.new(root, 'test', 'test') node.node_info[:page] = Webgen::Page.from_data("--- name:content\ndata\n--- name:other\nother") template = Webgen::Node.new(root, 'template', 'template') template.node_info[:page] = Webgen::Page.from_data("--- name:content pipeline:blocks\nbeforeafter") processors = { 'blocks' => obj } context = Webgen::ContentProcessor::Context.new(:chain => [node], :processors => processors) context.content = '' obj.call(context) assert_equal('databeforedataafter', context.content) assert_equal(Set.new([node.absolute_lcn, template.absolute_lcn]), node.node_info[:used_nodes]) context.content = '' assert_raise(RuntimeError) { obj.call(context) } context.content = '' node.node_info[:used_nodes] = Set.new context[:chain] = [node, template, node] obj.call(context) assert_equal('beforedataafter', context.content) assert_equal(Set.new([template.absolute_lcn, node.absolute_lcn]), node.node_info[:used_nodes]) context.content = 'befaft' obj.call(context) assert_equal('befaft', context.content) context.content = '' assert_raise(RuntimeError) { obj.call(context) } context.content = '' obj.call(context) assert_equal('other', context.content) context.content = '' obj.call(context) assert_equal('other', context.content) context.content = '' obj.call(context) assert_equal('beforedataafter', context.content) end end