[macruby-changes] [1751] MacRuby/branches/experimental
source_changes at macosforge.org
source_changes at macosforge.org
Fri Jun 5 14:28:51 PDT 2009
Revision: 1751
http://trac.macosforge.org/projects/ruby/changeset/1751
Author: lsansonetti at apple.com
Date: 2009-06-05 14:28:49 -0700 (Fri, 05 Jun 2009)
Log Message:
-----------
String#capitalize: fixed 2 failing specs, re-enabling the spec again, tagging the remaining failing spec (common ByteString VS UTF16 string comparison issue)
Modified Paths:
--------------
MacRuby/branches/experimental/string.c
Added Paths:
-----------
MacRuby/branches/experimental/spec/frozen/core/string/capitalize_spec.rb
MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/capitalize_tags.txt
Removed Paths:
-------------
MacRuby/branches/experimental/spec/frozen/core/string/capitalize_spec_disabled.rb
Copied: MacRuby/branches/experimental/spec/frozen/core/string/capitalize_spec.rb (from rev 1748, MacRuby/branches/experimental/spec/frozen/core/string/capitalize_spec_disabled.rb)
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/capitalize_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/string/capitalize_spec.rb 2009-06-05 21:28:49 UTC (rev 1751)
@@ -0,0 +1,65 @@
+# -*- encoding: utf-8 -*-
+require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/fixtures/classes.rb'
+
+describe "String#capitalize" do
+ it "returns a copy of self with the first character converted to uppercase and the remainder to lowercase" do
+ "".capitalize.should == ""
+ "h".capitalize.should == "H"
+ "H".capitalize.should == "H"
+ "hello".capitalize.should == "Hello"
+ "HELLO".capitalize.should == "Hello"
+ "123ABC".capitalize.should == "123abc"
+ end
+
+ it "taints resulting string when self is tainted" do
+ "".taint.capitalize.tainted?.should == true
+ "hello".taint.capitalize.tainted?.should == true
+ end
+
+ it "is locale insensitive (only upcases a-z and only downcases A-Z)" do
+ "ÄÖÜ".capitalize.should == "ÄÖÜ"
+ "ärger".capitalize.should == "ärger"
+ "BÄR".capitalize.should == "BÄr"
+ end
+
+ it "returns subclass instances when called on a subclass" do
+ StringSpecs::MyString.new("hello").capitalize.class.should == StringSpecs::MyString
+ StringSpecs::MyString.new("Hello").capitalize.class.should == StringSpecs::MyString
+ end
+end
+
+describe "String#capitalize!" do
+ it "capitalizes self in place" do
+ a = "hello"
+ a.capitalize!.should equal(a)
+ a.should == "Hello"
+ end
+
+ it "returns nil when no changes are made" do
+ a = "Hello"
+ a.capitalize!.should == nil
+ a.should == "Hello"
+
+ "".capitalize!.should == nil
+ "H".capitalize!.should == nil
+ end
+
+ ruby_version_is ""..."1.9" do
+ it "raises a TypeError when self is frozen" do
+ ["", "Hello", "hello"].each do |a|
+ a.freeze
+ lambda { a.capitalize! }.should raise_error(TypeError)
+ end
+ end
+ end
+
+ ruby_version_is "1.9" do
+ it "raises a RuntimeError when self is frozen" do
+ ["", "Hello", "hello"].each do |a|
+ a.freeze
+ lambda { a.capitalize! }.should raise_error(RuntimeError)
+ end
+ end
+ end
+end
Deleted: MacRuby/branches/experimental/spec/frozen/core/string/capitalize_spec_disabled.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/capitalize_spec_disabled.rb 2009-06-05 21:11:09 UTC (rev 1750)
+++ MacRuby/branches/experimental/spec/frozen/core/string/capitalize_spec_disabled.rb 2009-06-05 21:28:49 UTC (rev 1751)
@@ -1,65 +0,0 @@
-# -*- encoding: utf-8 -*-
-require File.dirname(__FILE__) + '/../../spec_helper'
-require File.dirname(__FILE__) + '/fixtures/classes.rb'
-
-describe "String#capitalize" do
- it "returns a copy of self with the first character converted to uppercase and the remainder to lowercase" do
- "".capitalize.should == ""
- "h".capitalize.should == "H"
- "H".capitalize.should == "H"
- "hello".capitalize.should == "Hello"
- "HELLO".capitalize.should == "Hello"
- "123ABC".capitalize.should == "123abc"
- end
-
- it "taints resulting string when self is tainted" do
- "".taint.capitalize.tainted?.should == true
- "hello".taint.capitalize.tainted?.should == true
- end
-
- it "is locale insensitive (only upcases a-z and only downcases A-Z)" do
- "ÄÖÜ".capitalize.should == "ÄÖÜ"
- "ärger".capitalize.should == "ärger"
- "BÄR".capitalize.should == "BÄr"
- end
-
- it "returns subclass instances when called on a subclass" do
- StringSpecs::MyString.new("hello").capitalize.class.should == StringSpecs::MyString
- StringSpecs::MyString.new("Hello").capitalize.class.should == StringSpecs::MyString
- end
-end
-
-describe "String#capitalize!" do
- it "capitalizes self in place" do
- a = "hello"
- a.capitalize!.should equal(a)
- a.should == "Hello"
- end
-
- it "returns nil when no changes are made" do
- a = "Hello"
- a.capitalize!.should == nil
- a.should == "Hello"
-
- "".capitalize!.should == nil
- "H".capitalize!.should == nil
- end
-
- ruby_version_is ""..."1.9" do
- it "raises a TypeError when self is frozen" do
- ["", "Hello", "hello"].each do |a|
- a.freeze
- lambda { a.capitalize! }.should raise_error(TypeError)
- end
- end
- end
-
- ruby_version_is "1.9" do
- it "raises a RuntimeError when self is frozen" do
- ["", "Hello", "hello"].each do |a|
- a.freeze
- lambda { a.capitalize! }.should raise_error(RuntimeError)
- end
- end
- end
-end
Added: MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/capitalize_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/capitalize_tags.txt (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/capitalize_tags.txt 2009-06-05 21:28:49 UTC (rev 1751)
@@ -0,0 +1 @@
+fails:String#capitalize is locale insensitive (only upcases a-z and only downcases A-Z)
Property changes on: MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/capitalize_tags.txt
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: MacRuby/branches/experimental/string.c
===================================================================
--- MacRuby/branches/experimental/string.c 2009-06-05 21:11:09 UTC (rev 1750)
+++ MacRuby/branches/experimental/string.c 2009-06-05 21:28:49 UTC (rev 1751)
@@ -2772,23 +2772,25 @@
rb_str_modify(str);
n = CFStringGetLength((CFStringRef)str);
- if (n == 0)
+ if (n == 0) {
return Qnil;
+ }
buffer = (UniChar *)alloca(sizeof(UniChar) * n);
CFStringGetCharacters((CFStringRef)str, CFRangeMake(0, n), buffer);
changed = false;
- if (iswlower(buffer[0])) {
+ if (iswascii(buffer[0]) && iswlower(buffer[0])) {
buffer[0] = towupper(buffer[0]);
changed = true;
}
for (i = 1; i < n; i++) {
- if (iswupper(buffer[i])) {
+ if (iswascii(buffer[0]) && iswupper(buffer[i])) {
buffer[i] = towlower(buffer[i]);
changed = true;
}
}
- if (!changed)
+ if (!changed) {
return Qnil;
+ }
tmp = CFStringCreateWithCharacters(NULL, buffer, n);
CFStringReplaceAll((CFMutableStringRef)str, tmp);
CFRelease(tmp);
@@ -2812,7 +2814,7 @@
static VALUE
rb_str_capitalize(VALUE str, SEL sel)
{
- str = rb_str_dup(str);
+ str = rb_str_new3(str);
rb_str_capitalize_bang(str, 0);
return str;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090605/95114f75/attachment-0001.html>
More information about the macruby-changes
mailing list