1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-25 22:53:22 +00:00

Fix term.blit failing on substrings

Hahah. Serves me right for trying to optimise too much. Fixes #1123.
This commit is contained in:
Jonathan Coates 2022-07-02 16:47:43 +01:00
parent 4e438df9ad
commit 56f0e0674f
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
2 changed files with 19 additions and 1 deletions

View File

@ -47,13 +47,15 @@ public void write( String text, int start )
public void write( ByteBuffer text, int start )
{
int pos = start;
int bufferPos = text.position();
start = Math.max( start, 0 );
int length = text.remaining();
int end = Math.min( start + length, pos + length );
end = Math.min( end, this.text.length );
for( int i = start; i < end; i++ )
{
this.text[i] = (char) (text.get( i - pos ) & 0xFF);
this.text[i] = (char) (text.get( bufferPos + i - pos ) & 0xFF);
}
}

View File

@ -14,9 +14,12 @@
import org.hamcrest.Matcher;
import org.junit.jupiter.api.Test;
import java.nio.ByteBuffer;
import static dan200.computercraft.core.terminal.TerminalMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.jupiter.api.Assertions.*;
class TerminalTest
@ -366,6 +369,19 @@ void testBlitOutOfBounds()
callCounter.assertNotCalled();
}
@Test
public void testBlitPartialBuffer()
{
Terminal terminal = new Terminal( 4, 3 );
ByteBuffer text = LuaValues.encode( "123456" );
text.position( 1 );
terminal.blit( text, LuaValues.encode( "aaaaaa" ), LuaValues.encode( "aaaaaa" ) );
assertThat( terminal.getLine( 0 ).toString(), equalTo( "2345" ) );
}
@Test
void testWriteFromOrigin()
{