diff options
author | Rafael França <rafael@franca.dev> | 2019-07-28 00:02:33 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-28 00:02:33 -0400 |
commit | 49238eaf8c24645074682cebc8d78a260cacf5dd (patch) | |
tree | 24f3db4726ded7f94efaba7f67a05908e67477ab /activesupport/test | |
parent | ac6f3c9299209ea4b2fa7c368ea1ff406735ca93 (diff) | |
parent | 0e2de0e3fdc9a1fc763531b74e9fc49666022ff9 (diff) | |
download | rails-49238eaf8c24645074682cebc8d78a260cacf5dd.tar.gz rails-49238eaf8c24645074682cebc8d78a260cacf5dd.tar.bz2 rails-49238eaf8c24645074682cebc8d78a260cacf5dd.zip |
Merge pull request #36185 from jonathanhefner/optimize-string-first-and-last
Improve String#first and #last performance
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/string_ext_test.rb | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index b1ab9533e7..af8f9c9b09 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -482,12 +482,16 @@ class StringAccessTest < ActiveSupport::TestCase assert_not_same different_string, string end - test "#first with negative Integer is deprecated" do - string = "hello" - message = "Calling String#first with a negative integer limit " \ - "will raise an ArgumentError in Rails 6.1." - assert_deprecated(message) do - string.first(-1) + test "#first with Integer returns a non-frozen string" do + string = "he" + (0..string.length + 1).each do |limit| + assert_not string.first(limit).frozen? + end + end + + test "#first with negative Integer raises ArgumentError" do + assert_raise ArgumentError do + "hello".first(-1) end end @@ -509,12 +513,16 @@ class StringAccessTest < ActiveSupport::TestCase assert_not_same different_string, string end - test "#last with negative Integer is deprecated" do - string = "hello" - message = "Calling String#last with a negative integer limit " \ - "will raise an ArgumentError in Rails 6.1." - assert_deprecated(message) do - string.last(-1) + test "#last with Integer returns a non-frozen string" do + string = "he" + (0..string.length + 1).each do |limit| + assert_not string.last(limit).frozen? + end + end + + test "#last with negative Integer raises ArgumentError" do + assert_raise ArgumentError do + "hello".last(-1) end end |