Skip to content
Browse files

Add specs for rb_str_equal

  • Loading branch information...
1 parent 3919947 commit e518867be56e178bf328f18ecfe1228b8e637d37 @dbussink dbussink committed Sep 28, 2012
View
1 spec/ruby/optional/capi/ext/rubyspec.h
@@ -449,6 +449,7 @@
#define HAVE_RB_STR_LEN 1
#ifdef RUBY_VERSION_IS_1_9
#define HAVE_RB_STR_LENGTH 1
+#define HAVE_RB_STR_EQUAL 1
#endif
#define HAVE_RB_STR_NEW 1
#define HAVE_RB_STR_NEW2 1
View
10 spec/ruby/optional/capi/ext/string_spec.c
@@ -457,6 +457,12 @@ static VALUE string_spec_rb_str_hash(VALUE self, VALUE str) {
}
#endif
+#ifdef HAVE_RB_STR_EQUAL
+VALUE string_spec_rb_str_equal(VALUE self, VALUE str1, VALUE str2) {
+ return rb_str_equal(str1, str2);
+}
+#endif
+
#ifdef HAVE_RB_USASCII_STR_NEW
static VALUE string_spec_rb_usascii_str_new(VALUE self, VALUE str, VALUE len) {
return rb_usascii_str_new(RSTRING_PTR(str), NUM2INT(len));
@@ -665,6 +671,10 @@ void Init_string_spec() {
rb_define_method(cls, "rb_str_hash", string_spec_rb_str_hash, 1);
#endif
+#ifdef HAVE_RB_STR_EQUAL
+ rb_define_method(cls, "rb_str_equal", string_spec_rb_str_equal, 2);
+#endif
+
#ifdef HAVE_RB_USASCII_STR_NEW
rb_define_method(cls, "rb_usascii_str_new", string_spec_rb_usascii_str_new, 2);
#endif
View
12 spec/ruby/optional/capi/string_spec.rb
@@ -580,6 +580,18 @@ def to_str
end
end
+ describe "rb_str_equal" do
+ it "compares two same strings" do
+ s = "hello"
+ @s.rb_str_equal(s, "hello").should be_true
+ end
+
+ it "compares two different strings" do
+ s = "hello"
+ @s.rb_str_equal(s, "hella").should be_false
+ end
+ end
+
describe :rb_external_str_new, :shared => true do
it "returns a String in the default external encoding" do
Encoding.default_external = "UTF-8"

0 comments on commit e518867

Please sign in to comment.
Something went wrong with that request. Please try again.