From: <kp...@us...> - 2023-10-03 11:13:05
|
Revision: 25689 http://sourceforge.net/p/jedit/svn/25689 Author: kpouer Date: 2023-10-03 11:13:02 +0000 (Tue, 03 Oct 2023) Log Message: ----------- Add some unit test for #4125 Modified Paths: -------------- jEdit/trunk/org/gjt/sp/jedit/textarea/TextArea.java Added Paths: ----------- jEdit/trunk/test/org/gjt/sp/jedit/textarea/LineCharacterBreakerTest.java Modified: jEdit/trunk/org/gjt/sp/jedit/textarea/TextArea.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/textarea/TextArea.java 2023-10-01 22:43:12 UTC (rev 25688) +++ jEdit/trunk/org/gjt/sp/jedit/textarea/TextArea.java 2023-10-03 11:13:02 UTC (rev 25689) @@ -367,7 +367,7 @@ * view.getTextArea().getBuffer(). * */ - public final JEditBuffer getBuffer() + public JEditBuffer getBuffer() { return buffer; } //}}} @@ -1260,7 +1260,7 @@ * Returns the line containing the specified offset. * @param offset The offset */ - public final int getLineOfOffset(int offset) + public int getLineOfOffset(int offset) { return buffer.getLineOfOffset(offset); } //}}} @@ -6292,7 +6292,7 @@ //{{{ LineCharacterBreaker class // Shared context among some operations which are aware of // characters above BMP and combining character sequence. - private static class LineCharacterBreaker + public static class LineCharacterBreaker { private final BreakIterator charBreaker; private final int index0Offset; @@ -6301,7 +6301,7 @@ { final int line = textArea.getLineOfOffset(offset); charBreaker = BreakIterator.getCharacterInstance(); - charBreaker.setText(new CharIterator(textArea.buffer.getLineSegment(line))); + charBreaker.setText(new CharIterator(textArea.getBuffer().getLineSegment(line))); index0Offset = textArea.getLineStartOffset(line); } @@ -6314,7 +6314,7 @@ { int following = charBreaker.following(offset - index0Offset); - if (following == BreakIterator.DONE) + if (following == BreakIterator.DONE || (Runtime.version().feature() >= 20 && following == offset - index0Offset)) { // This means a end of line. Then it is // safe to assume 1 code unit is a character. Added: jEdit/trunk/test/org/gjt/sp/jedit/textarea/LineCharacterBreakerTest.java =================================================================== --- jEdit/trunk/test/org/gjt/sp/jedit/textarea/LineCharacterBreakerTest.java (rev 0) +++ jEdit/trunk/test/org/gjt/sp/jedit/textarea/LineCharacterBreakerTest.java 2023-10-03 11:13:02 UTC (rev 25689) @@ -0,0 +1,71 @@ +/* + * jEdit - Programmer's Text Editor + * :tabSize=8:indentSize=8:noTabs=false: + * :folding=explicit:collapseFolds=1: + * + * Copyright © 2023 jEdit contributors + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +package org.gjt.sp.jedit.textarea; + +import org.gjt.sp.jedit.buffer.JEditBuffer; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.internal.util.Primitives; +import org.mockito.junit.MockitoJUnitRunner; + +import static org.junit.jupiter.api.Assertions.*; + +@RunWith(MockitoJUnitRunner.class) +public class LineCharacterBreakerTest { + @Mock + private TextArea textArea; + @Mock + private JEditBuffer buffer; + + @Before + public void setUp() throws Exception { + Mockito.reset(textArea, buffer); + } + + @Test + public void testNextOf() { + var line = 10; + var integerArgumentCaptor = ArgumentCaptor.forClass(Primitives.primitiveTypeOf(int.class)); + Mockito.when(textArea.getLineOfOffset(integerArgumentCaptor.capture())).thenReturn(line); + Mockito.when(textArea.getBuffer()).thenReturn(buffer); + Mockito.when(buffer.getLineSegment(line)).thenReturn("732K /run"); + Mockito.when(textArea.getLineStartOffset(line)).thenReturn(136); + var breaker = new TextArea.LineCharacterBreaker(textArea, 148); + assertEquals(149, breaker.nextOf(148)); + } + + @Test + public void testPreviousOf() { + var line = 10; + var integerArgumentCaptor = ArgumentCaptor.forClass(Primitives.primitiveTypeOf(int.class)); + Mockito.when(textArea.getLineOfOffset(integerArgumentCaptor.capture())).thenReturn(line); + Mockito.when(textArea.getBuffer()).thenReturn(buffer); + Mockito.when(buffer.getLineSegment(line)).thenReturn("732K /run"); + Mockito.when(textArea.getLineStartOffset(line)).thenReturn(136); + var breaker = new TextArea.LineCharacterBreaker(textArea, 148); + assertEquals(136, breaker.previousOf(137)); + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |