[slf4j-dev] svn commit: r462 - in slf4j/trunk: src/java/org/slf4j/impl tests/src/java/org/slf4j/impl

ceki at slf4j.org ceki at slf4j.org
Tue Dec 20 20:26:22 CET 2005


Author: ceki
Date: Tue Dec 20 20:26:19 2005
New Revision: 462

Modified:
   slf4j/trunk/src/java/org/slf4j/impl/MessageFormatter.java
   slf4j/trunk/tests/src/java/org/slf4j/impl/MessageFormatterTest.java
Log:

-tests
- bug fixes

Modified: slf4j/trunk/src/java/org/slf4j/impl/MessageFormatter.java
==============================================================================
--- slf4j/trunk/src/java/org/slf4j/impl/MessageFormatter.java	(original)
+++ slf4j/trunk/src/java/org/slf4j/impl/MessageFormatter.java	Tue Dec 20 20:26:19 2005
@@ -91,11 +91,14 @@
     int len = messagePattern.length();
     int j = messagePattern.indexOf(DELIM_START);
     
-    char escape = 'x';
+  
     
     StringBuffer sbuf = new StringBuffer(messagePattern.length() + 50);
 
     for (int L = 0; L < argArray.length; L++) {
+      
+      char escape = 'x';
+      
       j = messagePattern.indexOf(DELIM_START, i);
 
       if (j == -1 || (j+1 == len)) {
@@ -113,7 +116,8 @@
         }
         
         if(escape == '\\') {
-          sbuf.append(messagePattern.substring(i, j));
+          L--; // DELIM_START was escaped, thus should not be incremented
+          sbuf.append(messagePattern.substring(i, j-1));
           sbuf.append(DELIM_START);
           i = j + 1;
         } else if ((delimStop != DELIM_STOP)) {

Modified: slf4j/trunk/tests/src/java/org/slf4j/impl/MessageFormatterTest.java
==============================================================================
--- slf4j/trunk/tests/src/java/org/slf4j/impl/MessageFormatterTest.java	(original)
+++ slf4j/trunk/tests/src/java/org/slf4j/impl/MessageFormatterTest.java	Tue Dec 20 20:26:19 2005
@@ -44,6 +44,14 @@
  */
 public class MessageFormatterTest extends TestCase {
   
+  public void testNull() {
+    String result;
+    Integer i3 = new Integer(3);
+    
+    result = MessageFormatter.format(null, i3);
+    assertEquals(null, result);
+  }
+  
   public void test1Param() {
     String result;
     Integer i3 = new Integer(3);
@@ -67,13 +75,13 @@
     assertEquals("Incorrect {subst", result);
     
     result = MessageFormatter.format("Escaped \\{} subst", i3);
-    assertEquals("Escaped \\{} subst", result);
+    assertEquals("Escaped {} subst", result);
 
     result = MessageFormatter.format("\\{Escaped", i3);
-    assertEquals("\\{Escaped", result);
+    assertEquals("{Escaped", result);
 
     result = MessageFormatter.format("\\{}Escaped", i3);
-    assertEquals("\\{}Escaped", result);
+    assertEquals("{}Escaped", result);
   }
   
   public void test2Param() {
@@ -89,7 +97,28 @@
     
     result = MessageFormatter.format("{}{}", i1, i2);
     assertEquals("12", result);
+    
     result = MessageFormatter.format("Val1={}, Val2={", i1, i2);
     assertEquals("Val1=1, Val2={", result);
+
+    result = MessageFormatter.format("Value {} is larger than \\{}", i1, i2);
+    assertEquals("Value 1 is larger than {}", result);
+    
+    result = MessageFormatter.format("Value {} is larger than \\{} tail", i1, i2);
+    assertEquals("Value 1 is larger than {} tail", result);    
+
+    result = MessageFormatter.format("Value {} is larger than \\{", i1, i2);
+    assertEquals("Value 1 is larger than \\{", result);  
+    
+    result = MessageFormatter.format("Value {} is larger than \\{tail", i1, i2);
+    assertEquals("Value 1 is larger than {tail", result);  
+  
+    
+    result = MessageFormatter.format("Value \\{} is larger than {}", i1, i2);
+    assertEquals("Value {} is larger than 1", result);    
+
+  
   }
+  
+
 }



More information about the slf4j-dev mailing list