New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Magic comment "immutable: string" makes "literal".freeze the default for that file #487

Closed
wants to merge 4 commits into
base: trunk
from
Jump to file or symbol
Failed to load files and symbols.
+14 −17
Diff settings

Always

Just for now

Viewing a subset of changes. View all
Prev

Move and add a test

  • Loading branch information...
ColinDKelley committed Dec 29, 2013
commit c614bdda236d4cbd785e8c0f86379b92e3f1562c
@@ -1,14 +1,5 @@
# -*- immutable: string -*-
#class NilClass
# def freeze
# raise '!!!'
# end
#end
#
#puts('', '')
require 'test/unit'
require_relative 'test_string_literal_mutable.rb'
@@ -46,14 +37,6 @@ def test_strings_are_immutable_in_this_file
end
end
def test_string_interpolation
str = interpolated_string("blah blah")
exception = assert_raise RuntimeError do
mutate(str)
end
assert_match /can't modify frozen String/, exception.message
end
def test_strings_in_other_file_are_mutable
mutate(TestStringLiteralMutable::CONSTANT)
assert_equal "SING", TestStringLiteralMutable::CONSTANT
@@ -65,6 +48,20 @@ def test_literal_strings_should_have_the_same_object_id
assert_equal s1.object_id, s2.object_id
end
def test_different_literal_strings_with_the_same_value_in_the_same_file_should_have_the_same_object_id
s1 = some_string
s2 = "A nice frozen string!"
assert_equal s2.object_id, s2.object_id
end
def test_string_interpolation
str = interpolated_string("blah blah")
exception = assert_raise RuntimeError do
mutate(str)
end
assert_match /can't modify frozen String/, exception.message
end
def test_interpolated_strings_should_have_a_different_object_id
s1 = interpolated_string('x')
s2 = interpolated_string('x')
ProTip! Use n and p to navigate between commits in a pull request.