public void TestTooFewArgumentValues() { SimpleFormatter fmt = SimpleFormatter.Compile( "Templates {2}{1} and {4} are out of order."); try { fmt.Format("freddy", "tommy", "frog", "leg"); fail("Expected IllegalArgumentException"); } catch (ArgumentException e) { // Expected } try { fmt.FormatAndAppend( new StringBuilder(), null, "freddy", "tommy", "frog", "leg"); fail("Expected IllegalArgumentException"); } catch (ArgumentException e) { // Expected } try { fmt.FormatAndReplace( new StringBuilder(), null, "freddy", "tommy", "frog", "leg"); fail("Expected IllegalArgumentException"); } catch (ArgumentException e) { // Expected } }
public void TestFormatReplaceNoOptimizationNoOffsets() { SimpleFormatter fmt = SimpleFormatter.Compile( "Arguments {0} and {1}"); StringBuilder result = new StringBuilder("previous:"); assertEquals( "", "Arguments previous: and frog", fmt.FormatAndReplace(result, null, result.ToString(), "frog").ToString()); }
public void TestFormatReplaceOptimizationNoOffsets() { SimpleFormatter fmt = SimpleFormatter.Compile("{2}, {0}, {1} and {3}"); StringBuilder result = new StringBuilder("original"); assertEquals( "format", "original, freddy, frog and by", fmt.FormatAndReplace( result, null, "freddy", "frog", result.ToString(), "by").ToString()); }
public void TestFormatReplaceNoOptimizationLeadingArgumentUsedTwice() { SimpleFormatter fmt = SimpleFormatter.Compile( "{2}, {0}, {1} and {3} {2}"); StringBuilder result = new StringBuilder("original"); int[] offsets = new int[4]; assertEquals( "", "original, freddy, frog and by original", fmt.FormatAndReplace( result, offsets, "freddy", "frog", result.ToString(), "by").ToString()); int[] expectedOffsets = { 10, 18, 30, 27 }; verifyOffsets(expectedOffsets, offsets); }
public void TestFormatReplaceNoOptimizationLeadingText() { SimpleFormatter fmt = SimpleFormatter.Compile("boo {2}, {0}, {1} and {3}"); int[] offsets = new int[4]; StringBuilder result = new StringBuilder("original"); assertEquals( "format", "boo original, freddy, frog and by", fmt.FormatAndReplace( result, offsets, "freddy", "frog", result.ToString(), "by").ToString()); int[] expectedOffsets = { 14, 22, 4, 31 }; verifyOffsets(expectedOffsets, offsets); }
public void TestWithNoArguments() { SimpleFormatter fmt = SimpleFormatter.Compile("This doesn''t have templates '{0}"); assertEquals( "getArgumentLimit", 0, fmt.ArgumentLimit); assertEquals( "format", "This doesn't have templates {0}", fmt.Format("unused")); assertEquals( "format with values=null", "This doesn't have templates {0}", fmt.Format((ICharSequence[])null)); assertEquals( "toString", "This doesn't have templates {0}", fmt.ToString()); int[] offsets = new int[1]; assertEquals( "formatAndAppend", "This doesn't have templates {0}", fmt.FormatAndAppend(new StringBuilder(), offsets).ToString()); assertEquals( "offsets[0]", -1, offsets[0]); assertEquals( "formatAndAppend with values=null", "This doesn't have templates {0}", fmt.FormatAndAppend(new StringBuilder(), null, (ICharSequence[])null).ToString()); assertEquals( "formatAndReplace with values=null", "This doesn't have templates {0}", fmt.FormatAndReplace(new StringBuilder(), null, (ICharSequence[])null).ToString()); }