From 1fd17ef320f1eb107881eb95783a5508c1ff0aab Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Fri, 27 Aug 2010 13:20:30 -0500 Subject: [PATCH] add test for WebGUI::Macro::transform --- lib/WebGUI/Macro.pm | 4 ++-- t/Macro.t | 30 ++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/lib/WebGUI/Macro.pm b/lib/WebGUI/Macro.pm index 6f5811f50..3ef455fcd 100644 --- a/lib/WebGUI/Macro.pm +++ b/lib/WebGUI/Macro.pm @@ -257,7 +257,7 @@ The name of the macro called. The module name for the macro from the config file. -=item originalText +=item originalString The full original text of the macro call. @@ -299,7 +299,7 @@ sub _transformMacro { session => $session, macro => $macro, macroPackage => $macroPackage, - originalText => $original, + originalString => $original, parameters => $params, parameterString => $paramString, }); diff --git a/t/Macro.t b/t/Macro.t index 230d083c5..3a4eaa8f7 100644 --- a/t/Macro.t +++ b/t/Macro.t @@ -43,8 +43,6 @@ foreach my $macro (qw/ } $session->config->addToHash('macros', "Ex'tras", "Extras"); -plan tests => 51; - my $macroText = "CompanyName: ^c;"; my $companyName = $session->setting->get('companyName'); WebGUI::HTML::makeParameterSafe( \$companyName ); @@ -337,3 +335,31 @@ is ( '@MacroCall[`1`.` 2`.`3`]:', 'internal spaces are okay' ); + +my $macroText = 'before ^VisualMacro("1", 2,); after'; +my $macroData; +WebGUI::Macro::transform($session, \$macroText, sub { + $macroData = shift; + return "replace"; +}); + +is ( + $macroText, + 'before replace after', + 'transform replaces macro calls' +); + +is_deeply($macroData, { + session => $session, + macro => 'VisualMacro', + macroPackage => 'WebGUI::Macro::VisualMacro', + originalString => '^VisualMacro("1", 2,);', + parameters => [ + '1', + ' 2', + ], + parameterString => '("1", 2,)', +}, 'transform passes sub correct data'); + +done_testing; +