Skip to content

Commit

Permalink
Add spec for 1.9 rb_str_length
Browse files Browse the repository at this point in the history
  • Loading branch information
dbussink committed Sep 28, 2012
1 parent 7c140e5 commit 03502d9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions spec/ruby/optional/capi/ext/rubyspec.h
Expand Up @@ -447,6 +447,9 @@
#define HAVE_RB_STR_INSPECT 1
#define HAVE_RB_STR_INTERN 1
#define HAVE_RB_STR_LEN 1
#ifdef RUBY_VERSION_IS_1_9
#define HAVE_RB_STR_LENGTH 1
#endif
#define HAVE_RB_STR_NEW 1
#define HAVE_RB_STR_NEW2 1
#define HAVE_RB_STR_NEW3 1
Expand Down
10 changes: 10 additions & 0 deletions spec/ruby/optional/capi/ext/string_spec.c
Expand Up @@ -149,6 +149,12 @@ VALUE string_spec_rb_str_len(VALUE self, VALUE str) {
}
#endif

#ifdef HAVE_RB_STR_LENGTH
VALUE string_spec_rb_str_length(VALUE self, VALUE str) {
return rb_str_length(str);
}
#endif

#ifdef HAVE_RB_STR_NEW
VALUE string_spec_rb_str_new(VALUE self, VALUE str, VALUE len) {
return rb_str_new(RSTRING_PTR(str), FIX2INT(len));
Expand Down Expand Up @@ -535,6 +541,10 @@ void Init_string_spec() {
rb_define_method(cls, "rb_str_len", string_spec_rb_str_len, 1);
#endif

#ifdef HAVE_RB_STR_LENGTH
rb_define_method(cls, "rb_str_length", string_spec_rb_str_length, 1);
#endif

#ifdef HAVE_RB_STR_NEW
rb_define_method(cls, "rb_str_new", string_spec_rb_str_new, 2);
#endif
Expand Down
15 changes: 15 additions & 0 deletions spec/ruby/optional/capi/string_spec.rb
@@ -1,3 +1,4 @@
# encoding: UTF-8
require File.expand_path('../spec_helper', __FILE__)

load_extension('string')
Expand Down Expand Up @@ -564,6 +565,20 @@ def to_str
@s.rb_str_len("dewdrops").should == 8
end
end

ruby_version_is "1.9" do

describe "rb_str_length" do
it "returns the string's length" do
@s.rb_str_length("dewdrops").should == 8
end

it "counts characters in multi byte encodings" do
@s.rb_str_length("düwdrops").should == 8
end
end
end

end
end

Expand Down

0 comments on commit 03502d9

Please sign in to comment.