@@ -104,4 +104,44 @@ public void shouldNotChangeEncodingOfTokensAfterPartitioning() {
104
104
RubyEncoding encoding = (RubyEncoding ) firstToken .callMethod (context , "encoding" );
105
105
assertEquals ("ISO-8859-1" , encoding .toString ());
106
106
}
107
+
108
+ @ Test
109
+ public void shouldNotChangeEncodingOfTokensAfterPartitioningInCaseMultipleExtractionInInvoked () {
110
+ RubyString rubyString = RubyString .newString (RUBY , new byte []{(byte ) 0xA3 }); // £ character
111
+ IRubyObject rubyInput = rubyString .force_encoding (context , RUBY .newString ("ISO8859-1" ));
112
+ sut .extract (context , rubyInput );
113
+ IRubyObject capitalAInLatin1 = RubyString .newString (RUBY , new byte []{(byte ) 0x41 })
114
+ .force_encoding (context , RUBY .newString ("ISO8859-1" ));
115
+ RubyArray <RubyString > tokens = (RubyArray <RubyString >)sut .extract (context , capitalAInLatin1 );
116
+ assertTrue (tokens .isEmpty ());
117
+
118
+ tokens = (RubyArray <RubyString >)sut .extract (context , RubyString .newString (RUBY , new byte []{(byte ) 0x0A }));
119
+
120
+ // read the first token, the £ string
121
+ IRubyObject firstToken = tokens .shift (context );
122
+ assertEquals ("£A" , firstToken .toString ());
123
+
124
+ // verify encoding "ISO8859-1" is preserved in the Java to Ruby String conversion
125
+ RubyEncoding encoding = (RubyEncoding ) firstToken .callMethod (context , "encoding" );
126
+ assertEquals ("ISO-8859-1" , encoding .toString ());
127
+ }
128
+
129
+ @ Test
130
+ public void shouldNotChangeEncodingOfTokensAfterPartitioningWhenRetrieveLastFlushedToken () {
131
+ RubyString rubyString = RubyString .newString (RUBY , new byte []{(byte ) 0xA3 , 0x0A , 0x41 }); // £ character, newline, A
132
+ IRubyObject rubyInput = rubyString .force_encoding (context , RUBY .newString ("ISO8859-1" ));
133
+ RubyArray <RubyString > tokens = (RubyArray <RubyString >)sut .extract (context , rubyInput );
134
+
135
+ // read the first token, the £ string
136
+ IRubyObject firstToken = tokens .shift (context );
137
+ assertEquals ("£" , firstToken .toString ());
138
+
139
+ // flush and check that the remaining A is still encoded in ISO8859-1
140
+ IRubyObject lastToken = sut .flush (context );
141
+ assertEquals ("A" , lastToken .toString ());
142
+
143
+ // verify encoding "ISO8859-1" is preserved in the Java to Ruby String conversion
144
+ RubyEncoding encoding = (RubyEncoding ) lastToken .callMethod (context , "encoding" );
145
+ assertEquals ("ISO-8859-1" , encoding .toString ());
146
+ }
107
147
}
0 commit comments