@Test public void testNewCharacterBuffer() { CharacterBuffer newCharacterBuffer = CharacterUtils.newCharacterBuffer(1024); assertEquals(1024, newCharacterBuffer.getBuffer().length); assertEquals(0, newCharacterBuffer.getOffset()); assertEquals(0, newCharacterBuffer.getLength()); newCharacterBuffer = CharacterUtils.newCharacterBuffer(2); assertEquals(2, newCharacterBuffer.getBuffer().length); assertEquals(0, newCharacterBuffer.getOffset()); assertEquals(0, newCharacterBuffer.getLength()); try { newCharacterBuffer = CharacterUtils.newCharacterBuffer(1); fail("length must be >= 2"); } catch (IllegalArgumentException e) { } }
@Test public void testFillNoHighSurrogate() throws IOException { Version[] versions = new Version[] { Version.LUCENE_3_0, TEST_VERSION_CURRENT }; for (Version version : versions) { CharacterUtils instance = CharacterUtils.getInstance(version); Reader reader = new StringReader("helloworld"); CharacterBuffer buffer = CharacterUtils.newCharacterBuffer(6); assertTrue(instance.fill(buffer,reader)); assertEquals(0, buffer.getOffset()); assertEquals(6, buffer.getLength()); assertEquals("hellow", new String(buffer.getBuffer())); assertFalse(instance.fill(buffer,reader)); assertEquals(4, buffer.getLength()); assertEquals(0, buffer.getOffset()); assertEquals("orld", new String(buffer.getBuffer(), buffer.getOffset(), buffer.getLength())); assertFalse(instance.fill(buffer,reader)); } }
@Test public void testFillJava15() throws IOException { String input = "1234\ud801\udc1c789123\ud801\ud801\udc1c\ud801"; CharacterUtils instance = CharacterUtils.getInstance(); Reader reader = new StringReader(input); CharacterBuffer buffer = CharacterUtils.newCharacterBuffer(5); assertTrue(instance.fill(buffer, reader)); assertEquals(4, buffer.getLength()); assertEquals("1234", new String(buffer.getBuffer(), buffer.getOffset(), buffer.getLength())); assertTrue(instance.fill(buffer, reader)); assertEquals(5, buffer.getLength()); assertEquals("\ud801\udc1c789", new String(buffer.getBuffer())); assertTrue(instance.fill(buffer, reader)); assertEquals(4, buffer.getLength()); assertEquals("123\ud801", new String(buffer.getBuffer(), buffer.getOffset(), buffer.getLength())); assertFalse(instance.fill(buffer, reader)); assertEquals(3, buffer.getLength()); assertEquals("\ud801\udc1c\ud801", new String(buffer.getBuffer(), buffer .getOffset(), buffer.getLength())); assertFalse(instance.fill(buffer, reader)); assertEquals(0, buffer.getLength()); }
@Test public void testFillJava14() throws IOException { String input = "1234\ud801\udc1c789123\ud801\ud801\udc1c\ud801"; CharacterUtils instance = CharacterUtils.getInstance(Version.LUCENE_3_0); Reader reader = new StringReader(input); CharacterBuffer buffer = CharacterUtils.newCharacterBuffer(5); assertTrue(instance.fill(buffer, reader)); assertEquals(5, buffer.getLength()); assertEquals("1234\ud801", new String(buffer.getBuffer(), buffer .getOffset(), buffer.getLength())); assertTrue(instance.fill(buffer, reader)); assertEquals(5, buffer.getLength()); assertEquals("\udc1c7891", new String(buffer.getBuffer())); buffer = CharacterUtils.newCharacterBuffer(6); assertTrue(instance.fill(buffer, reader)); assertEquals(6, buffer.getLength()); assertEquals("23\ud801\ud801\udc1c\ud801", new String(buffer.getBuffer(), buffer .getOffset(), buffer.getLength())); assertFalse(instance.fill(buffer, reader)); }
@Test public void testFillNoHighSurrogate() throws IOException { Version[] versions = new Version[] { Version.LUCENE_30, TEST_VERSION_CURRENT }; for (Version version : versions) { CharacterUtils instance = CharacterUtils.getInstance(version); Reader reader = new StringReader("helloworld"); CharacterBuffer buffer = CharacterUtils.newCharacterBuffer(6); assertTrue(instance.fill(buffer,reader)); assertEquals(0, buffer.getOffset()); assertEquals(6, buffer.getLength()); assertEquals("hellow", new String(buffer.getBuffer())); assertTrue(instance.fill(buffer,reader)); assertEquals(4, buffer.getLength()); assertEquals(0, buffer.getOffset()); assertEquals("orld", new String(buffer.getBuffer(), buffer.getOffset(), buffer.getLength())); assertFalse(instance.fill(buffer,reader)); } }
@Test public void testFillJava14() throws IOException { String input = "1234\ud801\udc1c789123\ud801\ud801\udc1c\ud801"; CharacterUtils instance = CharacterUtils.getInstance(Version.LUCENE_30); Reader reader = new StringReader(input); CharacterBuffer buffer = CharacterUtils.newCharacterBuffer(5); assertTrue(instance.fill(buffer, reader)); assertEquals(5, buffer.getLength()); assertEquals("1234\ud801", new String(buffer.getBuffer(), buffer .getOffset(), buffer.getLength())); assertTrue(instance.fill(buffer, reader)); assertEquals(5, buffer.getLength()); assertEquals("\udc1c7891", new String(buffer.getBuffer())); buffer = CharacterUtils.newCharacterBuffer(6); assertTrue(instance.fill(buffer, reader)); assertEquals(6, buffer.getLength()); assertEquals("23\ud801\ud801\udc1c\ud801", new String(buffer.getBuffer(), buffer .getOffset(), buffer.getLength())); assertFalse(instance.fill(buffer, reader)); }
@Test public void testFillNoHighSurrogate() throws IOException { Version[] versions = new Version[] { Version.LUCENE_30, TEST_VERSION_CURRENT }; for (Version version : versions) { CharacterUtils instance = CharacterUtils.getInstance(version); Reader reader = new StringReader("helloworld"); CharacterBuffer buffer = CharacterUtils.newCharacterBuffer(6); assertTrue(instance.fill(buffer,reader)); assertEquals(0, buffer.getOffset()); assertEquals(6, buffer.getLength()); assertEquals("hellow", new String(buffer.getBuffer())); assertFalse(instance.fill(buffer,reader)); assertEquals(4, buffer.getLength()); assertEquals(0, buffer.getOffset()); assertEquals("orld", new String(buffer.getBuffer(), buffer.getOffset(), buffer.getLength())); assertFalse(instance.fill(buffer,reader)); } }
@Test public void testFillJava15() throws IOException { String input = "1234\ud801\udc1c789123\ud801\ud801\udc1c\ud801"; CharacterUtils instance = CharacterUtils.getInstance(TEST_VERSION_CURRENT); Reader reader = new StringReader(input); CharacterBuffer buffer = CharacterUtils.newCharacterBuffer(5); assertTrue(instance.fill(buffer, reader)); assertEquals(4, buffer.getLength()); assertEquals("1234", new String(buffer.getBuffer(), buffer.getOffset(), buffer.getLength())); assertTrue(instance.fill(buffer, reader)); assertEquals(5, buffer.getLength()); assertEquals("\ud801\udc1c789", new String(buffer.getBuffer())); assertTrue(instance.fill(buffer, reader)); assertEquals(4, buffer.getLength()); assertEquals("123\ud801", new String(buffer.getBuffer(), buffer.getOffset(), buffer.getLength())); assertFalse(instance.fill(buffer, reader)); assertEquals(3, buffer.getLength()); assertEquals("\ud801\udc1c\ud801", new String(buffer.getBuffer(), buffer .getOffset(), buffer.getLength())); assertFalse(instance.fill(buffer, reader)); assertEquals(0, buffer.getLength()); }
@Test public void testFillJava15() throws IOException { String input = "1234\ud801\udc1c789123\ud801\ud801\udc1c\ud801"; CharacterUtils instance = CharacterUtils.getInstance(TEST_VERSION_CURRENT); Reader reader = new StringReader(input); CharacterBuffer buffer = CharacterUtils.newCharacterBuffer(5); assertTrue(instance.fill(buffer, reader)); assertEquals(4, buffer.getLength()); assertEquals("1234", new String(buffer.getBuffer(), buffer.getOffset(), buffer.getLength())); assertTrue(instance.fill(buffer, reader)); assertEquals(5, buffer.getLength()); assertEquals("\ud801\udc1c789", new String(buffer.getBuffer())); assertTrue(instance.fill(buffer, reader)); assertEquals(4, buffer.getLength()); assertEquals("123\ud801", new String(buffer.getBuffer(), buffer.getOffset(), buffer.getLength())); assertTrue(instance.fill(buffer, reader)); assertEquals(2, buffer.getLength()); assertEquals("\ud801\udc1c", new String(buffer.getBuffer(), buffer .getOffset(), buffer.getLength())); assertTrue(instance.fill(buffer, reader)); assertEquals(1, buffer.getLength()); assertEquals("\ud801", new String(buffer.getBuffer(), buffer .getOffset(), buffer.getLength())); assertFalse(instance.fill(buffer, reader)); }