Skip to content

Commit

Permalink
Fixed test to verify the case of encoding preservation
Browse files Browse the repository at this point in the history
  • Loading branch information
andsel committed Jan 28, 2025
1 parent 226a0d7 commit 3a090a0
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.logstash.common;

import org.jruby.RubyArray;
import org.jruby.RubyEncoding;
import org.jruby.RubyString;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
Expand Down Expand Up @@ -91,16 +92,16 @@ public void shouldTokenizeEmptyPayloadWithNewline() {

@Test
public void shouldNotChangeEncodingOfTokensAfterPartitioning() {
// RubyString rubyString = RubyString.newString(RUBY, new byte[]{(byte) 0xA3}); // £ character
RubyString rubyString = RubyString.newString(RUBY, new byte[]{(byte) 0xA3, 0x0A, 0x41}); // £ character, newline, A
IRubyObject rubyInput = rubyString.force_encoding(context, RUBY.newString("ISO8859-1"));
RubyArray<RubyString> tokens = (RubyArray<RubyString>)sut.extract(context, rubyInput);
IRubyObject firstToken = tokens.shift(context);

// IRubyObject token = sut.flush(context);

// assertEquals((byte) 0xA3, token.asJavaString().getBytes()[0]);
// assertEquals("£", token.asJavaString());
// read the first token, the £ string
IRubyObject firstToken = tokens.shift(context);
assertEquals("£", firstToken.toString());

// verify encoding "ISO8859-1" is preserved in the Java to Ruby String conversion
RubyEncoding encoding = (RubyEncoding) firstToken.callMethod(context, "encoding");
assertEquals("ISO8859-1", encoding.toString());
}
}

0 comments on commit 3a090a0

Please sign in to comment.