From 4ff26f51f61f9bf7d0bb34557e72c1280ee4f859 Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Sat, 16 Feb 2008 00:02:30 +0000 Subject: 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 --- activesupport/test/core_ext/string_ext_test.rb | 17 +++++++++++++++++ 1 file changed, 17 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 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' -- cgit v1.2.3