From: jarosluv Date: Wed, 16 Oct 2013 10:53:21 +0000 (+0400) Subject: Modified regular expressions for correct formatting of grammatical cases in Russian... X-Git-Tag: 2.4.0~4^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=60bfa24f0cd585685d9a470c3da866d9dee171c7;p=thirdparty%2Fmoment.git Modified regular expressions for correct formatting of grammatical cases in Russian language. Escaped symbols doesn't affect the correct format of grammatical cases in pattern 'D[oD]? MMMM?'. --- diff --git a/lang/ru.js b/lang/ru.js index e8d589007..1d1816ce9 100644 --- a/lang/ru.js +++ b/lang/ru.js @@ -39,7 +39,7 @@ 'accusative': 'января_февраля_марта_апреля_мая_июня_июля_августа_сентября_октября_ноября_декабря'.split('_') }, - nounCase = (/D[oD]? *MMMM?/).test(format) ? + nounCase = (/D[oD]?(\[[^\[\]]*\]|\s+)+MMMM?/).test(format) ? 'accusative' : 'nominative'; @@ -52,7 +52,7 @@ 'accusative': 'янв_фев_мар_апр_мая_июня_июля_авг_сен_окт_ноя_дек'.split('_') }, - nounCase = (/D[oD]? *MMMM?/).test(format) ? + nounCase = (/D[oD]?(\[[^\[\]]*\]|\s+)+MMMM?/).test(format) ? 'accusative' : 'nominative'; diff --git a/test/lang/ru.js b/test/lang/ru.js index 6a1805ea5..f1aecded6 100644 --- a/test/lang/ru.js +++ b/test/lang/ru.js @@ -170,6 +170,38 @@ exports["lang:ru"] = { test.done(); }, + "format month case with escaped symbols" : function (test) { + test.expect(48); + + var months = { + 'nominative': 'январь_февраль_март_апрель_май_июнь_июль_август_сентябрь_октябрь_ноябрь_декабрь'.split('_'), + 'accusative': 'января_февраля_марта_апреля_мая_июня_июля_августа_сентября_октября_ноября_декабря'.split('_') + }, i; + for (i = 0; i < 12; i++) { + test.equal(moment([2013, i, 1]).format('D[] MMMM'), '1 ' + months.accusative[i], '1 ' + months.accusative[i]); + test.equal(moment([2013, i, 1]).format('[]D[] []MMMM[]'), '1 ' + months.accusative[i] + '', '1 ' + months.accusative[i] + ''); + test.equal(moment([2013, i, 1]).format('D[-й день] MMMM'), '1-й день ' + months.accusative[i], '1-й день ' + months.accusative[i]); + test.equal(moment([2013, i, 1]).format('D, MMMM'), '1, ' + months.nominative[i], '1, ' + months.nominative[i]); + } + test.done(); + }, + + "format month short case with escaped symbols" : function (test) { + test.expect(48); + + var monthsShort = { + 'nominative': 'янв_фев_мар_апр_май_июнь_июль_авг_сен_окт_ноя_дек'.split('_'), + 'accusative': 'янв_фев_мар_апр_мая_июня_июля_авг_сен_окт_ноя_дек'.split('_') + }, i; + for (i = 0; i < 12; i++) { + test.equal(moment([2013, i, 1]).format('D[] MMM'), '1 ' + monthsShort.accusative[i], '1 ' + monthsShort.accusative[i]); + test.equal(moment([2013, i, 1]).format('[]D[] []MMM[]'), '1 ' + monthsShort.accusative[i] + '', '1 ' + monthsShort.accusative[i] + ''); + test.equal(moment([2013, i, 1]).format('D[-й день] MMM'), '1-й день ' + monthsShort.accusative[i], '1-й день ' + monthsShort.accusative[i]); + test.equal(moment([2013, i, 1]).format('D, MMM'), '1, ' + monthsShort.nominative[i], '1, ' + monthsShort.nominative[i]); + } + test.done(); + }, + "format week" : function (test) { test.expect(7);