Skip to content

Commit

Permalink
Item12285: Unit tests
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@16229 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Dec 17, 2012
1 parent 8653127 commit 81e045f
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
50 changes: 50 additions & 0 deletions UnitTestContrib/test/unit/Fn_MAKETEXT.pm
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,56 @@ sub test_multiple_args {
$this->assert_str_equals( 'edit WebHome now', $result );
}

sub test_quant_plurals {
my $this = shift;

my $result = $topicObject->expandMacros(
'%MAKETEXT{"edit [*,_1,file] in [_2]" args="1,here"}%');
$this->assert_str_equals( 'edit 1 file in here', $result );

$result = $topicObject->expandMacros(
'%MAKETEXT{"edit [*,_1,file] in [_2]" args="2,WebHome"}%');
$this->assert_str_equals( 'edit 2 files in WebHome', $result );
}

sub test_escaping {
my $this = shift;

# Make sure the real Locale::Maketext gets called
$Foswiki::cfg{UserInterfaceInternationalisation} = 1;

my $str =
' %MAKETEXT{"This \\\\\'.`echo A`.\\\\\' [*,_1,\\\\\'.`echo A`.\\\\\' ]" args="1"}% ';

my $result = $topicObject->expandMacros($str);
$this->assert_str_equals(
' This \\\'.`echo A`.\\\' 1 \\\'.`echo A`.\\\' ', $result );
}

sub test_invalid_args {
my $this = shift;

my $result = $topicObject->expandMacros(
'%MAKETEXT{"edit [_0] [_222]" args="WebHome, now"}%');
$this->assert_str_equals(
'edit <span class="foswikiAlert">Invalid parameter <code>"_0"</code>, MAKETEXT rejected.</span> <span class="foswikiAlert">Excessive parameter number 222, MAKETEXT rejected.</span>',
$result
);

$result = $topicObject->expandMacros(
'%MAKETEXT{"edit [_222] [_0]" args="WebHome, now"}%');
$this->assert_str_equals(
'edit <span class="foswikiAlert">Excessive parameter number 222, MAKETEXT rejected.</span> <span class="foswikiAlert">Invalid parameter <code>"_0"</code>, MAKETEXT rejected.</span>',
$result
);
$result =
$topicObject->expandMacros('%MAKETEXT{"edit [*,_222,file]" args="2"}%');
$this->assert_str_equals(
'edit <span class="foswikiAlert">Excessive parameter number 222, MAKETEXT rejected.</span>',
$result
);
}

sub test_multiple_args_one_empty {
my $this = shift;

Expand Down
14 changes: 14 additions & 0 deletions core/data/System/VarMAKETEXT.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ current user's selected language via =locale/*.po= translation files.
args="%SYSTEMWEB%.ResetPassword,%WIKIUSERNAME%"
}%</pre>
* *Notes:*
* =[_n]= brackets are validated to a positive integer from 1 to 100.
* Missing arguments are replaced with an empty string ''.
* An ampersand (<code>&amp;</code>) followed by one ascii alphabetic
character (a...z, A...Z) in the translatable string will be expanded
to an access key string. For example, =&amp;X= will expand to
Expand All @@ -50,4 +52,16 @@ current user's selected language via =locale/*.po= translation files.
shown in the examples above.
* The string will be output in English if no mapping can be found in
the =.po= translation file for the current user's selected language.

* *Plurals:*
* The =%<nop>MAKETEXT= macro also supports a _limited_ subset of the =quant= style bracket notation: <pre class="tml">
%<nop>MAKETEXT{string="Edit [*,_1,file]" args="4"}%
expands to:
%MAKETEXT{string="Edit [*,_1,file]" args="4"}%</pre>
* *Notes on plurals:*
* Only 3 arguments are supported.
* The first parameter must be an asterisk. Literals =quant=, =numf= or =#= are not supported.
* The 2nd parameter must be the argument number
* The 3rd parameter is the word or phrase to be made plural.

<!--%JQREQUIRE{"chili"}%-->

0 comments on commit 81e045f

Please sign in to comment.