@@ -32,43 +32,45 @@ def to_str
32
32
end
33
33
end
34
34
35
- describe "rb_str_set_len" do
36
- before :each do
37
- # Make a completely new copy of the string
38
- # for every example (#dup doesn't cut it).
39
- @str = "abcdefghij" . b [ 0 ..-1 ]
40
- end
35
+ [ Encoding ::BINARY , Encoding ::UTF_8 ] . each do |enc |
36
+ describe "rb_str_set_len on a #{ enc . name } String" do
37
+ before :each do
38
+ # Make a completely new copy of the string
39
+ # for every example (#dup doesn't cut it).
40
+ @str = "abcdefghij" . force_encoding ( enc ) [ 0 ..-1 ]
41
+ end
41
42
42
- it "reduces the size of the string" do
43
- @s . rb_str_set_len ( @str , 5 ) . should == "abcde"
44
- end
43
+ it "reduces the size of the string" do
44
+ @s . rb_str_set_len ( @str , 5 ) . should == "abcde"
45
+ end
45
46
46
- it "inserts a NULL byte at the length" do
47
- @s . rb_str_set_len ( @str , 5 ) . should == "abcde"
48
- @s . rb_str_set_len ( @str , 8 ) . should == "abcde\x00 gh"
49
- end
47
+ it "inserts a NULL byte at the length" do
48
+ @s . rb_str_set_len ( @str , 5 ) . should == "abcde"
49
+ @s . rb_str_set_len ( @str , 8 ) . should == "abcde\x00 gh"
50
+ end
50
51
51
- it "updates the byte size and character size" do
52
- @s . rb_str_set_len ( @str , 4 )
53
- @str . bytesize . should == 4
54
- @str . size . should == 4
55
- @str . should == "abcd"
56
- end
52
+ it "updates the byte size and character size" do
53
+ @s . rb_str_set_len ( @str , 4 )
54
+ @str . bytesize . should == 4
55
+ @str . size . should == 4
56
+ @str . should == "abcd"
57
+ end
57
58
58
- it "updates the string's attributes visible in C code" do
59
- @s . rb_str_set_len_RSTRING_LEN ( @str , 4 ) . should == 4
60
- end
59
+ it "updates the string's attributes visible in C code" do
60
+ @s . rb_str_set_len_RSTRING_LEN ( @str , 4 ) . should == 4
61
+ end
61
62
62
- it "can reveal characters written from C with RSTRING_PTR" do
63
- @s . rb_str_set_len ( @str , 1 )
64
- @str . should == "a"
63
+ it "can reveal characters written from C with RSTRING_PTR" do
64
+ @s . rb_str_set_len ( @str , 1 )
65
+ @str . should == "a"
65
66
66
- @s . RSTRING_PTR_set ( @str , 1 , 'B' . ord )
67
- @s . RSTRING_PTR_set ( @str , 2 , 'C' . ord )
68
- @s . rb_str_set_len ( @str , 3 )
67
+ @s . RSTRING_PTR_set ( @str , 1 , 'B' . ord )
68
+ @s . RSTRING_PTR_set ( @str , 2 , 'C' . ord )
69
+ @s . rb_str_set_len ( @str , 3 )
69
70
70
- @str . bytesize . should == 3
71
- @str . should == "aBC"
71
+ @str . bytesize . should == 3
72
+ @str . should == "aBC"
73
+ end
72
74
end
73
75
end
74
76
0 commit comments