| 1 32 package net.sf.retrotranslator.runtime.java.lang; 33 34 import junit.framework.TestCase; 35 36 39 public class _StringBufferTestCase extends TestCase { 40 41 public void testConvertConstructorArguments() throws Exception { 42 CharSequence sequence = "abc"; 43 assertEquals("abc", new StringBuffer (sequence).toString()); 44 sequence = null; 45 try { 46 new StringBuilder (sequence); 47 fail(); 48 } catch (NullPointerException e) { 49 } 51 } 52 53 public void testAppend() throws Exception { 54 CharSequence sequence = "xyz"; 55 assertEquals("abcxyz", new StringBuffer ("abc").append(sequence).toString()); 56 assertEquals("abcy", new StringBuilder ("abc").append(sequence, 1, 2).toString()); 57 } 58 59 public void testAppendCodePoint() throws Exception { 60 assertEquals("abc", new StringBuffer ("a").appendCodePoint('b').append('c').toString()); 61 assertEquals("a\uD834\uDD1Eb", new StringBuffer ("a").appendCodePoint(0x1D11E).append('b').toString()); 62 try { 63 new StringBuffer ().appendCodePoint(-1); 64 fail(); 65 } catch (IllegalArgumentException e) { 66 } 68 } 69 70 public void testCodePointAt() throws Exception { 71 assertEquals('b', new StringBuffer ("ab").codePointAt(1)); 72 assertEquals(0x1D11E, new StringBuffer ("b\uD834\uDD1Ec").codePointAt(1)); 73 assertEquals(0xD834, new StringBuffer ("b\uD834").codePointAt(1)); 74 try { 75 new StringBuffer ("abc").codePointAt(-1); 76 fail(); 77 } catch (IndexOutOfBoundsException e) { 78 } 80 try { 81 new StringBuffer ("abc").codePointAt(3); 82 fail(); 83 } catch (IndexOutOfBoundsException e) { 84 } 86 } 87 88 public void testCodePointBefore() throws Exception { 89 assertEquals('a', new StringBuffer ("ab").codePointBefore(1)); 90 assertEquals(0x1D11E, new StringBuffer ("b\uD834\uDD1Ec").codePointBefore(3)); 91 assertEquals(0xDD1E, new StringBuffer ("\uDD1E").codePointBefore(1)); 92 try { 93 new StringBuffer ("abc").codePointBefore(0); 94 fail(); 95 } catch (IndexOutOfBoundsException e) { 96 } 98 try { 99 new StringBuffer ("abc").codePointBefore(4); 100 fail(); 101 } catch (IndexOutOfBoundsException e) { 102 } 104 } 105 106 public void testCodePointCount() throws Exception { 107 assertEquals(2, new StringBuffer ("abcd").codePointCount(1, 3)); 108 assertEquals(3, new StringBuffer ("b\uD834\uDD1Ec").codePointCount(0, 4)); 109 assertEquals(2, new StringBuffer ("b\uD834\uDD1Ec").codePointCount(0, 2)); 110 assertEquals(2, new StringBuffer ("b\uD834").codePointCount(0, 2)); 111 try { 112 new StringBuffer ("abc").codePointCount(-1, 1); 113 fail(); 114 } catch (IndexOutOfBoundsException e) { 115 } 117 try { 118 new StringBuffer ("abc").codePointCount(1, 0); 119 fail(); 120 } catch (IndexOutOfBoundsException e) { 121 } 123 try { 124 new StringBuffer ("abc").codePointCount(5, 5); 125 fail(); 126 } catch (IndexOutOfBoundsException e) { 127 } 129 try { 130 new StringBuffer ("abc").codePointCount(1, 5); 131 fail(); 132 } catch (IndexOutOfBoundsException e) { 133 } 135 } 136 137 public void testInsert() throws Exception { 138 CharSequence sequence = "xyz"; 139 assertEquals("axyzbc", new StringBuffer ("abc").insert(1, sequence).toString()); 140 assertEquals("aybc", new StringBuilder ("abc").insert(1, sequence, 1, 2).toString()); 141 } 142 143 public void testOffsetByCodePoints() throws Exception { 144 assertEquals(3, new StringBuffer ("abc").offsetByCodePoints(1, 2)); 145 assertEquals(1, new StringBuffer ("abc").offsetByCodePoints(1, 0)); 146 assertEquals(3, new StringBuffer ("b\uD834\uDD1Ec").offsetByCodePoints(0, 2)); 147 try { 148 new StringBuffer ("abc").offsetByCodePoints(-1, 1); 149 fail(); 150 } catch (IndexOutOfBoundsException e) { 151 } 153 try { 154 new StringBuffer ("abc").offsetByCodePoints(10, 0); 155 fail(); 156 } catch (IndexOutOfBoundsException e) { 157 } 159 try { 160 new StringBuffer ("abc").offsetByCodePoints(0, 5); 161 fail(); 162 } catch (IndexOutOfBoundsException e) { 163 } 165 try { 166 new StringBuffer ("abc").offsetByCodePoints(2, -5); 167 fail(); 168 } catch (IndexOutOfBoundsException e) { 169 } 171 } 172 173 } | Popular Tags |