@@ -97,6 +97,32 @@ def inspect
97
97
end
98
98
end
99
99
100
+ describe "rb_str_set_len on a UTF-16 String" do
101
+ before :each do
102
+ @str = "abcdefghij" . force_encoding ( Encoding ::UTF_16BE )
103
+ # Make sure to unshare the string
104
+ @s . rb_str_modify ( @str )
105
+ end
106
+
107
+ it "inserts two NULL bytes at the length" do
108
+ @s . rb_str_set_len ( @str , 4 ) . b . should == "abcd" . b
109
+ @s . rb_str_set_len ( @str , 8 ) . b . should == "abcd\x00 \x00 gh" . b
110
+ end
111
+ end
112
+
113
+ describe "rb_str_set_len on a UTF-32 String" do
114
+ before :each do
115
+ @str = "abcdefghijkl" . force_encoding ( Encoding ::UTF_32BE )
116
+ # Make sure to unshare the string
117
+ @s . rb_str_modify ( @str )
118
+ end
119
+
120
+ it "inserts four NULL bytes at the length" do
121
+ @s . rb_str_set_len ( @str , 4 ) . b . should == "abcd" . b
122
+ @s . rb_str_set_len ( @str , 12 ) . b . should == "abcd\x00 \x00 \x00 \x00 ijkl" . b
123
+ end
124
+ end
125
+
100
126
describe "rb_str_buf_new" do
101
127
it "returns the equivalent of an empty string" do
102
128
buf = @s . rb_str_buf_new ( 10 , nil )
@@ -592,6 +618,12 @@ def inspect
592
618
capacities [ 0 ] . should < capacities [ 1 ]
593
619
str . should == "fixture file contents to test read() with RSTRING_PTR"
594
620
end
621
+
622
+ it "terminates the string with at least (encoding min length) \\ 0 bytes" do
623
+ @s . RSTRING_PTR_null_terminate ( "abc" , 1 ) . should == "\x00 "
624
+ @s . RSTRING_PTR_null_terminate ( "abc" . encode ( "UTF-16BE" ) , 2 ) . should == "\x00 \x00 "
625
+ @s . RSTRING_PTR_null_terminate ( "abc" . encode ( "UTF-32BE" ) , 4 ) . should == "\x00 \x00 \x00 \x00 "
626
+ end
595
627
end
596
628
597
629
describe "RSTRING_LEN" do
0 commit comments