Cleaned up code supporting Ruby < 2.0
diff --git a/lib/rb/spec/binary_protocol_spec_shared.rb b/lib/rb/spec/binary_protocol_spec_shared.rb
index c83f5ae..d8edf85 100644
--- a/lib/rb/spec/binary_protocol_spec_shared.rb
+++ b/lib/rb/spec/binary_protocol_spec_shared.rb
@@ -38,25 +38,25 @@
it "should make strict_write readable" do
expect(@prot.strict_write).to eql(true)
- end
+ end
it "should write the message header" do
@prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
expect(@trans.read(@trans.available)).to eq([protocol_class.const_get(:VERSION_1) | Thrift::MessageTypes::CALL, "testMessage".size, "testMessage", 17].pack("NNa11N"))
end
-
+
it "should write the message header without version when writes are not strict" do
@prot = protocol_class.new(@trans, true, false) # no strict write
@prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
expect(@trans.read(@trans.available)).to eq("\000\000\000\vtestMessage\001\000\000\000\021")
end
-
+
it "should write the message header with a version when writes are strict" do
@prot = protocol_class.new(@trans) # strict write
@prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
expect(@trans.read(@trans.available)).to eq("\200\001\000\001\000\000\000\vtestMessage\000\000\000\021")
end
-
+
# message footer is a noop
@@ -64,44 +64,44 @@
@prot.write_field_begin('foo', Thrift::Types::DOUBLE, 3)
expect(@trans.read(@trans.available)).to eq([Thrift::Types::DOUBLE, 3].pack("cn"))
end
-
+
# field footer is a noop
-
+
it "should write the STOP field" do
@prot.write_field_stop
expect(@trans.read(1)).to eq("\000")
end
-
+
it "should write the map header" do
@prot.write_map_begin(Thrift::Types::STRING, Thrift::Types::LIST, 17)
expect(@trans.read(@trans.available)).to eq([Thrift::Types::STRING, Thrift::Types::LIST, 17].pack("ccN"));
end
-
+
# map footer is a noop
-
+
it "should write the list header" do
@prot.write_list_begin(Thrift::Types::I16, 42)
expect(@trans.read(@trans.available)).to eq([Thrift::Types::I16, 42].pack("cN"))
end
-
+
# list footer is a noop
-
+
it "should write the set header" do
@prot.write_set_begin(Thrift::Types::I16, 42)
expect(@trans.read(@trans.available)).to eq([Thrift::Types::I16, 42].pack("cN"))
end
-
+
it "should write a bool" do
@prot.write_bool(true)
@prot.write_bool(false)
expect(@trans.read(@trans.available)).to eq("\001\000")
end
-
+
it "should treat a nil bool as false" do
@prot.write_bool(nil)
expect(@trans.read(1)).to eq("\000")
end
-
+
it "should write a byte" do
# byte is small enough, let's check -128..127
(-128..127).each do |i|
@@ -120,11 +120,11 @@
it "errors out with a Bignum" do
expect { @prot.write_byte(2**65) }.to raise_error(RangeError)
end
-
+
it "should error gracefully when trying to write a nil byte" do
expect { @prot.write_byte(nil) }.to raise_error(StandardError, 'nil argument not allowed!')
end
-
+
it "should write an i16" do
# try a random scattering of values
# include the signed i16 minimum/maximum
@@ -133,17 +133,17 @@
end
# and try something out of signed range, it should clip
@prot.write_i16(2**15 + 5)
-
+
expect(@trans.read(@trans.available)).to eq("\200\000\374\000\000\021\000\000\330\360\006\273\177\377\200\005")
-
+
# a Bignum should error
# lambda { @prot.write_i16(2**65) }.should raise_error(RangeError)
end
-
+
it "should error gracefully when trying to write a nil i16" do
expect { @prot.write_i16(nil) }.to raise_error(StandardError, 'nil argument not allowed!')
end
-
+
it "should write an i32" do
# try a random scattering of values
# include the signed i32 minimum/maximum
@@ -153,14 +153,14 @@
# try something out of signed range, it should clip
expect(@trans.read(@trans.available)).to eq("\200\000\000\000" + "\377\376\037\r" + "\377\377\366\034" + "\377\377\377\375" + "\000\000\000\000" + "\000#\340\203" + "\000\0000+" + "\177\377\377\377")
[2 ** 31 + 5, 2 ** 65 + 5].each do |i|
- expect { @prot.write_i32(i) }.to raise_error(RangeError)
+ expect { @prot.write_i32(i) }.to raise_error(RangeError)
end
end
-
+
it "should error gracefully when trying to write a nil i32" do
expect { @prot.write_i32(nil) }.to raise_error(StandardError, 'nil argument not allowed!')
end
-
+
it "should write an i64" do
# try a random scattering of values
# try the signed i64 minimum/maximum
@@ -179,11 +179,11 @@
"\177\377\377\377\377\377\377\377"].join(""))
expect { @prot.write_i64(2 ** 65 + 5) }.to raise_error(RangeError)
end
-
+
it "should error gracefully when trying to write a nil i64" do
expect { @prot.write_i64(nil) }.to raise_error(StandardError, 'nil argument not allowed!')
end
-
+
it "should write a double" do
# try a random scattering of values, including min/max
values = [Float::MIN,-1231.15325, -123123.23, -23.23515123, 0, 12351.1325, 523.23, Float::MAX]
@@ -192,58 +192,42 @@
expect(@trans.read(@trans.available)).to eq([f].pack("G"))
end
end
-
+
it "should error gracefully when trying to write a nil double" do
expect { @prot.write_double(nil) }.to raise_error(StandardError, 'nil argument not allowed!')
end
- if RUBY_VERSION >= '1.9'
- it 'should write a string' do
- str = 'abc'
- @prot.write_string(str)
- a = @trans.read(@trans.available)
- expect(a.encoding).to eq(Encoding::BINARY)
- expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63])
- end
+ it 'should write a string' do
+ str = 'abc'
+ @prot.write_string(str)
+ a = @trans.read(@trans.available)
+ expect(a.encoding).to eq(Encoding::BINARY)
+ expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63])
+ end
- it 'should write a string with unicode characters' do
- str = "abc \u20AC \u20AD".encode('UTF-8')
- @prot.write_string(str)
- a = @trans.read(@trans.available)
- expect(a.encoding).to eq(Encoding::BINARY)
- expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x0B, 0x61, 0x62, 0x63, 0x20,
- 0xE2, 0x82, 0xAC, 0x20, 0xE2, 0x82, 0xAD])
- end
+ it 'should write a string with unicode characters' do
+ str = "abc \u20AC \u20AD".encode('UTF-8')
+ @prot.write_string(str)
+ a = @trans.read(@trans.available)
+ expect(a.encoding).to eq(Encoding::BINARY)
+ expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x0B, 0x61, 0x62, 0x63, 0x20,
+ 0xE2, 0x82, 0xAC, 0x20, 0xE2, 0x82, 0xAD])
+ end
- it 'should write should write a string with unicode characters and transcoding' do
- str = "abc \u20AC".encode('ISO-8859-15')
- @prot.write_string(str)
- a = @trans.read(@trans.available)
- expect(a.encoding).to eq(Encoding::BINARY)
- expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x07, 0x61, 0x62, 0x63, 0x20, 0xE2, 0x82, 0xAC])
- end
+ it 'should write should write a string with unicode characters and transcoding' do
+ str = "abc \u20AC".encode('ISO-8859-15')
+ @prot.write_string(str)
+ a = @trans.read(@trans.available)
+ expect(a.encoding).to eq(Encoding::BINARY)
+ expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x07, 0x61, 0x62, 0x63, 0x20, 0xE2, 0x82, 0xAC])
+ end
- it 'should write a binary string' do
- buffer = [0, 1, 2, 3].pack('C*')
- @prot.write_binary(buffer)
- a = @trans.read(@trans.available)
- expect(a.encoding).to eq(Encoding::BINARY)
- expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x02, 0x03])
- end
- else
- it 'should write a string' do
- str = 'abc'
- @prot.write_string(str)
- a = @trans.read(@trans.available)
- expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63])
- end
-
- it 'should write a binary string' do
- buffer = [0, 1, 2, 3].pack('C*')
- @prot.write_binary(buffer)
- a = @trans.read(@trans.available)
- expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x02, 0x03])
- end
+ it 'should write a binary string' do
+ buffer = [0, 1, 2, 3].pack('C*')
+ @prot.write_binary(buffer)
+ a = @trans.read(@trans.available)
+ expect(a.encoding).to eq(Encoding::BINARY)
+ expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x02, 0x03])
end
it "should error gracefully when trying to write a nil string" do
@@ -300,36 +284,36 @@
@trans.write([Thrift::Types::DOUBLE, Thrift::Types::I64, 42].pack("ccN"))
expect(@prot.read_map_begin).to eq([Thrift::Types::DOUBLE, Thrift::Types::I64, 42])
end
-
+
# map footer is a noop
-
+
it "should read a list header" do
@trans.write([Thrift::Types::STRING, 17].pack("cN"))
expect(@prot.read_list_begin).to eq([Thrift::Types::STRING, 17])
end
-
+
# list footer is a noop
-
+
it "should read a set header" do
@trans.write([Thrift::Types::STRING, 17].pack("cN"))
expect(@prot.read_set_begin).to eq([Thrift::Types::STRING, 17])
end
-
+
# set footer is a noop
-
+
it "should read a bool" do
@trans.write("\001\000");
expect(@prot.read_bool).to eq(true)
expect(@prot.read_bool).to eq(false)
end
-
+
it "should read a byte" do
[-128, -57, -3, 0, 17, 24, 127].each do |i|
@trans.write([i].pack("c"))
expect(@prot.read_byte).to eq(i)
end
end
-
+
it "should read an i16" do
# try a scattering of values, including min/max
[-2**15, -5237, -353, 0, 1527, 2234, 2**15-1].each do |i|
@@ -337,7 +321,7 @@
expect(@prot.read_i16).to eq(i)
end
end
-
+
it "should read an i32" do
# try a scattering of values, including min/max
[-2**31, -235125, -6236, 0, 2351, 123123, 2**31-1].each do |i|
@@ -345,7 +329,7 @@
expect(@prot.read_i32).to eq(i)
end
end
-
+
it "should read an i64" do
# try a scattering of values, including min/max
[-2**63, -123512312, -6346, 0, 32, 2346322323, 2**63-1].each do |i|
@@ -353,7 +337,7 @@
expect(@prot.read_i64).to eq(i)
end
end
-
+
it "should read a double" do
# try a random scattering of values, including min/max
[Float::MIN, -231231.12351, -323.233513, 0, 123.2351235, 2351235.12351235, Float::MAX].each do |f|
@@ -362,46 +346,30 @@
end
end
- if RUBY_VERSION >= '1.9'
- it 'should read a string' do
- # i32 of value 3, followed by three characters/UTF-8 bytes 'a', 'b', 'c'
- buffer = [0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63].pack('C*')
- @trans.write(buffer)
- a = @prot.read_string
- expect(a).to eq('abc'.encode('UTF-8'))
- expect(a.encoding).to eq(Encoding::UTF_8)
- end
+ it 'should read a string' do
+ # i32 of value 3, followed by three characters/UTF-8 bytes 'a', 'b', 'c'
+ buffer = [0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63].pack('C*')
+ @trans.write(buffer)
+ a = @prot.read_string
+ expect(a).to eq('abc'.encode('UTF-8'))
+ expect(a.encoding).to eq(Encoding::UTF_8)
+ end
- it 'should read a string containing unicode characters from UTF-8 encoded buffer' do
- # i32 of value 3, followed by one character U+20AC made up of three bytes
- buffer = [0x00, 0x00, 0x00, 0x03, 0xE2, 0x82, 0xAC].pack('C*')
- @trans.write(buffer)
- a = @prot.read_string
- expect(a).to eq("\u20AC".encode('UTF-8'))
- expect(a.encoding).to eq(Encoding::UTF_8)
- end
+ it 'should read a string containing unicode characters from UTF-8 encoded buffer' do
+ # i32 of value 3, followed by one character U+20AC made up of three bytes
+ buffer = [0x00, 0x00, 0x00, 0x03, 0xE2, 0x82, 0xAC].pack('C*')
+ @trans.write(buffer)
+ a = @prot.read_string
+ expect(a).to eq("\u20AC".encode('UTF-8'))
+ expect(a.encoding).to eq(Encoding::UTF_8)
+ end
- it 'should read a binary string' do
- buffer = [0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x02, 0x03].pack('C*')
- @trans.write(buffer)
- a = @prot.read_binary
- expect(a).to eq([0x00, 0x01, 0x02, 0x03].pack('C*'))
- expect(a.encoding).to eq(Encoding::BINARY)
- end
- else
- it 'should read a string' do
- # i32 of value 3, followed by three characters/UTF-8 bytes 'a', 'b', 'c'
- buffer = [0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63].pack('C*')
- @trans.write(buffer)
- expect(@prot.read_string).to eq('abc')
- end
-
- it 'should read a binary string' do
- buffer = [0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x02, 0x03].pack('C*')
- @trans.write(buffer)
- a = @prot.read_binary
- expect(a).to eq([0x00, 0x01, 0x02, 0x03].pack('C*'))
- end
+ it 'should read a binary string' do
+ buffer = [0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x02, 0x03].pack('C*')
+ @trans.write(buffer)
+ a = @prot.read_binary
+ expect(a).to eq([0x00, 0x01, 0x02, 0x03].pack('C*'))
+ expect(a.encoding).to eq(Encoding::BINARY)
end
it "should perform a complete rpc with no args or return" do
@@ -433,7 +401,7 @@
def get_socket_connection
server = Thrift::ServerSocket.new("localhost", 9090)
server.listen
-
+
clientside = Thrift::Socket.new("localhost", 9090)
clientside.open
serverside = server.accept
@@ -463,14 +431,14 @@
server.close
end
- class SrvHandler
+ class SrvHandler
def voidMethod()
end
-
+
def primitiveMethod
1
end
-
+
def structMethod
Fixtures::COMPACT_PROTOCOL_TEST_STRUCT
end
diff --git a/lib/rb/spec/bytes_spec.rb b/lib/rb/spec/bytes_spec.rb
index 2e8653c..c3ec087 100644
--- a/lib/rb/spec/bytes_spec.rb
+++ b/lib/rb/spec/bytes_spec.rb
@@ -21,140 +21,79 @@
require 'spec_helper'
describe Thrift::Bytes do
- if RUBY_VERSION >= '1.9'
- describe '.empty_byte_buffer' do
- it 'should create an empty buffer' do
- b = Thrift::Bytes.empty_byte_buffer
- expect(b.length).to eq(0)
- expect(b.encoding).to eq(Encoding::BINARY)
- end
-
- it 'should create an empty buffer of given size' do
- b = Thrift::Bytes.empty_byte_buffer 2
- expect(b.length).to eq(2)
- expect(b.getbyte(0)).to eq(0)
- expect(b.getbyte(1)).to eq(0)
- expect(b.encoding).to eq(Encoding::BINARY)
- end
+ describe '.empty_byte_buffer' do
+ it 'should create an empty buffer' do
+ b = Thrift::Bytes.empty_byte_buffer
+ expect(b.length).to eq(0)
+ expect(b.encoding).to eq(Encoding::BINARY)
end
- describe '.force_binary_encoding' do
- it 'should change encoding' do
- e = 'STRING'.encode('UTF-8')
- expect(e.encoding).not_to eq(Encoding::BINARY)
- a = Thrift::Bytes.force_binary_encoding e
- expect(a.encoding).to eq(Encoding::BINARY)
- end
+ it 'should create an empty buffer of given size' do
+ b = Thrift::Bytes.empty_byte_buffer 2
+ expect(b.length).to eq(2)
+ expect(b.getbyte(0)).to eq(0)
+ expect(b.getbyte(1)).to eq(0)
+ expect(b.encoding).to eq(Encoding::BINARY)
+ end
+ end
+
+ describe '.force_binary_encoding' do
+ it 'should change encoding' do
+ e = 'STRING'.encode('UTF-8')
+ expect(e.encoding).not_to eq(Encoding::BINARY)
+ a = Thrift::Bytes.force_binary_encoding e
+ expect(a.encoding).to eq(Encoding::BINARY)
+ end
+ end
+
+ describe '.get_string_byte' do
+ it 'should get the byte at index' do
+ s = "\x41\x42"
+ expect(Thrift::Bytes.get_string_byte(s, 0)).to eq(0x41)
+ expect(Thrift::Bytes.get_string_byte(s, 1)).to eq(0x42)
+ end
+ end
+
+ describe '.set_string_byte' do
+ it 'should set byte value at index' do
+ s = "\x41\x42"
+ Thrift::Bytes.set_string_byte(s, 0, 0x43)
+ expect(s.getbyte(0)).to eq(0x43)
+ expect(s).to eq('CB')
+ end
+ end
+
+ describe '.convert_to_utf8_byte_buffer' do
+ it 'should convert UTF-8 String to byte buffer' do
+ e = "\u20AC".encode('UTF-8') # a string with euro sign character U+20AC
+ expect(e.length).to eq(1)
+
+ a = Thrift::Bytes.convert_to_utf8_byte_buffer e
+ expect(a.encoding).to eq(Encoding::BINARY)
+ expect(a.length).to eq(3)
+ expect(a.unpack('C*')).to eq([0xE2, 0x82, 0xAC])
end
- describe '.get_string_byte' do
- it 'should get the byte at index' do
- s = "\x41\x42"
- expect(Thrift::Bytes.get_string_byte(s, 0)).to eq(0x41)
- expect(Thrift::Bytes.get_string_byte(s, 1)).to eq(0x42)
- end
+ it 'should convert ISO-8859-15 String to UTF-8 byte buffer' do
+ # Assumptions
+ e = "\u20AC".encode('ISO-8859-15') # a string with euro sign character U+20AC, then converted to ISO-8859-15
+ expect(e.length).to eq(1)
+ expect(e.unpack('C*')).to eq([0xA4]) # euro sign is a different code point in ISO-8859-15
+
+ a = Thrift::Bytes.convert_to_utf8_byte_buffer e
+ expect(a.encoding).to eq(Encoding::BINARY)
+ expect(a.length).to eq(3)
+ expect(a.unpack('C*')).to eq([0xE2, 0x82, 0xAC])
end
+ end
- describe '.set_string_byte' do
- it 'should set byte value at index' do
- s = "\x41\x42"
- Thrift::Bytes.set_string_byte(s, 0, 0x43)
- expect(s.getbyte(0)).to eq(0x43)
- expect(s).to eq('CB')
- end
- end
-
- describe '.convert_to_utf8_byte_buffer' do
- it 'should convert UTF-8 String to byte buffer' do
- e = "\u20AC".encode('UTF-8') # a string with euro sign character U+20AC
- expect(e.length).to eq(1)
-
- a = Thrift::Bytes.convert_to_utf8_byte_buffer e
- expect(a.encoding).to eq(Encoding::BINARY)
- expect(a.length).to eq(3)
- expect(a.unpack('C*')).to eq([0xE2, 0x82, 0xAC])
- end
-
- it 'should convert ISO-8859-15 String to UTF-8 byte buffer' do
- # Assumptions
- e = "\u20AC".encode('ISO-8859-15') # a string with euro sign character U+20AC, then converted to ISO-8859-15
- expect(e.length).to eq(1)
- expect(e.unpack('C*')).to eq([0xA4]) # euro sign is a different code point in ISO-8859-15
-
- a = Thrift::Bytes.convert_to_utf8_byte_buffer e
- expect(a.encoding).to eq(Encoding::BINARY)
- expect(a.length).to eq(3)
- expect(a.unpack('C*')).to eq([0xE2, 0x82, 0xAC])
- end
- end
-
- describe '.convert_to_string' do
- it 'should convert UTF-8 byte buffer to a UTF-8 String' do
- e = [0xE2, 0x82, 0xAC].pack("C*")
- expect(e.encoding).to eq(Encoding::BINARY)
- a = Thrift::Bytes.convert_to_string e
- expect(a.encoding).to eq(Encoding::UTF_8)
- expect(a).to eq("\u20AC")
- end
- end
-
- else # RUBY_VERSION
- describe '.empty_byte_buffer' do
- it 'should create an empty buffer' do
- b = Thrift::Bytes.empty_byte_buffer
- expect(b.length).to eq(0)
- end
-
- it 'should create an empty buffer of given size' do
- b = Thrift::Bytes.empty_byte_buffer 2
- expect(b.length).to eq(2)
- expect(b[0]).to eq(0)
- expect(b[1]).to eq(0)
- end
- end
-
- describe '.force_binary_encoding' do
- it 'should be a no-op' do
- e = 'STRING'
- a = Thrift::Bytes.force_binary_encoding e
- expect(a).to eq(e)
- expect(a).to be(e)
- end
- end
-
- describe '.get_string_byte' do
- it 'should get the byte at index' do
- s = "\x41\x42"
- expect(Thrift::Bytes.get_string_byte(s, 0)).to eq(0x41)
- expect(Thrift::Bytes.get_string_byte(s, 1)).to eq(0x42)
- end
- end
-
- describe '.set_string_byte' do
- it 'should set byte value at index' do
- s = "\x41\x42"
- Thrift::Bytes.set_string_byte(s, 0, 0x43)
- expect(s[0]).to eq(0x43)
- expect(s).to eq('CB')
- end
- end
-
- describe '.convert_to_utf8_byte_buffer' do
- it 'should be a no-op' do
- e = 'STRING'
- a = Thrift::Bytes.convert_to_utf8_byte_buffer e
- expect(a).to eq(e)
- expect(a).to be(e)
- end
- end
-
- describe '.convert_to_string' do
- it 'should be a no-op' do
- e = 'STRING'
- a = Thrift::Bytes.convert_to_string e
- expect(a).to eq(e)
- expect(a).to be(e)
- end
+ describe '.convert_to_string' do
+ it 'should convert UTF-8 byte buffer to a UTF-8 String' do
+ e = [0xE2, 0x82, 0xAC].pack("C*")
+ expect(e.encoding).to eq(Encoding::BINARY)
+ a = Thrift::Bytes.convert_to_string e
+ expect(a.encoding).to eq(Encoding::UTF_8)
+ expect(a).to eq("\u20AC")
end
end
end
diff --git a/lib/rb/spec/json_protocol_spec.rb b/lib/rb/spec/json_protocol_spec.rb
index 9acaf86..e53fd3e 100644
--- a/lib/rb/spec/json_protocol_spec.rb
+++ b/lib/rb/spec/json_protocol_spec.rb
@@ -221,25 +221,18 @@
expect(@trans.read(@trans.available)).to eq("\"-Infinity\"")
end
- if RUBY_VERSION >= '1.9'
- it 'should write string' do
- @prot.write_string('this is a test string')
- a = @trans.read(@trans.available)
- expect(a).to eq('"this is a test string"'.force_encoding(Encoding::BINARY))
- expect(a.encoding).to eq(Encoding::BINARY)
- end
+ it 'should write string' do
+ @prot.write_string('this is a test string')
+ a = @trans.read(@trans.available)
+ expect(a).to eq('"this is a test string"'.force_encoding(Encoding::BINARY))
+ expect(a.encoding).to eq(Encoding::BINARY)
+ end
- it 'should write string with unicode characters' do
- @prot.write_string("this is a test string with unicode characters: \u20AC \u20AD")
- a = @trans.read(@trans.available)
- expect(a).to eq("\"this is a test string with unicode characters: \u20AC \u20AD\"".force_encoding(Encoding::BINARY))
- expect(a.encoding).to eq(Encoding::BINARY)
- end
- else
- it 'should write string' do
- @prot.write_string('this is a test string')
- expect(@trans.read(@trans.available)).to eq('"this is a test string"')
- end
+ it 'should write string with unicode characters' do
+ @prot.write_string("this is a test string with unicode characters: \u20AC \u20AD")
+ a = @trans.read(@trans.available)
+ expect(a).to eq("\"this is a test string with unicode characters: \u20AC \u20AD\"".force_encoding(Encoding::BINARY))
+ expect(a.encoding).to eq(Encoding::BINARY)
end
it "should write binary" do
@@ -509,25 +502,18 @@
expect(@prot.read_double).to eq(12.23)
end
- if RUBY_VERSION >= '1.9'
- it 'should read string' do
- @trans.write('"this is a test string"'.force_encoding(Encoding::BINARY))
- a = @prot.read_string
- expect(a).to eq('this is a test string')
- expect(a.encoding).to eq(Encoding::UTF_8)
- end
+ it 'should read string' do
+ @trans.write('"this is a test string"'.force_encoding(Encoding::BINARY))
+ a = @prot.read_string
+ expect(a).to eq('this is a test string')
+ expect(a.encoding).to eq(Encoding::UTF_8)
+ end
- it 'should read string with unicode characters' do
- @trans.write('"this is a test string with unicode characters: \u20AC \u20AD"'.force_encoding(Encoding::BINARY))
- a = @prot.read_string
- expect(a).to eq("this is a test string with unicode characters: \u20AC \u20AD")
- expect(a.encoding).to eq(Encoding::UTF_8)
- end
- else
- it 'should read string' do
- @trans.write('"this is a test string"')
- expect(@prot.read_string).to eq('this is a test string')
- end
+ it 'should read string with unicode characters' do
+ @trans.write('"this is a test string with unicode characters: \u20AC \u20AD"'.force_encoding(Encoding::BINARY))
+ a = @prot.read_string
+ expect(a).to eq("this is a test string with unicode characters: \u20AC \u20AD")
+ expect(a.encoding).to eq(Encoding::UTF_8)
end
it "should read binary" do