Permalink
Browse files

- #4 fix: capitalization of an empty string

  • Loading branch information...
1 parent f9e0bd8 commit 8b43b6a043ea0d08c6c89bdbfb057fb718e03d7a @apohllo committed Feb 27, 2012
Showing with 20 additions and 2 deletions.
  1. +2 −2 lib/string_case_pl.rb
  2. +18 −0 test/test_character_case_change.rb
View
@@ -56,8 +56,8 @@ def upcase
def capitalize
s = self.dup
- s[0] = s[0].upcase
- s[1..-1] = s[1..-1].downcase
+ s[0..0] = s[0..0].upcase
+ s[1..-1] = s[1..-1].downcase if s[1]
s
end
@@ -146,4 +146,22 @@ def test_capitalize!
assert_equal(copy.capitalize!, nil)
end
+ def test_empty_string_capitalize
+ empty_string = ""
+ empty_string_copy = empty_string.dup
+ assert_equal(empty_string_copy,empty_string.capitalize)
+ end
+
+ def test_empty_string_capitalize!
+ empty_string = ""
+ empty_string.capitalize!
+ assert_equal(empty_string,"")
+ end
+
+ def test_one_letter_capitalize
+ one_letter = "ą"
+ assert_equal(one_letter.capitalize,"Ą")
+ one_letter = "Ą"
+ assert_equal(one_letter.capitalize,"Ą")
+ end
end

0 comments on commit 8b43b6a

Please sign in to comment.