@@ -354,90 +354,68 @@ public void testUnescapePropsValue() {
354354 }
355355 }
356356
357- private static final String [][] QUOTES_TEST_CASES =
358- {
359- {"You're about to delete {0} rows." ,"You''re about to delete {0} rows." },
360- {"You're about to delete '{0}' rows in Mike's file {0}." ,"You''re about to delete ''{0}'' rows in Mike''s file {0}." },
361- {"Log shows '{''}' in file {0}" ,"Log shows '{''}' in file {0}" },
362- {"Log shows '{''} in file {0}" ,"Log shows '{''} in file {0}" },
363- {"Log shows '{'}' in file {0}" ,"Log shows '{'}' in file {0}" },
364- {"Log shows '{'error'}' in file {0}" ,"Log shows '{'error'}' in file {0}" },
365- {"Log shows '{''error''}' in file {0}" ,"Log shows '{''error''}' in file {0}" },
366- {"File {0} shows '{''error''}'" ,"File {0} shows '{''error''}'" },
367- };
368-
369- private static final String [][] TO_DOUBLE_AUTO_TEST_CASES =
370- {
371- // { input , expected }
372- {"The file isn't in use." , "The file isn't in use." },
373- };
374-
375- private static final String [][] TO_DOUBLE_ALL_TEST_CASES =
376- {
377- // { input , expected }
378- {"The file isn't in use." , "The file isn''t in use." },
379- };
380-
381- private static final String [][] TO_SINGLE_AUTO_TEST_CASES =
382- {
383- // { input , expected }
384- {"File {0} isn't in use." , "File {0} isn't in use." },
385- {"The file isn''t in use." , "The file isn''t in use." }, // no arguments - not unescaped
386- };
387-
388- private static final String [][] TO_SINGLE_ALL_TEST_CASES =
389- {
390- // { input , expected }
391- {"File {0} isn't in use." , "File {0} isn't in use." },
392- {"The file isn''t in use." , "The file isn't in use." },
393- };
357+ private static final String [][] MESSAGE_PATTERN_TEST_CASES = {
358+ // {<GP expression>,
359+ // <props expression - auto>[,
360+ // <props expression - all>, // if absent, use <prop expression - auto>
361+ // <GP expression after round trip - auto>, // if absent, use <GP expression>
362+ // <GP expression after round trip - all>]} // if absent, use <GP expression>
363+ { "You're about to delete {0} rows." ,
364+ "You''re about to delete {0} rows." },
365+ { "You're about to delete '{0}' rows in Mike's file {0}." ,
366+ "You''re about to delete '{0}' rows in Mike''s file {0}." },
367+ { "Log shows '{''}' in file {0}" ,
368+ "Log shows '{''}' in file {0}" },
369+ { "Log shows '{''} in file {0}" ,
370+ "Log shows '{''} in file {0}" ,
371+ "Log shows '{''} in file {0}'" , // escape with MessagePatternEscape.ALL
372+ null ,
373+ "Log shows '{''} in file {0}'" }, // round trip with MessagePatternEscape.ALL
374+ { "Log shows '{'}' in file {0}" ,
375+ "Log shows '{'}'' in file {0}" },
376+ { "Log shows '{'error'}' in file {0}" ,
377+ "Log shows '{'error'}' in file {0}" },
378+ { "Log shows '{''error''}' in file {0}" ,
379+ "Log shows '{''error''}' in file {0}" },
380+ { "File {0} shows '{''error''}'" ,
381+ "File {0} shows '{''error''}'" },
382+ { "The file isn't in use." ,
383+ "The file isn't in use." ,
384+ "The file isn''t in use." }, // escape with MessagePatternEscape.ALL
385+ { "File {0} isn't in use." ,
386+ "File {0} isn''t in use." },
387+ };
394388
395389 @ Test
396- public void testConvertSingleQuote () {
397- for (String [] testCase : QUOTES_TEST_CASES ) {
398- String result = JavaPropertiesResource .ConvertSingleQuote (testCase [0 ], MessagePatternEscape .AUTO );
399- assertEquals ("ConvertSingleQuote (" + testCase [0 ] + ", AUTO)" , testCase [1 ], result );
390+ public void testEscapeMessagePattern () throws ResourceFilterException {
391+ for (String [] testCase : MESSAGE_PATTERN_TEST_CASES ) {
392+ String result = JavaPropertiesResource .escapeMessagePattern (testCase [0 ], MessagePatternEscape .AUTO );
393+ assertEquals ("escapeMessagePattern (" + testCase [0 ] + ", AUTO)" , testCase [1 ], result );
400394 }
401395
402- for (String [] testCase : QUOTES_TEST_CASES ) {
403- String result = JavaPropertiesResource .ConvertSingleQuote (testCase [0 ], MessagePatternEscape .ALL );
404- assertEquals ("ConvertSingleQuote(" + testCase [0 ] + ", ALL)" , testCase [1 ], result );
405- }
406-
407- for (String [] testCase : TO_DOUBLE_AUTO_TEST_CASES ) {
408- String result = JavaPropertiesResource .ConvertSingleQuote (testCase [0 ], MessagePatternEscape .AUTO );
409- assertEquals ("ConvertSingleQuote(" + testCase [0 ] + ", AUTO)" , testCase [1 ], result );
410- }
411-
412- for (String [] testCase : TO_DOUBLE_ALL_TEST_CASES ) {
413- String result = JavaPropertiesResource .ConvertSingleQuote (testCase [0 ], MessagePatternEscape .ALL );
414- assertEquals ("ConvertSingleQuote(" + testCase [0 ] + ", ALL)" , testCase [1 ], result );
396+ for (String [] testCase : MESSAGE_PATTERN_TEST_CASES ) {
397+ String result = JavaPropertiesResource .escapeMessagePattern (testCase [0 ], MessagePatternEscape .ALL );
398+ String expected = testCase .length >= 3 && testCase [2 ] != null ? testCase [2 ] : testCase [1 ];
399+ assertEquals ("escapeMessagePattern(" + testCase [0 ] + ", ALL)" , expected , result );
415400 }
416401 }
417402
418403 @ Test
419- public void testConvertDoubleSingleQuoteAuto (){
420- for (String [] testCase : QUOTES_TEST_CASES ) {
421- String result = JavaPropertiesResource .ConvertDoubleSingleQuote (testCase [1 ], MessagePatternEscape .AUTO );
422- assertEquals ("ConvertDoubleSingleQuote(" + testCase [1 ] + ", AUTO)" , testCase [0 ], result );
423- }
424-
425- for (String [] testCase : QUOTES_TEST_CASES ) {
426- String result = JavaPropertiesResource .ConvertDoubleSingleQuote (testCase [1 ], MessagePatternEscape .ALL );
427- assertEquals ("ConvertDoubleSingleQuote(" + testCase [1 ] + ", ALL)" , testCase [0 ], result );
428- }
429-
430- for (String [] testCase : TO_SINGLE_AUTO_TEST_CASES ) {
431- String result = JavaPropertiesResource .ConvertDoubleSingleQuote (testCase [0 ], MessagePatternEscape .AUTO );
432- assertEquals ("ConvertDoubleSingleQuote(" + testCase [0 ] + ", AUTO)" , testCase [1 ], result );
404+ public void testUnescapeMessagePattern () throws ResourceFilterException {
405+ for (String [] testCase : MESSAGE_PATTERN_TEST_CASES ) {
406+ String result = JavaPropertiesResource .unescapeMessagePattern (testCase [1 ], MessagePatternEscape .AUTO );
407+ String expected = testCase .length >= 4 && testCase [3 ] != null ? testCase [3 ] : testCase [0 ];
408+ assertEquals ("unescapeMessagePattern(" + testCase [1 ] + ", AUTO)" , expected , result );
433409 }
434410
435- for (String [] testCase : TO_SINGLE_ALL_TEST_CASES ) {
436- String result = JavaPropertiesResource .ConvertDoubleSingleQuote (testCase [0 ], MessagePatternEscape .ALL );
437- assertEquals ("ConvertDoubleSingleQuote(" + testCase [0 ] + ", ALL)" , testCase [1 ], result );
411+ for (String [] testCase : MESSAGE_PATTERN_TEST_CASES ) {
412+ String input = testCase .length >= 3 && testCase [2 ] != null ? testCase [2 ] : testCase [1 ];
413+ String result = JavaPropertiesResource .unescapeMessagePattern (input , MessagePatternEscape .ALL );
414+ String expected = testCase .length >= 5 && testCase [4 ] != null ? testCase [4 ] : testCase [0 ];
415+ assertEquals ("unescapeMessagePattern(" + input + ", ALL)" , expected , result );
438416 }
439417 }
440-
418+
441419 @ Test
442420 public void testWriteAllQuotes () throws IOException , ResourceFilterException {
443421 File tempFile = File .createTempFile (this .getClass ().getSimpleName (), ".properties" );
0 commit comments