Permalink
Browse files

Merge branch 'more_jruby' into m

* more_jruby:
  [5553333] Updated java interop on to_java method.
  Added cruise task
  java coercion
  • Loading branch information...
2 parents 297cfde + ccfa664 commit ab59dc4791f10322cb404c52ecd1ba94bd9d9e1e @jimweirich jimweirich committed Dec 23, 2010
Showing with 83 additions and 0 deletions.
  1. +57 −0 Rakefile
  2. +13 −0 koans/about_java_interop.rb
  3. +13 −0 src/about_java_interop.rb
View
@@ -57,6 +57,28 @@ module Koans
end
end
+module RubyImpls
+ # Calculate the list of relevant Ruby implementations.
+ def self.find_ruby_impls
+ rubys = `rvm list`.gsub(/=>/,'').split(/\n/).sort
+ expected.map { |impl|
+ puts "DBG: impl=#{impl.inspect}"
+ last = rubys.grep(Regexp.new(Regexp.quote(impl))).last
+ last ? last.split.first : nil
+ }.compact
+ end
+
+ # Return a (cached) list of relevant Ruby implementations.
+ def self.list
+ @list ||= find_ruby_impls
+ end
+
+ # List of expected ruby implementations.
+ def self.expected
+ %w(ruby-1.8.6 ruby-1.8.7 ruby-1.9.2 jruby ree)
+ end
+end
+
task :default => :walk_the_path
task :walk_the_path do
@@ -107,3 +129,38 @@ SRC_FILES.each do |koan_src|
Koans.make_koan_file koan_src, t.name
end
end
+
+task :run do
+ puts 'koans'
+ Dir.chdir("src") do
+ puts "in #{Dir.pwd}"
+ sh "ruby path_to_enlightenment.rb"
+ end
+end
+
+
+desc "Pre-checkin tests (=> run_all)"
+task :cruise => :run_all
+
+desc "Run the completed koans againts a list of relevant Ruby Implementations"
+task :run_all do
+ results = {}
+ RubyImpls.list.each do |impl|
+ puts "=" * 40
+ puts "On Ruby #{impl}"
+ res = sh "rvm #{impl} rake run"
+ results[impl] = res
+ puts
+ end
+ puts "=" * 40
+ puts "Summary:"
+ puts
+ results.each do |impl, res|
+ puts "#{impl} => RAN"
+ end
+ puts
+ RubyImpls.expected.each do |requested_impl|
+ impl_pattern = Regexp.new(Regexp.quote(requested_impl))
+ puts "No Results for #{requested_impl}" if results.keys.grep(impl_pattern).empty?
+ end
+end
@@ -95,6 +95,19 @@ def test_however_most_methods_returning_strings_return_ruby_strings
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
+ assert_equal __, [].to_java.class == Java::JavaUtil::ArrayList
+ assert_equal __, {}.to_java.class == Java::JavaUtil::HashMap
+ assert_equal __, Object.new.to_java.class == Java::JavaLang::Object
+ end
+
def test_java_collections_are_enumerable
java_array = java.util.ArrayList.new
java_array << "one" << "two" << "three"
View
@@ -95,6 +95,19 @@ def test_however_most_methods_returning_strings_return_ruby_strings
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
+ assert_equal __(false), [].to_java.class == Java::JavaUtil::ArrayList
+ assert_equal __(false), {}.to_java.class == Java::JavaUtil::HashMap
+ assert_equal __(false), Object.new.to_java.class == Java::JavaLang::Object
+ end
+
def test_java_collections_are_enumerable
java_array = java.util.ArrayList.new
java_array << "one" << "two" << "three"

0 comments on commit ab59dc4

Please sign in to comment.