1 Commits

Author SHA1 Message Date
Marc Peabody
e26666280c java coercion 2010-10-02 10:11:18 -04:00
8 changed files with 42 additions and 38 deletions

View File

@@ -22,8 +22,8 @@ class AboutExceptions < EdgeCase::Koan
assert_equal __, result
assert_equal __, ex.is_a?(StandardError), "Should be a Standard Error"
assert_equal __, ex.is_a?(RuntimeError), "Should be a Runtime Error"
assert ex.is_a?(___), "Failure message."
assert ex.is_a?(___), "Failure message."
assert RuntimeError.ancestors.include?(StandardError),
"RuntimeError is a subclass of StandardError"

View File

@@ -95,6 +95,21 @@ class AboutJavaInterop < EdgeCase::Koan
assert_equal __, java_array.toString.is_a?(java.lang.String)
end
def test_some_ruby_objects_can_be_coerced_to_java
assert_equal __, "ruby string".to_java.class
assert_equal __, 1.to_java.class
assert_equal __, 9.32.to_java.class
assert_equal __, false.to_java.class
end
def test_some_ruby_objects_can_NOT_be_coerced_to_java
[[], {}, Object.new].each do |ruby_object|
assert_raise(___) do
ruby_object.to_java_class
end
end
end
def test_java_collections_are_enumerable
java_array = java.util.ArrayList.new
java_array << "one" << "two" << "three"

View File

@@ -53,7 +53,7 @@ class AboutSymbols < EdgeCase::Koan
assert_equal symbol, __.to_sym
end
def test_symbols_with_interpolation_can_be_built
def test_symbols_with_spaces_can_be_built
value = "and"
symbol = :"cats #{value} dogs"

View File

@@ -93,29 +93,16 @@ module EdgeCase
end
def colorize(string, color_value)
if use_colors?
color(color_value) + string + color(COLORS[:clear])
else
if ENV['NO_COLOR']
string
else
color(color_value) + string + color(COLORS[:clear])
end
end
def color(color_value)
"\e[#{color_value}m"
end
def use_colors?
return false if ENV['NO_COLOR']
if ENV['ANSI_COLOR'].nil?
! using_windows?
else
ENV['ANSI_COLOR'] =~ /^(t|y)/i
end
end
def using_windows?
File::ALT_SEPARATOR
end
end
class Sensei

View File

@@ -22,8 +22,8 @@ class AboutExceptions < EdgeCase::Koan
assert_equal __(:exception_handled), result
assert_equal __(true), ex.is_a?(StandardError), "Should be a Standard Error"
assert_equal __(true), ex.is_a?(RuntimeError), "Should be a Runtime Error"
assert ex.is_a?(___(StandardError)), "Failure message."
assert ex.is_a?(___(RuntimeError)), "Failure message."
assert RuntimeError.ancestors.include?(StandardError), # __
"RuntimeError is a subclass of StandardError"

View File

@@ -95,6 +95,21 @@ class AboutJavaInterop < EdgeCase::Koan
assert_equal __(false), java_array.toString.is_a?(java.lang.String)
end
def test_some_ruby_objects_can_be_coerced_to_java
assert_equal __(Java::JavaLang::String), "ruby string".to_java.class
assert_equal __(Java::JavaLang::Long), 1.to_java.class
assert_equal __(Java::JavaLang::Double), 9.32.to_java.class
assert_equal __(Java::JavaLang::Boolean), false.to_java.class
end
def test_some_ruby_objects_can_NOT_be_coerced_to_java
[[], {}, Object.new].each do |ruby_object|
assert_raise(___(NoMethodError)) do
ruby_object.to_java_class
end
end
end
def test_java_collections_are_enumerable
java_array = java.util.ArrayList.new
java_array << "one" << "two" << "three"

View File

@@ -53,7 +53,7 @@ class AboutSymbols < EdgeCase::Koan
assert_equal symbol, __("cats and dogs").to_sym
end
def test_symbols_with_interpolation_can_be_built
def test_symbols_with_spaces_can_be_built
value = "and"
symbol = :"cats #{value} dogs"

View File

@@ -93,29 +93,16 @@ module EdgeCase
end
def colorize(string, color_value)
if use_colors?
color(color_value) + string + color(COLORS[:clear])
else
if ENV['NO_COLOR']
string
else
color(color_value) + string + color(COLORS[:clear])
end
end
def color(color_value)
"\e[#{color_value}m"
end
def use_colors?
return false if ENV['NO_COLOR']
if ENV['ANSI_COLOR'].nil?
! using_windows?
else
ENV['ANSI_COLOR'] =~ /^(t|y)/i
end
end
def using_windows?
File::ALT_SEPARATOR
end
end
class Sensei