Updated for JRuby

This commit is contained in:
Jim Weirich
2010-09-27 10:44:58 -04:00
parent b2c47e0c0f
commit 584b26e532
3 changed files with 49 additions and 19 deletions

View File

@@ -25,15 +25,21 @@ class AboutSymbols < EdgeCase::Koan
def test_method_names_become_symbols
all_symbols = Symbol.all_symbols
assert_equal __(true), all_symbols.include?(:test_method_names_are_symbols)
assert_equal __(true), all_symbols.include?(:test_method_names_become_symbols)
end
RubyConstant = "What is the sound of one hand clapping?"
def test_constants_become_symbols
all_symbols = Symbol.all_symbols
# THINK ABOUT IT:
#
# Why do we capture the list of symbols before we check for the
# method name?
assert_equal true, all_symbols.include?(__(:RubyConstant))
in_ruby_version("mri") do
RubyConstant = "What is the sound of one hand clapping?"
def test_constants_become_symbols
all_symbols = Symbol.all_symbols
assert_equal __(true), all_symbols.include?(__(:RubyConstant))
end
end
def test_symbols_can_be_made_from_strings
@@ -47,6 +53,13 @@ class AboutSymbols < EdgeCase::Koan
assert_equal symbol, __("cats and dogs").to_sym
end
def test_symbols_with_spaces_can_be_built
value = "and"
symbol = :"cats #{value} dogs"
assert_equal symbol, __("cats and dogs").to_sym
end
def test_to_s_is_called_on_interpolated_symbols
symbol = :cats
string = "It is raining #{symbol} and dogs."
@@ -65,13 +78,23 @@ class AboutSymbols < EdgeCase::Koan
assert_equal __(false), symbol.respond_to?(:each_char)
assert_equal __(false), symbol.respond_to?(:reverse)
end
# It's important to realize that symbols are not "immutable
# strings", though they are immutable. None of the
# interesting string operations are available on symbols.
def test_symbols_cannot_be_concatenated
# Exceptions will be pondered further father down the path
assert_raise(___(NoMethodError)) do
:cats + :dogs
end
end
def test_symbols_can_be_dynamically_created
assert_equal __(:catsdogs), ("cats" + "dogs").to_sym
end
# THINK ABOUT IT:
#
# Why is it not a good idea to dynamically create a lot of symbols?
end