#============================================================= -*-perl-*- # # t/xmlstyle.t # # Test the XML::Style plugin. # # Written by Andy Wardley # # Copyright (C) 1996-2001 Andy Wardley. All Rights Reserved. # Copyright (C) 1998-2001 Canon Research Centre Europe Ltd. # # This is free software; you can redistribute it and/or modify it # under the same terms as Perl itself. # # $Id: xmlstyle.t,v 1.5 2003/03/17 22:34:14 abw Exp $ # #======================================================================== use strict; use lib qw( ./lib ../lib ../blib/arch ); use Template; use Template::Test; use Cwd qw( abs_path ); $^W = 1; $Template::Test::PRESERVE = 1; test_expect(\*DATA); __END__ -- test -- [% USE xmlstyle -%] [% FILTER xmlstyle -%] The foo The bar [%- END %] -- expect -- The foo The bar -- test -- [% USE xmlstyle foo = { element = 'bar' } -%] [% FILTER xmlstyle -%] The foo The bar [%- END %] -- expect -- The foo The bar -- test -- [% USE xmlstyle foo = { element = 'baz' } -%] [% FILTER xmlstyle -%] The foo The bar [%- END %] -- expect -- The foo The bar -- test -- [% USE xmlstyle -%] [% FILTER xmlstyle foo = { element = 'wiz' } -%] The foo The bar [%- END %] -- expect -- The foo The bar -- test -- [% USE xmlstyle foo = { element = 'bar' } -%] [% FILTER xmlstyle foo = { element = 'baz' } -%] The foo The bar [%- END %] -- expect -- The foo The bar -- test -- [% USE xmlstyle foo = { element = 'oof' } -%] [% FILTER xmlstyle bar = { element = 'rab' } -%] The foo The bar [%- END %] -- expect -- The foo The bar -- test -- [% USE xmlstyle -%] [% FILTER xmlstyle foo = { attributes = { wiz = 'waz' } } -%] The foo [%- END %] -- expect -- The foo -- test -- [% USE xmlstyle foo = { attributes = { wiz = 'waz' } }-%] [% FILTER xmlstyle bar = { attributes = { biz = 'boz' } } -%] The foo blam [%- END %] -- expect -- The foo blam -- test -- [% USE xmlstyle list = { element = 'ul' pre_start = "

\n" post_start = "\n" pre_end = "\n" post_end = "\n

" attributes = { class = 'mylist' } } item = { element = 'li' post_start = '' pre_end = '' post_end = "\n
" attributes = { class = 'myitem' } } -%] [% FILTER xmlstyle -%] The First Item The Second Item The Third Item [%- END %] -- expect --

#------------------------------------------------------------------------ # test use of plugin filter via variable #------------------------------------------------------------------------ -- test -- [% USE xmlstyle foo = { element = 'bar' } -%] [% FILTER $xmlstyle -%] The foo [%- END %] -- expect -- The foo -- test -- [% USE xmlstyle foo = { element = 'bar' } -%] [% FILTER $xmlstyle bar = { element = 'baz' } -%] The foo The bar [%- END %] -- expect -- The foo The bar -- test -- [% USE zap = xmlstyle foo = { element = 'bar' } -%] [% FILTER $zap bar = { element = 'baz' } -%] The foo The bar [%- END %] -- expect -- The foo The bar -- test -- [% USE zap = xmlstyle foo = { element = 'bar' } -%] [% FILTER $zap 'blaml' bar = { element = 'baz' } -%] The foo The bar [%- END %] -- expect -- The foo The bar -- test -- [% USE xmlstyle 'zap' -%] [% FILTER zap bar = { element = 'baz' } -%] The foo The bar [%- END %] -- expect -- The foo The bar #------------------------------------------------------------------------ # an example based on one from Tony Bowden posted to the mailing list #------------------------------------------------------------------------ -- test -- [% USE xmlstyle video = { element = 'table' attributes = { class='videoTable' }, } title = { pre_start = "\n Title:\n " element = 'td' attributes = { class='videoTitle' } post_end = "\n " } price = { pre_start = "\n Price:\n " element = 'td' attributes = { class='videoPrice' } post_end = "\n " } ; FILTER xmlstyle -%] [% END %] -- expect --
Title: Buffy Series 1
Price: 10.99