aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/string_ext_test.rb
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2008-02-16 00:02:30 +0000
committerMichael Koziarski <michael@koziarski.com>2008-02-16 00:02:30 +0000
commit4ff26f51f61f9bf7d0bb34557e72c1280ee4f859 (patch)
tree9ce2f97947ecc132937a26c517df4594379a9179 /activesupport/test/core_ext/string_ext_test.rb
parent191ffc94568ca22885eac7001cae7fef452dcfdd (diff)
downloadrails-4ff26f51f61f9bf7d0bb34557e72c1280ee4f859.tar.gz
rails-4ff26f51f61f9bf7d0bb34557e72c1280ee4f859.tar.bz2
rails-4ff26f51f61f9bf7d0bb34557e72c1280ee4f859.zip
Add String#squish and String#squish! to remove consecutive chunks of whitespace. Closes #11123 [jordi, Henrik N]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8878 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test/core_ext/string_ext_test.rb')
-rw-r--r--activesupport/test/core_ext/string_ext_test.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb
index e1525d6170..19a30f1730 100644
--- a/activesupport/test/core_ext/string_ext_test.rb
+++ b/activesupport/test/core_ext/string_ext_test.rb
@@ -168,6 +168,23 @@ class StringInflectionsTest < Test::Unit::TestCase
assert !s.end_with?('el')
end
+ def test_string_squish
+ original = %{ A string with tabs(\t\t), newlines(\n\n), and
+ many spaces( ). }
+
+ expected = "A string with tabs( ), newlines( ), and many spaces( )."
+
+ # Make sure squish returns what we expect:
+ assert_equal original.squish, expected
+ # But doesn't modify the original string:
+ assert_not_equal original, expected
+
+ # Make sure squish! returns what we expect:
+ assert_equal original.squish!, expected
+ # And changes the original string:
+ assert_equal original, expected
+ end
+
if RUBY_VERSION < '1.9'
def test_each_char_with_utf8_string_when_kcode_is_utf8
old_kcode, $KCODE = $KCODE, 'UTF8'