Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add spec for 1.9 rb_str_length

  • Loading branch information...
commit 03502d9910d778207696bfe51af3f93eedac9a64 1 parent 7c140e5
@dbussink dbussink authored
View
3  spec/ruby/optional/capi/ext/rubyspec.h
@@ -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
View
10 spec/ruby/optional/capi/ext/string_spec.c
@@ -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));
@@ -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
View
15 spec/ruby/optional/capi/string_spec.rb
@@ -1,3 +1,4 @@
+# encoding: UTF-8
require File.expand_path('../spec_helper', __FILE__)
load_extension('string')
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.