Permalink
Browse files

Merge pull request #39 from mking/master

Add Hash conversion
  • Loading branch information...
2 parents 5d038d6 + 53a751b commit 8f9093d758aa15ded2c112f6d3e3537cc968477d Jason Roelofs committed Apr 13, 2012
Showing with 40 additions and 0 deletions.
  1. +14 −0 rice/Hash.hpp
  2. +26 −0 test/test_To_From_Ruby.cpp
View
@@ -204,6 +204,20 @@ class Hash::Iterator
} // namespace Rice
+template<>
+inline
+Rice::Hash from_ruby<Rice::Hash>(Rice::Object x)
+{
+ return Rice::Hash(x);
+}
+
+template<>
+inline
+Rice::Object to_ruby<Rice::Hash>(Rice::Hash const & x)
+{
+ return x;
+}
+
#include "Hash.ipp"
#endif // Rice__Hash__hpp_
View
@@ -1,6 +1,8 @@
#include "unittest.hpp"
#include "rice/to_from_ruby.hpp"
#include "rice/String.hpp"
+#include "rice/Array.hpp"
+#include "rice/Hash.hpp"
#include <limits>
#include <cmath>
@@ -275,3 +277,27 @@ TESTCASE(std_string_from_ruby_with_binary)
ASSERT_EQUAL(5, got.length());
ASSERT_EQUAL(std::string("\000test", 5), got);
}
+
+TESTCASE(array_to_ruby)
+{
+ Array a(rb_ary_new());
+ ASSERT_EQUAL(a.value(), to_ruby(a).value());
+}
+
+TESTCASE(array_from_ruby)
+{
+ Array a(rb_ary_new());
+ ASSERT_EQUAL(a.value(), from_ruby<Array>(a).value());
+}
+
+TESTCASE(hash_to_ruby)
+{
+ Hash h(rb_hash_new());
+ ASSERT_EQUAL(h.value(), to_ruby(h).value());
+}
+
+TESTCASE(hash_from_ruby)
+{
+ Hash h(rb_hash_new());
+ ASSERT_EQUAL(h.value(), from_ruby<Hash>(h).value());
+}

0 comments on commit 8f9093d

Please sign in to comment.