From d73f32ce0004ddb1a8470ed50c9f8323ebc5613f Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Fri, 13 Oct 2006 20:27:46 +0000 Subject: make sure the String::Access methods return strings, and not multibyte Char instances git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5299 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/test/core_ext/string_ext_test.rb | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index 47f772ab9b..7eff505a22 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -84,6 +84,33 @@ class StringInflectionsTest < Test::Unit::TestCase assert_equal 'x', 'x'.last(4) end + def test_access_returns_a_real_string + hash = {} + hash["h"] = true + hash["hello123".at(0)] = true + assert_equal %w(h), hash.keys + + hash = {} + hash["llo"] = true + hash["hello".from(2)] = true + assert_equal %w(llo), hash.keys + + hash = {} + hash["hel"] = true + hash["hello".to(2)] = true + assert_equal %w(hel), hash.keys + + hash = {} + hash["hello"] = true + hash["123hello".last(5)] = true + assert_equal %w(hello), hash.keys + + hash = {} + hash["hello"] = true + hash["hello123".first(5)] = true + assert_equal %w(hello), hash.keys + end + def test_starts_ends_with s = "hello" assert s.starts_with?('h') -- cgit v1.2.3