From 81e045f33a09bbe6d8fcc102a5586e7e7e8073a5 Mon Sep 17 00:00:00 2001 From: GeorgeClark Date: Mon, 17 Dec 2012 02:06:32 +0000 Subject: [PATCH] Item12285: Unit tests git-svn-id: http://svn.foswiki.org/trunk@16229 0b4bb1d4-4e5a-0410-9cc4-b2b747904278 --- UnitTestContrib/test/unit/Fn_MAKETEXT.pm | 50 ++++++++++++++++++++++++ core/data/System/VarMAKETEXT.txt | 14 +++++++ 2 files changed, 64 insertions(+) diff --git a/UnitTestContrib/test/unit/Fn_MAKETEXT.pm b/UnitTestContrib/test/unit/Fn_MAKETEXT.pm index 0b8e82c54b..5e92a026d5 100644 --- a/UnitTestContrib/test/unit/Fn_MAKETEXT.pm +++ b/UnitTestContrib/test/unit/Fn_MAKETEXT.pm @@ -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 Invalid parameter "_0", MAKETEXT rejected. Excessive parameter number 222, MAKETEXT rejected.', + $result + ); + + $result = $topicObject->expandMacros( + '%MAKETEXT{"edit [_222] [_0]" args="WebHome, now"}%'); + $this->assert_str_equals( +'edit Excessive parameter number 222, MAKETEXT rejected. Invalid parameter "_0", MAKETEXT rejected.', + $result + ); + $result = + $topicObject->expandMacros('%MAKETEXT{"edit [*,_222,file]" args="2"}%'); + $this->assert_str_equals( +'edit Excessive parameter number 222, MAKETEXT rejected.', + $result + ); +} + sub test_multiple_args_one_empty { my $this = shift; diff --git a/core/data/System/VarMAKETEXT.txt b/core/data/System/VarMAKETEXT.txt index 64734d45ce..dcd8974c79 100644 --- a/core/data/System/VarMAKETEXT.txt +++ b/core/data/System/VarMAKETEXT.txt @@ -33,6 +33,8 @@ current user's selected language via =locale/*.po= translation files. args="%SYSTEMWEB%.ResetPassword,%WIKIUSERNAME%" }% * *Notes:* + * =[_n]= brackets are validated to a positive integer from 1 to 100. + * Missing arguments are replaced with an empty string ''. * An ampersand (&) followed by one ascii alphabetic character (a...z, A...Z) in the translatable string will be expanded to an access key string. For example, =&X= will expand to @@ -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 =%MAKETEXT= macro also supports a _limited_ subset of the =quant= style bracket notation:
+  %MAKETEXT{string="Edit [*,_1,file]" args="4"}%
+  expands to:
+    %MAKETEXT{string="Edit [*,_1,file]" args="4"}%
+ * *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. +