[DRE-commits] [ruby-oj] 01/07: Imported Upstream version 2.9.6

Cédric Boutillier boutil at moszumanska.debian.org
Mon Jun 23 05:16:34 UTC 2014


This is an automated email from the git hooks/post-receive script.

boutil pushed a commit to annotated tag debian/2.9.6-1
in repository ruby-oj.

commit a3764a166053308a734308becc85103b394ee1ec
Author: Cédric Boutillier <boutil at debian.org>
Date:   Fri Jun 20 21:37:23 2014 +0200

    Imported Upstream version 2.9.6
---
 README.md                                  |  11 +-
 checksums.yaml.gz                          | Bin 267 -> 270 bytes
 ext/oj/dump.c                              |   3 +-
 ext/oj/oj.c                                |  75 +++++++++-
 ext/oj/parse.c                             |  23 ++-
 ext/oj/parse.h                             |   1 +
 ext/oj/reader.c                            |   5 +-
 ext/oj/scp.c                               |  11 +-
 lib/oj/mimic.rb                            |   4 +-
 lib/oj/schandler.rb                        |  56 ++++++-
 lib/oj/version.rb                          |   2 +-
 metadata.yml                               |  76 +++++++---
 test/_test_mimic_rails.rb                  |  31 ++++
 test/a.rb                                  |  38 -----
 test/bug.rb                                |  23 ++-
 test/debian_test.rb                        |  90 ------------
 test/e.rb                                  |  12 --
 test/foo.rb                                |  24 ---
 test/helper.rb                             |  27 ++++
 test/io.rb                                 |  48 ++++++
 test/{test_mimic.rb => isolated/shared.rb} | 119 ++++++++-------
 test/isolated/test_mimic_after.rb          |  13 ++
 test/isolated/test_mimic_alone.rb          |  12 ++
 test/isolated/test_mimic_before.rb         |  13 ++
 test/isolated/test_mimic_define.rb         |  28 ++++
 test/isolated/test_mimic_rails_after.rb    |  19 +++
 test/isolated/test_mimic_rails_before.rb   |  19 +++
 test/lots.rb                               |  68 ---------
 test/mj.rb                                 |  48 ------
 test/perf_str.rb                           |  38 -----
 test/perf_strictx.rb                       |  97 -------------
 test/test_compat.rb                        | 114 +++++++--------
 test/test_debian.rb                        |  53 +++++++
 test/test_fast.rb                          |  26 ++--
 test/test_file.rb                          | 103 ++++++-------
 test/test_gc.rb                            |  46 +++---
 test/test_mimic_after.rb                   |  35 -----
 test/test_object.rb                        | 214 +++++++++++++--------------
 test/test_saj.rb                           |  30 ++--
 test/test_scp.rb                           |  35 +++--
 test/test_strict.rb                        |  32 ++--
 test/test_strictx.rb                       |  58 --------
 test/{tests.rb => test_various.rb}         | 225 ++++++++++++-----------------
 test/test_writer.rb                        |  22 ++-
 test/write_fake_log.rb                     |  63 --------
 test/x.rb                                  |  59 --------
 test/zip.rb                                |  34 +++++
 47 files changed, 978 insertions(+), 1205 deletions(-)

diff --git a/README.md b/README.md
index df63ba4..03c92e8 100644
--- a/README.md
+++ b/README.md
@@ -26,9 +26,12 @@ Follow [@peterohler on Twitter](http://twitter.com/#!/peterohler) for announceme
 
 [![Build Status](https://secure.travis-ci.org/ohler55/oj.png?branch=master)](http://travis-ci.org/ohler55/oj)
 
-### Current Release 2.9.4
+### Current Release 2.9.6
 
- - In mimic mode parse errors not match the JSON::ParserError.
+ - Fixed bug using StringIO with SCParser.
+
+ - Tightened up JSON mimic to raise an exception if JSON.parse is called on
+   a JSON documents that returns a primitive type.
 
 [Older release notes](http://www.ohler.com/dev/oj_misc/release_notes.html).
 
@@ -60,6 +63,10 @@ is the `:object` mode.
   preferred over the `to_json` method. If neither the `to_json` or `to_hash`
   methods exists, then the Oj internal `Object` variable encoding is used.
 
+To change default serialization mode:
+```ruby
+Oj.default_options[:mode] = :compat
+```
 
 ## Compatibility
 
diff --git a/checksums.yaml.gz b/checksums.yaml.gz
index cf4d326..91e4640 100644
Binary files a/checksums.yaml.gz and b/checksums.yaml.gz differ
diff --git a/ext/oj/dump.c b/ext/oj/dump.c
index cfa8303..fa440ba 100644
--- a/ext/oj/dump.c
+++ b/ext/oj/dump.c
@@ -113,7 +113,7 @@ static const char	hex_chars[17] = "0123456789abcdef";
 
 static char	hibit_friendly_chars[256] = "\
 66666666222622666666666666666666\
-11211111111111111111111111111111\
+11211111111111121111111111111111\
 11111111111111111111111111112111\
 11111111111111111111111111111111\
 11111111111111111111111111111111\
@@ -512,6 +512,7 @@ dump_cstr(const char *str, size_t cnt, int is_sym, int escape1, Out out) {
 	    case '2':
 		*out->cur++ = '\\';
 		switch (*str) {
+		case '\\':	*out->cur++ = '\\';	break;
 		case '\b':	*out->cur++ = 'b';	break;
 		case '\t':	*out->cur++ = 't';	break;
 		case '\n':	*out->cur++ = 'n';	break;
diff --git a/ext/oj/oj.c b/ext/oj/oj.c
index 05cc783..c87fe5c 100644
--- a/ext/oj/oj.c
+++ b/ext/oj/oj.c
@@ -177,7 +177,7 @@ static VALUE	define_mimic_json(int argc, VALUE *argv, VALUE self);
  * - circular: [true|false|nil] support circular references while dumping
  * - auto_define: [true|false|nil] automatically define classes if they do not exist
  * - symbol_keys: [true|false|nil] use symbols instead of strings for hash keys
- * - escape_mode: [:json|:xss_safe|:ascii|nil] use symbols instead of strings for hash keys
+ * - escape_mode: [:json|:xss_safe|:ascii|nil] determines the characters to escape
  * - class_cache: [true|false|nil] cache classes for faster parsing (if dynamically modifying classes or reloading classes then don't use this)
  * - mode: [:object|:strict|:compat|:null] load and dump modes to use for JSON
  * - time_format: [:unix|:xmlschema|:ruby] time format when dumping in :compat mode
@@ -1614,6 +1614,7 @@ static VALUE
 mimic_parse(int argc, VALUE *argv, VALUE self) {
     struct _ParseInfo	pi;
     VALUE		args[1];
+    VALUE		result;
 
     if (argc < 1) {
 	rb_raise(rb_eArgError, "Wrong number of arguments to parse.");
@@ -1643,7 +1644,22 @@ mimic_parse(int argc, VALUE *argv, VALUE self) {
     }
     *args = *argv;
 
-    return oj_pi_parse(1, args, &pi, 0, 0, 0);
+    result = oj_pi_parse(1, args, &pi, 0, 0, 0);
+    switch (rb_type(result)) {
+    case T_NIL:
+    case T_TRUE:
+    case T_FALSE:
+    case T_FIXNUM:
+    case T_FLOAT:
+    case T_CLASS:
+    case T_SYMBOL:
+	rb_raise(oj_parse_error_class, "parse is only allowed to return data structure.");
+	break;
+    default:
+	// okay
+	break;
+    }
+    return result;
 }
 
 static VALUE
@@ -1680,6 +1696,48 @@ mimic_create_id(VALUE self, VALUE id) {
     return id;
 }
 
+static struct _Options	mimic_object_to_json_options = {
+    0,			// indent
+    No,			// circular
+    No,			// auto_define
+    No,			// sym_key
+    JSONEsc,		// escape_mode
+    CompatMode,		// mode
+    No,			// class_cache
+    UnixTime,		// time_format
+    Yes,		// bigdec_as_num
+    AutoDec,		// bigdec_load
+    No,			// to_json
+    Yes,		// nilnil
+    json_class,		// create_id
+    10,			// create_id_len
+    9,			// sec_prec
+    Yes,		// allow_gc
+    0,			// dump_opts
+};
+
+static VALUE
+mimic_object_to_json(int argc, VALUE *argv, VALUE self) {
+    char		buf[4096];
+    struct _Out		out;
+    VALUE		rstr;
+    
+    out.buf = buf;
+    out.end = buf + sizeof(buf) - 10;
+    out.allocated = 0;
+    oj_dump_obj_to_json(self, &mimic_object_to_json_options, &out);
+    if (0 == out.buf) {
+	rb_raise(rb_eNoMemError, "Not enough memory.");
+    }
+    rstr = rb_str_new2(out.buf);
+    rstr = oj_encode(rstr);
+    if (out.allocated) {
+	xfree(out.buf);
+    }
+    return rstr;
+}
+
+
 /* Document-method: mimic_JSON
  *    call-seq: mimic_JSON() => Module
  *
@@ -1752,6 +1810,9 @@ define_mimic_json(int argc, VALUE *argv, VALUE self) {
 
     rb_define_module_function(mimic, "parse", mimic_parse, -1);
     rb_define_module_function(mimic, "parse!", mimic_parse, -1);
+
+    rb_define_method(rb_cObject, "to_json", mimic_object_to_json, -1);
+
     rb_gv_set("$VERBOSE", dummy);
 
     array_nl_sym = ID2SYM(rb_intern("array_nl"));			rb_gc_register_address(&array_nl_sym);
@@ -1761,9 +1822,15 @@ define_mimic_json(int argc, VALUE *argv, VALUE self) {
     space_sym = ID2SYM(rb_intern("space"));				rb_gc_register_address(&space_sym);
     symbolize_names_sym = ID2SYM(rb_intern("symbolize_names"));		rb_gc_register_address(&symbolize_names_sym);
 
-    if (!rb_const_defined_at(mimic, rb_intern("ParserError"))) {
-	rb_define_const(mimic, "ParserError", oj_parse_error_class);
+    if (rb_const_defined_at(mimic, rb_intern("ParserError"))) {
+	rb_funcall(mimic, rb_intern("remove_const"), 1, ID2SYM(rb_intern("ParserError")));
     }
+    rb_define_const(mimic, "ParserError", oj_parse_error_class);
+
+    if (!rb_const_defined_at(mimic, rb_intern("State"))) {
+        rb_define_class_under(mimic, "State", rb_cObject);
+    }
+
     oj_default_options.mode = CompatMode;
     oj_default_options.escape_mode = ASCIIEsc;
     oj_default_options.nilnil = Yes;
diff --git a/ext/oj/parse.c b/ext/oj/parse.c
index e959434..3bd07d8 100644
--- a/ext/oj/parse.c
+++ b/ext/oj/parse.c
@@ -70,11 +70,11 @@ static void
 skip_comment(ParseInfo pi) {
     if ('*' == *pi->cur) {
 	pi->cur++;
-	for (; '\0' != *pi->cur; pi->cur++) {
+	for (; pi->cur < pi->end; pi->cur++) {
 	    if ('*' == *pi->cur && '/' == *(pi->cur + 1)) {
 		pi->cur += 2;
 		return;
-	    } else if ('\0' == *pi->cur) {
+	    } else if (pi->end <= pi->cur) {
 		oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "comment not terminated");
 		return;
 	    }
@@ -226,7 +226,7 @@ read_escaped_str(ParseInfo pi, const char *start) {
 	buf_append_string(&buf, start, cnt);
     }
     for (s = pi->cur; '"' != *s; s++) {
-	if ('\0' == *s) {
+	if (s >= pi->end) {
 	    oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "quoted string not terminated");
 	    buf_cleanup(&buf);
 	    return;
@@ -328,9 +328,12 @@ read_str(ParseInfo pi) {
     Val		parent = stack_peek(&pi->stack);
 
     for (; '"' != *pi->cur; pi->cur++) {
-	if ('\0' == *pi->cur) {
+	if (pi->end <= pi->cur) {
 	    oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "quoted string not terminated");
 	    return;
+	} else if ('\0' == *pi->cur) {
+	    oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "NULL byte in string");
+	    return;
 	} else if ('\\' == *pi->cur) {
 	    read_escaped_str(pi, str);
 	    return;
@@ -736,6 +739,12 @@ protect_parse(VALUE pip) {
     return Qnil;
 }
 
+void
+oj_pi_set_input_str(ParseInfo pi, volatile VALUE input) {
+    pi->json = rb_string_value_ptr((VALUE*)&input);
+    pi->end = pi->json + RSTRING_LEN(input);
+}
+
 VALUE
 oj_pi_parse(int argc, VALUE *argv, ParseInfo pi, char *json, size_t len, int yieldOk) {
     char		*buf = 0;
@@ -763,8 +772,7 @@ oj_pi_parse(int argc, VALUE *argv, ParseInfo pi, char *json, size_t len, int yie
 	pi->end = json + len;
 	free_json = 1;
     } else if (T_STRING == rb_type(input)) {
-	pi->json = rb_string_value_cstr((VALUE*)&input);
-	pi->end = pi->json + RSTRING_LEN(input);
+	oj_pi_set_input_str(pi, input);
     } else if (Qnil == input && Yes == pi->options.nilnil) {
 	return Qnil;
     } else {
@@ -776,8 +784,7 @@ oj_pi_parse(int argc, VALUE *argv, ParseInfo pi, char *json, size_t len, int yie
 
 	if (oj_stringio_class == clas) {
 	    s = rb_funcall2(input, oj_string_id, 0, 0);
-	    pi->json = rb_string_value_cstr((VALUE*)&s);
-	    pi->end = pi->json + RSTRING_LEN(s);
+	    oj_pi_set_input_str(pi, s);
 #if !IS_WINDOWS
 	} else if (rb_respond_to(input, oj_fileno_id) &&
 		   Qnil != (s = rb_funcall(input, oj_fileno_id, 0)) &&
diff --git a/ext/oj/parse.h b/ext/oj/parse.h
index 5f5aac0..75a64ec 100644
--- a/ext/oj/parse.h
+++ b/ext/oj/parse.h
@@ -89,6 +89,7 @@ typedef struct _ParseInfo {
 
 extern void	oj_parse2(ParseInfo pi);
 extern void	oj_set_error_at(ParseInfo pi, VALUE err_clas, const char* file, int line, const char *format, ...);
+extern void	oj_pi_set_input_str(ParseInfo pi, volatile VALUE input);
 extern VALUE	oj_pi_parse(int argc, VALUE *argv, ParseInfo pi, char *json, size_t len, int yieldOk);
 extern VALUE	oj_num_as_value(NumInfo ni);
 
diff --git a/ext/oj/reader.c b/ext/oj/reader.c
index 291a87c..430d09e 100644
--- a/ext/oj/reader.c
+++ b/ext/oj/reader.c
@@ -163,7 +163,9 @@ oj_reader_read(Reader reader) {
 
 static VALUE
 rescue_cb(VALUE rbuf, VALUE err) {
-    if (rb_eTypeError != rb_obj_class(err)) {
+    VALUE	clas = rb_obj_class(err);
+
+    if (rb_eTypeError != clas && rb_eEOFError != clas) {
 	Reader	reader = (Reader)rbuf;
 
 	rb_raise(err, "at line %d, column %d\n", reader->line, reader->col);
@@ -186,7 +188,6 @@ partial_io_cb(VALUE rbuf) {
     }
     str = StringValuePtr(rstr);
     cnt = RSTRING_LEN(rstr);
-    //printf("*** read %lu bytes, str: '%s'\n", cnt, str);
     strcpy(reader->tail, str);
     reader->read_end = reader->tail + cnt;
 
diff --git a/ext/oj/scp.c b/ext/oj/scp.c
index aabb29f..ffca55f 100644
--- a/ext/oj/scp.c
+++ b/ext/oj/scp.c
@@ -256,7 +256,7 @@ oj_sc_parse(int argc, VALUE *argv, VALUE self) {
 	pi.expect_value = 0;
     }
     if (rb_type(input) == T_STRING) {
-	pi.json = StringValuePtr(input);
+	oj_pi_set_input_str(&pi, input);
     } else {
 	VALUE		clas = rb_obj_class(input);
 	volatile VALUE	s;
@@ -265,7 +265,7 @@ oj_sc_parse(int argc, VALUE *argv, VALUE self) {
 #endif
 	if (oj_stringio_class == clas) {
 	    s = rb_funcall2(input, oj_string_id, 0, 0);
-	    pi.json = StringValuePtr(input);
+	    oj_pi_set_input_str(&pi, s);
 #if !IS_WINDOWS
 	    // JRuby gets confused with what is the real fileno.
 	} else if (rb_respond_to(input, oj_fileno_id) &&
@@ -275,20 +275,19 @@ oj_sc_parse(int argc, VALUE *argv, VALUE self) {
 	    size_t	len = lseek(fd, 0, SEEK_END);
 
 	    lseek(fd, 0, SEEK_SET);
-	    buf = ALLOC_N(char, len + 1);
+	    buf = ALLOC_N(char, len);
 	    pi.json = buf;
+	    pi.end = buf + len;
 	    if (0 >= (cnt = read(fd, (char*)pi.json, len)) || cnt != (ssize_t)len) {
 		if (0 != buf) {
 		    xfree(buf);
 		}
 		rb_raise(rb_eIOError, "failed to read from IO Object.");
 	    }
-	    ((char*)pi.json)[len] = '\0';
 #endif
 	} else if (rb_respond_to(input, oj_read_id)) {
 	    s = rb_funcall2(input, oj_read_id, 0, 0);
-	    pi.json = rb_string_value_cstr((VALUE*)&s);
-
+	    oj_pi_set_input_str(&pi, s);
 	} else {
 	    rb_raise(rb_eArgError, "saj_parse() expected a String or IO Object.");
 	}
diff --git a/lib/oj/mimic.rb b/lib/oj/mimic.rb
index ee88e5c..4a4d602 100644
--- a/lib/oj/mimic.rb
+++ b/lib/oj/mimic.rb
@@ -1,12 +1,12 @@
 
 module Oj
-  
+
   def self.mimic_loaded(mimic_paths=[])
     $LOAD_PATH.each do |d|
       next unless File.exist?(d)
       offset = d.size() + 1
       Dir.glob(File.join(d, '**', '*.rb')).each do |file|
-        next unless file[offset..-1].start_with?('json')
+        next if file[offset..-1] !~ /^json[\/\\\.]{1}/
         $LOADED_FEATURES << file unless $LOADED_FEATURES.include?(file)
       end
     end
diff --git a/lib/oj/schandler.rb b/lib/oj/schandler.rb
index 75a6bd3..047a502 100644
--- a/lib/oj/schandler.rb
+++ b/lib/oj/schandler.rb
@@ -30,10 +30,56 @@ module Oj
   #
   #    def hash_start(); end
   #    def hash_end(); end
+  #    def hash_set(h, key, value); end
   #    def array_start(); end
   #    def array_end(); end
+  #    def array_append(a, value); end
   #    def add_value(value); end
-  #    def error(message, line, column); end
+  #
+  # As certain elements of a JSON document are reached during parsing the
+  # callbacks are called. The parser helps by keeping track of objects created
+  # by the callbacks but does not create those objects itself.
+  #
+  #    hash_start
+  #
+  # When a JSON object element starts the hash_start() callback is called if
+  # public. It should return what ever Ruby Object is to be used as the element
+  # that will later be included in the hash_set() callback.
+  # 
+  #    hash_end
+  # 
+  # At the end of a JSON object element the hash_end() callback is called if public.
+  # 
+  #    hash_set
+  # 
+  # When a key value pair is encountered during parsing the hash_set() callback
+  # is called if public. The first element will be the object returned from the
+  # enclosing hash_start() callback. The second argument is the key and the last
+  # is the value.
+  # 
+  #    array_start
+  # 
+  # When a JSON array element is started the array_start() callback is called if
+  # public. It should return what ever Ruby Object is to be used as the element
+  # that will later be included in the array_append() callback.
+  # 
+  #    array_end
+  # 
+  # At the end of a JSON array element the array_end() callback is called if public.
+  # 
+  #    array_append
+  # 
+  # When a element is encountered that is an element of an array the
+  # array_append() callback is called if public. The first argument to the
+  # callback is the Ruby object returned from the enclosing array_start()
+  # callback.
+  # 
+  #    add_value
+  # 
+  # The handler is expected to handle multiple JSON elements in one stream,
+  # file, or string. When a top level JSON has been read completely the
+  # add_value() callback is called. Even if only one element was ready this
+  # callback returns the Ruby object that was constructed during the parsing.
   #
   class ScHandler
     # Create a new instance of the ScHandler class.
@@ -51,6 +97,9 @@ module Oj
     def hash_end()
     end
 
+    def hash_set(h, key, value)
+    end
+    
     def array_start()
     end
 
@@ -60,11 +109,8 @@ module Oj
     def add_value(value)
     end
     
-    def hash_set(h, key, value)
-    end
-    
     def array_append(a, value)
     end
-    
+
   end # ScHandler
 end # Oj
diff --git a/lib/oj/version.rb b/lib/oj/version.rb
index 5ed6d8f..31172cc 100644
--- a/lib/oj/version.rb
+++ b/lib/oj/version.rb
@@ -1,5 +1,5 @@
 
 module Oj
   # Current version of the module. 
-  VERSION = '2.9.4'
+  VERSION = '2.9.6'
 end
diff --git a/metadata.yml b/metadata.yml
index 67dfdb6..d10b0ea 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -1,15 +1,57 @@
 --- !ruby/object:Gem::Specification
 name: oj
 version: !ruby/object:Gem::Version
-  version: 2.9.4
+  version: 2.9.6
 platform: ruby
 authors:
 - Peter Ohler
 autorequire: 
 bindir: bin
 cert_chain: []
-date: 2014-05-28 00:00:00.000000000 Z
-dependencies: []
+date: 2014-06-15 00:00:00.000000000 Z
+dependencies:
+- !ruby/object:Gem::Dependency
+  name: rake-compiler
+  requirement: !ruby/object:Gem::Requirement
+    requirements:
+    - - "~>"
+      - !ruby/object:Gem::Version
+        version: '0.9'
+  type: :development
+  prerelease: false
+  version_requirements: !ruby/object:Gem::Requirement
+    requirements:
+    - - "~>"
+      - !ruby/object:Gem::Version
+        version: '0.9'
+- !ruby/object:Gem::Dependency
+  name: minitest
+  requirement: !ruby/object:Gem::Requirement
+    requirements:
+    - - "~>"
+      - !ruby/object:Gem::Version
+        version: '5'
+  type: :development
+  prerelease: false
+  version_requirements: !ruby/object:Gem::Requirement
+    requirements:
+    - - "~>"
+      - !ruby/object:Gem::Version
+        version: '5'
+- !ruby/object:Gem::Dependency
+  name: rails
+  requirement: !ruby/object:Gem::Requirement
+    requirements:
+    - - "~>"
+      - !ruby/object:Gem::Version
+        version: '4'
+  type: :development
+  prerelease: false
+  version_requirements: !ruby/object:Gem::Requirement
+    requirements:
+    - - "~>"
+      - !ruby/object:Gem::Version
+        version: '4'
 description: 'The fastest JSON parser and object serializer. '
 email: peter at ohler.com
 executables: []
@@ -59,14 +101,18 @@ files:
 - lib/oj/saj.rb
 - lib/oj/schandler.rb
 - lib/oj/version.rb
-- test/a.rb
+- test/_test_mimic_rails.rb
 - test/bug.rb
-- test/debian_test.rb
-- test/e.rb
 - test/files.rb
-- test/foo.rb
-- test/lots.rb
-- test/mj.rb
+- test/helper.rb
+- test/io.rb
+- test/isolated/shared.rb
+- test/isolated/test_mimic_after.rb
+- test/isolated/test_mimic_alone.rb
+- test/isolated/test_mimic_before.rb
+- test/isolated/test_mimic_define.rb
+- test/isolated/test_mimic_rails_after.rb
+- test/isolated/test_mimic_rails_before.rb
 - test/perf.rb
 - test/perf_compat.rb
 - test/perf_fast.rb
@@ -75,9 +121,7 @@ files:
 - test/perf_saj.rb
 - test/perf_scp.rb
 - test/perf_simple.rb
-- test/perf_str.rb
 - test/perf_strict.rb
-- test/perf_strictx.rb
 - test/sample.rb
 - test/sample/change.rb
 - test/sample/dir.rb
@@ -94,20 +138,17 @@ files:
 - test/sample_json.rb
 - test/struct.rb
 - test/test_compat.rb
+- test/test_debian.rb
 - test/test_fast.rb
 - test/test_file.rb
 - test/test_gc.rb
-- test/test_mimic.rb
-- test/test_mimic_after.rb
 - test/test_object.rb
 - test/test_saj.rb
 - test/test_scp.rb
 - test/test_strict.rb
-- test/test_strictx.rb
+- test/test_various.rb
 - test/test_writer.rb
-- test/tests.rb
-- test/write_fake_log.rb
-- test/x.rb
+- test/zip.rb
 homepage: http://www.ohler.com/oj
 licenses:
 - MIT
@@ -137,3 +178,4 @@ signing_key:
 specification_version: 4
 summary: A fast JSON parser and serializer.
 test_files: []
+has_rdoc: true
diff --git a/test/_test_mimic_rails.rb b/test/_test_mimic_rails.rb
new file mode 100755
index 0000000..bd995d9
--- /dev/null
+++ b/test/_test_mimic_rails.rb
@@ -0,0 +1,31 @@
+# encoding: UTF-8
+
+require 'helper'
+Oj.mimic_JSON
+require 'rails/all'
+
+class MimicRails < Minitest::Test
+
+  def test_mimic_exception
+    begin
+      ActiveSupport::JSON.decode("{")
+      puts "Failed"
+    rescue ActiveSupport::JSON.parse_error
+      assert(true)
+    rescue Exception
+      assert(false, 'Expected a JSON::ParserError')
+    end
+  end
+
+  def test_dump_string
+    Oj.default_options= {:indent => 2} # JSON this will not change anything
+    json = ActiveSupport::JSON.encode([1, true, nil])
+    assert_equal(%{[
+  1,
+  true,
+  null
+]
+}, json)
+  end
+
+end # MimicRails
diff --git a/test/a.rb b/test/a.rb
deleted file mode 100755
index d523795..0000000
--- a/test/a.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/usr/bin/env ruby -wW1
-# encoding: UTF-8
-
-$: << File.dirname(__FILE__)
-$: << File.join(File.dirname(__FILE__), "../lib")
-$: << File.join(File.dirname(__FILE__), "../ext")
-
-require 'pp'
-require 'oj'
-require 'perf'
-
-obj = [[1],[2],[3],[4],[5],[6],[7],[8],[9]]
-obj = [[],[],[],[],[],[],[],[],[]]
-obj = {
-  'a' => 'Alpha', # string
-  'b' => true,    # boolean
-  'c' => 12345,   # number
-  'd' => [ true, [false, [12345, nil], 3.967, ['something', false], nil]], # mix it up array
-  'e' => { 'one' => 1, 'two' => 2 }, # hash
-  'f' => nil,     # nil
-  'g' => 12345678901234567890123456789, # big number
-  'h' => { 'a' => { 'b' => { 'c' => { 'd' => {'e' => { 'f' => { 'g' => nil }}}}}}}, # deep hash, not that deep
-  'i' => [[[[[[[nil]]]]]]]  # deep array, again, not that deep
-}
-
-json = Oj.dump(obj, mode: :compat)
-
-puts json
-#pp Oj.saj_parse(nil, json)
-pp Oj.t_parse(json)
-
-if true
-  perf = Perf.new()
-  perf.add('SAJ', 'oj') { Oj.saj_parse(nil, json) }
-  perf.add('T', 'oj') { Oj.t_parse(json) }
-  perf.add('load', 'oj') { Oj.load(json) }
-  perf.run(10000)
-end
diff --git a/test/bug.rb b/test/bug.rb
index 06da3d6..a1a5f6e 100755
--- a/test/bug.rb
+++ b/test/bug.rb
@@ -1,17 +1,16 @@
 #!/usr/bin/env ruby
-# encoding: UTF-8
-
-# Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
-# required. That can be set in the RUBYOPT environment variable.
-# export RUBYOPT=-w
-
-$VERBOSE = true
 
-$: << File.join(File.dirname(__FILE__), "../lib")
-$: << File.join(File.dirname(__FILE__), "../ext")
+#!/usr/bin/env ruby
+# encoding: UTF-8
 
-require 'oj'
+$: << File.dirname(__FILE__)
 
-obj = Oj.load_file('bug.json', :mode => :object)
+require 'helper'
 
-puts Oj.dump(obj, :mode => :object, :indent => 0)
+File.open('tst', 'r') do |file|
+  puts file.gets
+  puts file.read(1)
+  Oj.load(file) do |val|
+    puts "*** inside: #{val}"
+  end
+end
diff --git a/test/debian_test.rb b/test/debian_test.rb
deleted file mode 100755
index 273acdb..0000000
--- a/test/debian_test.rb
+++ /dev/null
@@ -1,90 +0,0 @@
-#!/usr/bin/env ruby
-# encoding: UTF-8
-
-# Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
-# required. That can be set in the RUBYOPT environment variable.
-# export RUBYOPT=-w
-
-$VERBOSE = true
-
-$: << File.join(File.dirname(__FILE__), "../lib")
-$: << File.join(File.dirname(__FILE__), "../ext")
-
-require 'test/unit'
-require 'stringio'
-require 'date'
-require 'bigdecimal'
-require 'oj'
-
-$ruby = RUBY_DESCRIPTION.split(' ')[0]
-$ruby = 'ree' if 'ruby' == $ruby && RUBY_DESCRIPTION.include?('Ruby Enterprise Edition')
-
-def hash_eql(h1, h2)
-  return false if h1.size != h2.size
-  h1.keys.each do |k|
-    return false unless h1[k] == h2[k]
-  end
-  true
-end
-
-class Jam
-  attr_accessor :x, :y
-
-  def initialize(x, y)
-    @x = x
-    @y = y
-  end
-
-  def eql?(o)
-    self.class == o.class && @x == o.x && @y == o.y
-  end
-  alias == eql?
-
-end# Jam
-
-# contributed by sauliusg to fix as_json
-class Orange < Jam
-  def initialize(x, y)
-    super
-  end
-
-  def as_json()
-    puts "Orange.as_json called"
-    { :json_class => self.class,
-      :x => @x,
-      :y => @y }
-  end
-
-  def self.json_create(h)
-    puts "Orange.json_create"
-    self.new(h['x'], h['y'])
-  end
-end
-
-class DebJuice < ::Test::Unit::TestCase
-
-  def test_class_hash
-    Oj.hash_test()
-  end
-
-  def test_as_json_object_compat_hash_cached
-    Oj.default_options = { :mode => :compat, :class_cache => true }
-    obj = Orange.new(true, 58)
-    puts "dumping compat with cache"
-    json = Oj.dump(obj, :indent => 2)
-    assert(!json.nil?)
-    dump_and_load(obj, true)
-  end
-
-  def dump_and_load(obj, trace=false)
-    puts "dumping"
-    json = Oj.dump(obj, :indent => 2)
-    puts json if trace
-    puts "loading"
-    loaded = Oj.load(json);
-    puts "done"
-    assert_equal(obj, loaded)
-    loaded
-  end
-
-end
diff --git a/test/e.rb b/test/e.rb
deleted file mode 100755
index c7327d1..0000000
--- a/test/e.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/usr/bin/env ruby
-
-$: << File.join(File.dirname(__FILE__), "../lib")
-$: << File.join(File.dirname(__FILE__), "../ext")
-
-require 'oj'
-
-json = %{"\xc2\xa9\xc3\x98"}
-puts "original:\n#{json}"
-
-str = Oj.load(json)
-puts "out: #{str}"
diff --git a/test/foo.rb b/test/foo.rb
deleted file mode 100755
index 45481d3..0000000
--- a/test/foo.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env ruby
-# encoding: UTF-8
-
-# Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
-# required. That can be set in the RUBYOPT environment variable.
-# export RUBYOPT=-w
-
-$VERBOSE = true
-
-$: << File.join(File.dirname(__FILE__), "../lib")
-$: << File.join(File.dirname(__FILE__), "../ext")
-
-require 'oj'
-
-class Foo < String
-  def initialize(str, safe)
-    super(str)
-    @safe = safe
-  end
-end
-
-f = Foo.new("z")
-
-puts f
diff --git a/test/helper.rb b/test/helper.rb
new file mode 100644
index 0000000..9192abe
--- /dev/null
+++ b/test/helper.rb
@@ -0,0 +1,27 @@
+# Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
+# required. That can be set in the RUBYOPT environment variable.
+# export RUBYOPT=-w
+
+$VERBOSE = true
+
+%w(lib ext test).each do |dir|
+  $LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
+end
+
+require 'rubygems' if RUBY_VERSION.start_with?('1.8.')
+require 'minitest'
+require 'minitest/autorun'
+require 'stringio'
+require 'date'
+require 'bigdecimal'
+require 'pp'
+require 'oj'
+
+$ruby = RUBY_DESCRIPTION.split(' ')[0]
+$ruby = 'ree' if 'ruby' == $ruby && RUBY_DESCRIPTION.include?('Ruby Enterprise Edition')
+
+class Range
+  def to_hash()
+    { 'begin' => self.begin, 'end' => self.end, 'exclude_end' => self.exclude_end? }
+  end
+end
diff --git a/test/io.rb b/test/io.rb
new file mode 100755
index 0000000..bb8c4f6
--- /dev/null
+++ b/test/io.rb
@@ -0,0 +1,48 @@
+#!/usr/bin/env ruby
+# encoding: UTF-8
+
+$: << File.dirname(__FILE__)
+
+require 'helper'
+
+class Handler
+  def initialize
+    @state = []
+  end
+
+  def hash_start
+    @state << {}
+    @state.last
+  end
+
+  def hash_end
+    @state.pop
+  end
+
+  def hash_set(h,k,v)
+    h.store(k,v)
+  end
+
+  def array_start
+    @state << []
+    @state.last
+  end
+
+
+  def array_end
+    @state.pop
+  end
+
+  def array_append(a,v)
+    a << v
+  end
+
+  def error(message, line, column); p "ERROR: #{message}" end
+end
+
+handler = Handler.new
+def handler.add_value(v)
+  p v
+end
+
+Oj.sc_parse(handler, StringIO.new('{"a":"b","c":[1,2,{"d":"e"}]}[4,5,6]'))
diff --git a/test/test_mimic.rb b/test/isolated/shared.rb
old mode 100755
new mode 100644
similarity index 71%
rename from test/test_mimic.rb
rename to test/isolated/shared.rb
index 5781d10..530d84f
--- a/test/test_mimic.rb
+++ b/test/isolated/shared.rb
@@ -1,52 +1,47 @@
-#!/usr/bin/env ruby
 # encoding: UTF-8
 
-# Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
-# required. That can be set in the RUBYOPT environment variable.
-# export RUBYOPT=-w
+class SharedMimicTest < Minitest::Test
+  class Jam
+    attr_accessor :x, :y
 
-$VERBOSE = true
-
-$: << File.join(File.dirname(__FILE__), "../lib")
-$: << File.join(File.dirname(__FILE__), "../ext")
-
-require 'test/unit'
-require 'stringio'
-require 'bigdecimal'
-require 'oj'
+    def initialize(x, y)
+      @x = x
+      @y = y
+    end
 
-$ruby = RUBY_DESCRIPTION.split(' ')[0]
-$ruby = 'ree' if 'ruby' == $ruby && RUBY_DESCRIPTION.include?('Ruby Enterprise Edition')
+    def eql?(o)
+      self.class == o.class && @x == o.x && @y == o.y
+    end
+    alias == eql?
 
-class Jam
-  attr_accessor :x, :y
+    def as_json()
+      {"json_class" => self.class.to_s,"x" => @x,"y" => @y}
+    end
 
-  def initialize(x, y)
-    @x = x
-    @y = y
-  end
+    def self.json_create(h)
+      self.new(h['x'], h['y'])
+    end
 
-  def eql?(o)
-    self.class == o.class && @x == o.x && @y == o.y
-  end
-  alias == eql?
+  end # Jam
 
-  def as_json()
-    {"json_class" => self.class.to_s,"x" => @x,"y" => @y}
+  def setup
+    @default_options = Oj.default_options
   end
 
-  def self.json_create(h)
-    self.new(h['x'], h['y'])
+  def teardown
+    Oj.default_options = @default_options
   end
 
-end # Jam
-
-class Mimic < ::Test::Unit::TestCase
-
-  def test0_mimic_json
-    assert(defined?(JSON).nil?)
-    Oj.mimic_JSON
-    assert(!defined?(JSON).nil?)
+# exception
+  def test_exception
+    begin
+      JSON.parse("{")
+      puts "Failed"
+    rescue JSON::ParserError
+      assert(true)
+    rescue Exception
+      assert(false, 'Expected a JSON::ParserError')
+    end
   end
 
 # dump
@@ -55,6 +50,17 @@ class Mimic < ::Test::Unit::TestCase
     assert_equal(%{[1,true,null]}, json)
   end
 
+  def test_dump_with_options
+    Oj.default_options= {:indent => 2} # JSON this will not change anything
+    json = JSON.dump([1, true, nil])
+    assert_equal(%{[
+  1,
+  true,
+  null
+]
+}, json)
+  end
+
   def test_dump_io
     s = StringIO.new()
     json = JSON.dump([1, true, nil], s)
@@ -179,7 +185,7 @@ class Mimic < ::Test::Unit::TestCase
     obj = JSON.parse(json, :create_additions => true)
     assert_equal(jam, obj)
     obj = JSON.parse(json, :create_additions => false)
-    assert_equal({'json_class' => 'Jam', 'x' => true, 'y' => 58}, obj)
+    assert_equal({'json_class' => 'SharedMimicTest::Jam', 'x' => true, 'y' => 58}, obj)
     json.gsub!('json_class', 'kson_class')
     JSON.create_id = 'kson_class'
     obj = JSON.parse(json, :create_additions => true)
@@ -203,17 +209,30 @@ class Mimic < ::Test::Unit::TestCase
     end
   end
 
-  # exception check
-  def test_exception
-    json = %{["a":1]}
-    begin
-      obj = JSON.parse(json)
-      
-    rescue JSON::ParserError => je
-      assert(true)
-      return
+# make sure to_json is defined for object.
+  def test_mimic_to_json
+    {'a' => 1}.to_json()
+    Object.new().to_json()
+  end
+end # SharedMimicTest
+
+if defined?(ActiveSupport)
+  class SharedMimicRailsTest < SharedMimicTest
+    def test_activesupport_exception
+      begin
+        ActiveSupport::JSON.decode("{")
+        puts "Failed"
+      rescue ActiveSupport::JSON.parse_error
+        assert(true)
+      rescue Exception
+        assert(false, 'Expected a JSON::ParserError')
+      end
     end
-    assert(false, "*** expected an JSON::ParserError")
-  end
 
-end # Mimic
+    def test_activesupport_encode
+      Oj.default_options= {:indent => 0}
+      json = ActiveSupport::JSON.encode([1, true, nil])
+      assert_equal(%{[1,true,null]}, json)
+    end
+  end # SharedMimicRailsTest
+end
diff --git a/test/isolated/test_mimic_after.rb b/test/isolated/test_mimic_after.rb
new file mode 100755
index 0000000..79dde64
--- /dev/null
+++ b/test/isolated/test_mimic_after.rb
@@ -0,0 +1,13 @@
+#!/usr/bin/env ruby
+# encoding: UTF-8
+
+$: << File.join(File.dirname(__FILE__), '..')
+
+require 'helper'
+require 'isolated/shared'
+
+require 'json'
+Oj.mimic_JSON
+
+class MimicAfter < SharedMimicTest
+end # MimicAfter
diff --git a/test/isolated/test_mimic_alone.rb b/test/isolated/test_mimic_alone.rb
new file mode 100755
index 0000000..7cbcfbb
--- /dev/null
+++ b/test/isolated/test_mimic_alone.rb
@@ -0,0 +1,12 @@
+#!/usr/bin/env ruby
+# encoding: UTF-8
+
+$: << File.join(File.dirname(__FILE__), '..')
+
+require 'helper'
+require 'isolated/shared'
+
+Oj.mimic_JSON
+
+class MimicAlone < SharedMimicTest
+end # MimicAlone
diff --git a/test/isolated/test_mimic_before.rb b/test/isolated/test_mimic_before.rb
new file mode 100755
index 0000000..8629601
--- /dev/null
+++ b/test/isolated/test_mimic_before.rb
@@ -0,0 +1,13 @@
+#!/usr/bin/env ruby
+# encoding: UTF-8
+
+$: << File.join(File.dirname(__FILE__), '..')
+
+require 'helper'
+require 'isolated/shared'
+
+Oj.mimic_JSON
+require 'json'
+
+class MimicBefore < SharedMimicTest
+end # MimicBefore
diff --git a/test/isolated/test_mimic_define.rb b/test/isolated/test_mimic_define.rb
new file mode 100755
index 0000000..39036d4
--- /dev/null
+++ b/test/isolated/test_mimic_define.rb
@@ -0,0 +1,28 @@
+#!/usr/bin/env ruby
+# encoding: UTF-8
+
+$: << File.join(File.dirname(__FILE__), '..')
+
+require 'helper'
+
+class MimicDefine < Minitest::Test
+  def test_mimic_define
+    assert(defined?(JSON).nil?)
+    Oj.mimic_JSON
+
+    # Test constants
+    assert(!defined?(JSON).nil?)
+    assert(!defined?(JSON::ParserError).nil?)
+    assert(Object.respond_to?(:to_json))
+
+    # Test loaded features
+    assert(!require('json'))
+
+    begin
+      require('json_spec')
+      assert(false, '** should raise LoadError')
+    rescue LoadError
+      assert(true)
+    end
+  end
+end # MimicSingle
diff --git a/test/isolated/test_mimic_rails_after.rb b/test/isolated/test_mimic_rails_after.rb
new file mode 100755
index 0000000..39df4d5
--- /dev/null
+++ b/test/isolated/test_mimic_rails_after.rb
@@ -0,0 +1,19 @@
+#!/usr/bin/env ruby
+# encoding: UTF-8
+
+$: << File.join(File.dirname(__FILE__), '..')
+
+require 'helper'
+
+begin
+  require 'rails/all'
+rescue Exception
+  Process.exit!(true)
+end
+
+Oj.mimic_JSON
+
+require 'isolated/shared'
+
+class MimicRailsAfter < SharedMimicRailsTest
+end # MimicRailsAfter
diff --git a/test/isolated/test_mimic_rails_before.rb b/test/isolated/test_mimic_rails_before.rb
new file mode 100755
index 0000000..d9ff37e
--- /dev/null
+++ b/test/isolated/test_mimic_rails_before.rb
@@ -0,0 +1,19 @@
+#!/usr/bin/env ruby
+# encoding: UTF-8
+
+$: << File.join(File.dirname(__FILE__), '..')
+
+require 'helper'
+
+Oj.mimic_JSON
+begin
+  require 'rails/all'
+rescue Exception
+  Process.exit!(true)
+end
+
+require 'isolated/shared'
+
+class MimicRailsBefore < SharedMimicRailsTest
+end # MimicRailsBefore
+
diff --git a/test/lots.rb b/test/lots.rb
deleted file mode 100755
index 739ca2f..0000000
--- a/test/lots.rb
+++ /dev/null
@@ -1,68 +0,0 @@
-#!/usr/bin/env ruby
-# encoding: UTF-8
-
-# Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
-# required. That can be set in the RUBYOPT environment variable.
-# export RUBYOPT=-w
-
-$VERBOSE = true
-
-$: << File.join(File.dirname(__FILE__), "../lib")
-$: << File.join(File.dirname(__FILE__), "../ext")
-
-require 'oj'
-
-module One
-  module Two
-    module Three
-      class Empty
-
-        def initialize()
-        end
-
-        def eql?(o)
-          self.class == o.class
-        end
-        alias == eql?
-
-        def to_hash()
-          {'json_class' => "#{self.class.name}"}
-        end
-
-        def to_json(*a)
-          %{{"json_class":"#{self.class.name}"}}
-        end
-
-        def self.json_create(h)
-          self.new()
-        end
-      end # Empty
-    end # Three
-  end # Two
-end # One
-
-$obj = {
-  'a' => 'Alpha', # string
-  'b' => true,    # boolean
-  'c' => 12345,   # number
-  'd' => [ true, [false, [-123456789, nil], 3.9676, ['Something else.', false], nil]], # mix it up array
-  'e' => { 'zero' => nil, 'one' => 1, 'two' => 2, 'three' => [3], 'four' => [0, 1, 2, 3, 4] }, # hash
-  'f' => nil,     # nil
-  'g' => One::Two::Three::Empty.new(),
-  'h' => { 'a' => { 'b' => { 'c' => { 'd' => {'e' => { 'f' => { 'g' => nil }}}}}}}, # deep hash, not that deep
-  'i' => [[[[[[[nil]]]]]]]  # deep array, again, not that deep
-}
-
-$obj = [$obj]*10000
-
-Oj.default_options = { :indent => 2, :mode => :compat }
-
-$json = Oj.dump($obj, :mode => :compat)
-
-$result = nil
-100.times { |i|
-  print(".") if (0 == i % 10)
-  $result = Oj.compat_load($json)
-}
-
-
diff --git a/test/mj.rb b/test/mj.rb
deleted file mode 100755
index e5dbb56..0000000
--- a/test/mj.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-#!/usr/bin/env ruby
-# encoding: UTF-8
-
-$: << File.join(File.dirname(__FILE__), "../lib")
-$: << File.join(File.dirname(__FILE__), "../ext")
-# $: << File.join(File.dirname(__FILE__), "../../multi_json/lib")
-
-require 'multi_json'
-require 'benchmark'
-require 'yajl'
-require 'json'
-require 'oj'
-
-iter = 1_000_000
-iter = 100_000
-
-json = %({"k1":"val1","k2":"val2","k3":"val3"})
-obj = { k1: "val1", k2: "val2", k3: "val3" }
-
-puts "Benchmarks for different JSON handlers with MultiJson."
-puts "  Ruby #{RUBY_VERSION}"
-puts "  #{iter} iterations"
-
-MultiJson.engine = :oj
-dt = Benchmark.realtime { iter.times { MultiJson.decode(json) }}
-et = Benchmark.realtime { iter.times { MultiJson.encode(obj) }}
-puts "    Oj decode: #{dt}  encode: #{et}"
-
-MultiJson.engine = :yajl
-dt = Benchmark.realtime { iter.times { MultiJson.decode(json) }}
-et = Benchmark.realtime { iter.times { MultiJson.encode(obj) }}
-puts "  Yajl decode: #{dt}  encode: #{et}"
-
-MultiJson.engine = :json_gem
-dt = Benchmark.realtime { iter.times { MultiJson.decode(json) }}
-et = Benchmark.realtime { iter.times { MultiJson.encode(obj) }}
-puts "  Json decode: #{dt}  encode: #{et}"
-
-Oj.default_options = { :mode => :compat, :time_format => :ruby }
-dt = Benchmark.realtime { iter.times { Oj.load(json) }}
-et = Benchmark.realtime { iter.times { Oj.dump(obj) }}
-puts "Raw Oj decode: #{dt}  encode: #{et}"
-
-ye = Yajl::Encoder.new
-dt = Benchmark.realtime { iter.times { Yajl::Parser.parse(json) }}
-et = Benchmark.realtime { iter.times { Yajl::Encoder.encode(obj) }}
-e2 = Benchmark.realtime { iter.times { ye.encode(obj) }}
-puts "Raw Yajl decode: #{dt} encode: #{et}, encoder: #{e2}"
diff --git a/test/perf_str.rb b/test/perf_str.rb
deleted file mode 100755
index 0e416c5..0000000
--- a/test/perf_str.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/usr/bin/env ruby -wW1
-
-$: << '.'
-$: << '../lib'
-$: << '../ext'
-
-if __FILE__ == $0
-  if (i = ARGV.index('-I'))
-    x,path = ARGV.slice!(i, 2)
-    $: << path
-  end
-end
-
-require 'optparse'
-require 'ox'
-require 'oj'
-require 'perf'
-
-$indent = 0
-$iter = 1000
-
-opts = OptionParser.new
-
-opts.on("-i", "--iterations [Int]", Integer, "iterations")  { |i| $iter = i }
-opts.on("-h", "--help", "Show this display")                { puts opts; Process.exit!(0) }
-files = opts.parse(ARGV)
-
-$obj = "x" * 50_000
-
-Oj.default_options = { :mode => :strict, :indent => $indent }
-
-puts '-' * 80
-puts "Dump Performance"
-perf = Perf.new()
-perf.add('Oj', 'dump') { Oj.dump($obj) }
-perf.add('Ox', 'dump') { Ox.dump($obj, :indent => $indent, :circular => $circular) }
-perf.add('Marshal', 'dump') { Marshal.dump($obj) }
-perf.run($iter)
diff --git a/test/perf_strictx.rb b/test/perf_strictx.rb
deleted file mode 100755
index 945312b..0000000
--- a/test/perf_strictx.rb
+++ /dev/null
@@ -1,97 +0,0 @@
-#!/usr/bin/env ruby -wW1
-# encoding: UTF-8
-
-$: << '.'
-$: << File.join(File.dirname(__FILE__), "../lib")
-$: << File.join(File.dirname(__FILE__), "../ext")
-
-require 'stringio'
-require 'optparse'
-require 'perf'
-require 'oj'
-
-$verbose = false
-$indent = 0
-$iter = 20000
-$with_bignum = false
-$with_nums = true
-$size = 0
-
-opts = OptionParser.new
-opts.on("-v", "verbose")                                    { $verbose = true }
-opts.on("-c", "--count [Int]", Integer, "iterations")       { |i| $iter = i }
-opts.on("-i", "--indent [Int]", Integer, "indentation")     { |i| $indent = i }
-opts.on("-s", "--size [Int]", Integer, "size (~Kbytes)")    { |i| $size = i }
-opts.on("-b", "with bignum")                                { $with_bignum = true }
-opts.on("-n", "without numbers")                            { $with_nums = false }
-opts.on("-h", "--help", "Show this display")                { puts opts; Process.exit!(0) }
-files = opts.parse(ARGV)
-
-if $with_nums
-  $obj = {
-    'a' => 'Alpha', # string
-    'b' => true,    # boolean
-    'c' => 12345,   # number
-    'd' => [ true, [false, [-123456789, nil], 3.9676, ['Something else.', false], nil]], # mix it up array
-    'e' => { 'zero' => nil, 'one' => 1, 'two' => 2, 'three' => [3], 'four' => [0, 1, 2, 3, 4] }, # hash
-    'f' => nil,     # nil
-    'h' => { 'a' => { 'b' => { 'c' => { 'd' => {'e' => { 'f' => { 'g' => nil }}}}}}}, # deep hash, not that deep
-    'i' => [[[[[[[nil]]]]]]]  # deep array, again, not that deep
-  }
-  $obj['g'] = 12345678901234567890123456789 if $with_bignum
-else
-  $obj = {
-    'a' => 'Alpha',
-    'b' => true,
-    'c' => '12345',
-    'd' => [ true, [false, ['12345', nil], '3.967', ['something', false], nil]],
-    'e' => { 'zero' => '0', 'one' => '1', 'two' => '2' },
-    'f' => nil,
-    'h' => { 'a' => { 'b' => { 'c' => { 'd' => {'e' => { 'f' => { 'g' => nil }}}}}}}, # deep hash, not that deep
-    'i' => [[[[[[[nil]]]]]]]  # deep array, again, not that deep
-  }
-end
-
-Oj.default_options = { :indent => $indent, :mode => :strict }
-
-if 0 < $size
-  o = $obj
-  $obj = []
-  (4 * $size).times do
-    $obj << o
-  end
-end
-
-$json = Oj.dump($obj)
-$obj_json = Oj.dump($obj, :mode => :object)
-#puts "*** size: #{$obj_json.size}"
-$failed = {} # key is same as String used in tests later
-
-def capture_error(tag, orig, load_key, dump_key, &blk)
-  begin
-    obj = blk.call(orig)
-    raise "#{tag} #{dump_key} and #{load_key} did not return the same object as the original." unless orig == obj
-  rescue Exception => e
-    $failed[tag] = "#{e.class}: #{e.message}"
-  end
-end
-
-# Verify that all packages dump and load correctly and return the same Object as the original.
-capture_error('Oj:strict-str', $obj, 'load', 'dump') { |o| Oj.strict_load(Oj.dump(o, :mode => :strict)) }
-capture_error('Oj:strict', $obj, 'load', 'dump') { |o| Oj.strict_load(StringIO.new(Oj.dump(o, :mode => :strict))) }
-
-puts '-' * 80
-puts "Strict Parse Performance"
-perf = Perf.new()
-perf.add('Oj:strict-str', 'strict_load-str') { Oj.strict_load($json) }
-perf.add('Oj:strict-io', 'strict_load') { Oj.strict_load(StringIO.new($json)) }
-perf.run($iter)
-
-puts
-puts '-' * 80
-puts
-
-unless $failed.empty?
-  puts "The following packages were not included for the reason listed"
-  $failed.each { |tag,msg| puts "***** #{tag}: #{msg}" }
-end
diff --git a/test/test_compat.rb b/test/test_compat.rb
index 1ca4205..5a9b482 100755
--- a/test/test_compat.rb
+++ b/test/test_compat.rb
@@ -1,84 +1,70 @@
 #!/usr/bin/env ruby
 # encoding: UTF-8
 
-# Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
-# required. That can be set in the RUBYOPT environment variable.
-# export RUBYOPT=-w
+$: << File.dirname(__FILE__)
 
-$VERBOSE = true
+require 'helper'
 
-$: << File.join(File.dirname(__FILE__), "../lib")
-$: << File.join(File.dirname(__FILE__), "../ext")
+class CompatJuice < Minitest::Test
 
-require 'test/unit'
-require 'stringio'
-require 'date'
-require 'bigdecimal'
-require 'oj'
+  class Jeez
+    attr_accessor :x, :y
 
-$ruby = RUBY_DESCRIPTION.split(' ')[0]
-$ruby = 'ree' if 'ruby' == $ruby && RUBY_DESCRIPTION.include?('Ruby Enterprise Edition')
-
-class Jeez
-  attr_accessor :x, :y
+    def initialize(x, y)
+      @x = x
+      @y = y
+    end
 
-  def initialize(x, y)
-    @x = x
-    @y = y
-  end
+    def eql?(o)
+      self.class == o.class && @x == o.x && @y == o.y
+    end
+    alias == eql?
 
-  def eql?(o)
-    self.class == o.class && @x == o.x && @y == o.y
-  end
-  alias == eql?
-  
-  def as_json()
-    {"json_class" => self.class.to_s,"x" => @x,"y" => @y}
-  end
+    def as_json()
+      {"json_class" => self.class.to_s,"x" => @x,"y" => @y}
+    end
 
-  def self.json_create(h)
-    self.new(h['x'], h['y'])
-  end
-end # Jeez
+    def self.json_create(h)
+      self.new(h['x'], h['y'])
+    end
+  end # Jeez
 
-module One
-  module Two
-    module Three
-      class Deep
+  module One
+    module Two
+      module Three
+        class Deep
 
-        def initialize()
-        end
+          def initialize()
+          end
 
-        def eql?(o)
-          self.class == o.class
-        end
-        alias == eql?
+          def eql?(o)
+            self.class == o.class
+          end
+          alias == eql?
 
-        def to_hash()
-          {'json_class' => "#{self.class.name}"}
-        end
+          def to_hash()
+            {'json_class' => "#{self.class.name}"}
+          end
 
-        def to_json(*a)
-          %{{"json_class":"#{self.class.name}"}}
-        end
+          def to_json(*a)
+            %{{"json_class":"#{self.class.name}"}}
+          end
 
-        def self.json_create(h)
-          self.new()
-        end
-      end # Deep
-    end # Three
-  end # Two
-end # One
+          def self.json_create(h)
+            self.new()
+          end
+        end # Deep
+      end # Three
+    end # Two
+  end # One
 
-def hash_eql(h1, h2)
-  return false if h1.size != h2.size
-  h1.keys.each do |k|
-    return false unless h1[k] == h2[k]
+  def setup
+    @default_options = Oj.default_options
   end
-  true
-end
 
-class CompatJuice < ::Test::Unit::TestCase
+  def teardown
+    Oj.default_options = @default_options
+  end
 
   def test_nil
     dump_and_load(nil, false)
@@ -218,7 +204,7 @@ class CompatJuice < ::Test::Unit::TestCase
   end
 
   def test_io_file
-    filename = 'open_file_test.json'
+    filename = File.join(File.dirname(__FILE__), 'open_file_test.json')
     File.open(filename, 'w') { |f| f.write(%{{
   "x":true,
   "y":58,
@@ -297,7 +283,7 @@ class CompatJuice < ::Test::Unit::TestCase
   end
 
   def test_json_object_bad
-    json = %{{"json_class":"Junk","x":true}}
+    json = %{{"json_class":"CompatJuice::Junk","x":true}}
     begin
       Oj.compat_load(json)
     rescue Exception => e
diff --git a/test/test_debian.rb b/test/test_debian.rb
new file mode 100755
index 0000000..17f90e4
--- /dev/null
+++ b/test/test_debian.rb
@@ -0,0 +1,53 @@
+# encoding: UTF-8
+
+require 'helper'
+
+class DebJuice < Minitest::Test
+  class Jam
+    attr_accessor :x, :y
+
+    def initialize(x, y)
+      @x = x
+      @y = y
+    end
+
+    def eql?(o)
+      self.class == o.class && @x == o.x && @y == o.y
+    end
+    alias == eql?
+
+  end# Jam
+
+  # contributed by sauliusg to fix as_json
+  class Orange < Jam
+    def initialize(x, y)
+      super
+    end
+
+    def as_json()
+      { :json_class => self.class,
+        :x => @x,
+        :y => @y }
+    end
+
+    def self.json_create(h)
+      self.new(h['x'], h['y'])
+    end
+  end
+
+  def test_as_json_object_compat_hash_cached
+    Oj.default_options = { :mode => :compat, :class_cache => true }
+    obj = Orange.new(true, 58)
+    json = Oj.dump(obj, :indent => 2)
+    assert(!json.nil?)
+    dump_and_load(obj, true)
+  end
+
+  def dump_and_load(obj, trace=false)
+    json = Oj.dump(obj, :indent => 2)
+    loaded = Oj.load(json);
+    assert_equal(obj, loaded)
+    loaded
+  end
+
+end
diff --git a/test/test_fast.rb b/test/test_fast.rb
index a3818e5..0bdce41 100755
--- a/test/test_fast.rb
+++ b/test/test_fast.rb
@@ -1,17 +1,9 @@
 #!/usr/bin/env ruby
 # encoding: UTF-8
 
-# Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
-# required. That can be set in the RUBYOPT environment variable.
-# export RUBYOPT=-w
+$: << File.dirname(__FILE__)
 
-$VERBOSE = true
-
-$: << File.join(File.dirname(__FILE__), "../lib")
-$: << File.join(File.dirname(__FILE__), "../ext")
-
-require 'test/unit'
-require 'oj'
+require 'helper'
 
 $json1 = %{{
   "array": [
@@ -28,7 +20,15 @@ $json1 = %{{
   "boolean" : true
 }}
 
-class DocTest < ::Test::Unit::TestCase
+class DocTest < Minitest::Test
+  def setup
+    @default_options = Oj.default_options
+  end
+
+  def teardown
+    Oj.default_options = @default_options
+  end
+
   def test_nil
     json = %{null}
     Oj::Doc.open(json) do |doc|
@@ -310,7 +310,7 @@ class DocTest < ::Test::Unit::TestCase
   end
 
   def test_open_file
-    filename = 'open_file_test.json'
+    filename = File.join(File.dirname(__FILE__), 'open_file_test.json')
     File.open(filename, 'w') { |f| f.write('{"a":[1,2,3]}') }
     Oj::Doc.open_file(filename) do |doc|
       assert_equal(5, doc.size)
@@ -336,7 +336,7 @@ class DocTest < ::Test::Unit::TestCase
   end
 
   def test_file_open_close
-    filename = 'open_file_test.json'
+    filename = File.join(File.dirname(__FILE__), 'open_file_test.json')
     File.open(filename, 'w') { |f| f.write('{"a":[1,2,3]}') }
     doc = Oj::Doc.open_file(filename)
     assert_equal(Oj::Doc, doc.class)
diff --git a/test/test_file.rb b/test/test_file.rb
index 8d24502..5296b58 100755
--- a/test/test_file.rb
+++ b/test/test_file.rb
@@ -1,75 +1,63 @@
 #!/usr/bin/env ruby
 # encoding: UTF-8
 
-# Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
-# required. That can be set in the RUBYOPT environment variable.
-# export RUBYOPT=-w
+$: << File.dirname(__FILE__)
 
-$VERBOSE = true
+require 'helper'
 
-$: << File.join(File.dirname(__FILE__), "../lib")
-$: << File.join(File.dirname(__FILE__), "../ext")
+class FileJuice < Minitest::Test
+  class Jam
+    attr_accessor :x, :y
 
-require 'test/unit'
-require 'date'
-require 'bigdecimal'
-require 'oj'
-
-$ruby = RUBY_DESCRIPTION.split(' ')[0]
-$ruby = 'ree' if 'ruby' == $ruby && RUBY_DESCRIPTION.include?('Ruby Enterprise Edition')
-
-class Jam
-  attr_accessor :x, :y
+    def initialize(x, y)
+      @x = x
+      @y = y
+    end
 
-  def initialize(x, y)
-    @x = x
-    @y = y
-  end
+    def eql?(o)
+      self.class == o.class && @x == o.x && @y == o.y
+    end
+    alias == eql?
 
-  def eql?(o)
-    self.class == o.class && @x == o.x && @y == o.y
-  end
-  alias == eql?
+  end# Jam
 
-end# Jam
+  class Jeez < Jam
+    def initialize(x, y)
+      super
+    end
 
-class Jeez < Jam
-  def initialize(x, y)
-    super
-  end
+    def to_json()
+      %{{"json_class":"#{self.class}","x":#{@x},"y":#{@y}}}
+    end
 
-  def to_json()
-    %{{"json_class":"#{self.class}","x":#{@x},"y":#{@y}}}
-  end
+    def self.json_create(h)
+      self.new(h['x'], h['y'])
+    end
+  end# Jeez
 
-  def self.json_create(h)
-    self.new(h['x'], h['y'])
-  end
-end# Jeez
+  class Orange < Jam
+    def initialize(x, y)
+      super
+    end
 
-class Orange < Jam
-  def initialize(x, y)
-    super
-  end
+    def as_json()
+      { :json_class => self.class,
+        :x => @x,
+        :y => @y }
+    end
 
-  def as_json()
-    { :json_class => self.class,
-      :x => @x,
-      :y => @y }
+    def self.json_create(h)
+      self.new(h['x'], h['y'])
+    end
   end
 
-  def self.json_create(h)
-    self.new(h['x'], h['y'])
+  def setup
+    @default_options = Oj.default_options
   end
-end
 
-class Range
-  def to_hash()
-    { 'begin' => self.begin, 'end' => self.end, 'exclude_end' => self.exclude_end? }
+  def teardown
+    Oj.default_options = @default_options
   end
-end # Range
-
-class FileJuice < ::Test::Unit::TestCase
 
   def test_nil
     dump_and_load(nil, false)
@@ -100,7 +88,7 @@ class FileJuice < ::Test::Unit::TestCase
     dump_and_load(-2.48e100 * 1.0e10, false)
     dump_and_load(1/0.0, false)
   end
-  
+
   def test_string
     dump_and_load('', false)
     dump_and_load('abc', false)
@@ -155,9 +143,9 @@ class FileJuice < ::Test::Unit::TestCase
     Oj.default_options = { :mode => :compat, :use_to_json => true }
     obj = Jeez.new(true, 58)
     json = Oj.dump(obj, :indent => 2)
-    assert(%{{"json_class":"Jeez","x":true,"y":58}
+    assert(%{{"json_class":"FileJuice::Jeez","x":true,"y":58}
 } == json ||
-           %{{"json_class":"Jeez","y":58,"x":true}
+           %{{"json_class":"FileJuice::Jeez","y":58,"x":true}
 } == json)
     dump_and_load(obj, false)
     Oj.default_options = { :mode => :compat, :use_to_json => false }
@@ -211,7 +199,6 @@ class FileJuice < ::Test::Unit::TestCase
   end
 
   def test_bigdecimal_object
-    mode = Oj.default_options[:mode]
     Oj.default_options = {:mode => :object}
     dump_and_load(BigDecimal.new('3.14159265358979323846'), false)
   end
@@ -229,7 +216,7 @@ class FileJuice < ::Test::Unit::TestCase
   end
 
   def dump_and_load(obj, trace=false)
-    filename = 'file_test.json'
+    filename = File.join(File.dirname(__FILE__), 'file_test.json')
     File.open(filename, "w") { |f|
       Oj.to_stream(f, obj, :indent => 2)
     }
diff --git a/test/test_gc.rb b/test/test_gc.rb
index 31d5442..6d95cfa 100755
--- a/test/test_gc.rb
+++ b/test/test_gc.rb
@@ -1,38 +1,36 @@
 #!/usr/bin/env ruby
 # encoding: UTF-8
 
-# Ubuntu does not accept arguments to ruby when called using env. To get
-# warnings to show up the -w options is required. That can be set in the RUBYOPT
-# environment variable.
-# export RUBYOPT=-w
+$: << File.dirname(__FILE__)
 
-$VERBOSE = true
+require 'helper'
 
-$: << File.join(File.dirname(__FILE__), "../lib")
-$: << File.join(File.dirname(__FILE__), "../ext")
+class GCTest < Minitest::Test
+  class Goo
+    attr_accessor :x, :child
 
-require 'test/unit'
-require 'oj'
+    def initialize(x, child)
+      @x = x
+      @child = child
+    end
 
-class Goo
-  attr_accessor :x, :child
+    def to_hash()
+      { 'json_class' => "#{self.class}", 'x' => x, 'child' => child }
+    end
 
-  def initialize(x, child)
-    @x = x
-    @child = child
-  end
-  
-  def to_hash()
-    { 'json_class' => "#{self.class}", 'x' => x, 'child' => child }
-  end
+    def self.json_create(h)
+      GC.start
+      self.new(h['x'], h['child'])
+    end
+  end # Goo
 
-  def self.json_create(h)
-    GC.start
-    self.new(h['x'], h['child'])
+  def setup
+    @default_options = Oj.default_options
   end
-end # Goo
 
-class GCTest < ::Test::Unit::TestCase
+  def teardown
+    Oj.default_options = @default_options
+  end
 
   # if no crash then the GC marking is working
   def test_parse_compat_gc
diff --git a/test/test_mimic_after.rb b/test/test_mimic_after.rb
deleted file mode 100755
index fa1d88a..0000000
--- a/test/test_mimic_after.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/usr/bin/env ruby
-# encoding: UTF-8
-
-# Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
-# required. That can be set in the RUBYOPT environment variable.
-# export RUBYOPT=-w
-
-$VERBOSE = true
-
-$: << File.join(File.dirname(__FILE__), "../lib")
-$: << File.join(File.dirname(__FILE__), "../ext")
-
-require 'test/unit'
-require 'stringio'
-require 'oj'
-require 'json'
-
-class MimicAfter < ::Test::Unit::TestCase
-
-  def test0_mimic_json
-    assert(!defined?(JSON).nil?)
-    Oj.mimic_JSON
-  end
-
-# dump
-  def test_dump_string
-    Oj.default_options= {:indent => 2} # JSON this will not change anything
-    json = JSON.dump([1, true, nil])
-    assert_equal(%{[
-  1,
-  true,
-  null]}, json)
-  end
-
-end # MimicAfter
diff --git a/test/test_object.rb b/test/test_object.rb
index 65e8dd5..e425827 100755
--- a/test/test_object.rb
+++ b/test/test_object.rb
@@ -1,158 +1,143 @@
 #!/usr/bin/env ruby
 # encoding: UTF-8
 
-# Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
-# required. That can be set in the RUBYOPT environment variable.
-# export RUBYOPT=-w
+$: << File.dirname(__FILE__)
 
-$VERBOSE = true
+require 'helper'
 
-$: << File.join(File.dirname(__FILE__), "../lib")
-$: << File.join(File.dirname(__FILE__), "../ext")
+class ObjectJuice < Minitest::Test
+  class Jeez
+    attr_accessor :x, :y
 
-require 'test/unit'
-require 'stringio'
-require 'date'
-require 'bigdecimal'
-require 'oj'
+    def initialize(x, y)
+      @x = x
+      @y = y
+    end
 
-$ruby = RUBY_DESCRIPTION.split(' ')[0]
-$ruby = 'ree' if 'ruby' == $ruby && RUBY_DESCRIPTION.include?('Ruby Enterprise Edition')
+    def eql?(o)
+      self.class == o.class && @x == o.x && @y == o.y
+    end
+    alias == eql?
 
-class Jeez
-  attr_accessor :x, :y
+    def to_json(*a)
+      %{{"json_class":"#{self.class}","x":#{@x},"y":#{@y}}}
+    end
 
-  def initialize(x, y)
-    @x = x
-    @y = y
-  end
+    def self.json_create(h)
+      self.new(h['x'], h['y'])
+    end
+  end # Jeez
 
-  def eql?(o)
-    self.class == o.class && @x == o.x && @y == o.y
-  end
-  alias == eql?
-  
-  def to_json(*a)
-    %{{"json_class":"#{self.class}","x":#{@x},"y":#{@y}}}
-  end
+  module One
+    module Two
+      module Three
+        class Deep
 
-  def self.json_create(h)
-    self.new(h['x'], h['y'])
-  end
-end # Jeez
+          def initialize()
+          end
 
-module One
-  module Two
-    module Three
-      class Deep
+          def eql?(o)
+            self.class == o.class
+          end
+          alias == eql?
 
-        def initialize()
-        end
+          def to_hash()
+            {'json_class' => "#{self.class.name}"}
+          end
 
-        def eql?(o)
-          self.class == o.class
-        end
-        alias == eql?
+          def to_json(*a)
+            %{{"json_class":"#{self.class.name}"}}
+          end
 
-        def to_hash()
-          {'json_class' => "#{self.class.name}"}
-        end
+          def self.json_create(h)
+            self.new()
+          end
+        end # Deep
+      end # Three
+    end # Two
 
-        def to_json(*a)
-          %{{"json_class":"#{self.class.name}"}}
-        end
+    class Stuck2 < Struct.new(:a, :b)
+    end
 
-        def self.json_create(h)
-          self.new()
-        end
-      end # Deep
-    end # Three
-  end # Two
+  end # One
 
-  class Stuck2 < Struct.new(:a, :b)
+  class Stuck < Struct.new(:a, :b)
   end
 
-end # One
+  class Strung < String
 
-class Stuck < Struct.new(:a, :b)
-end
-
-class Strung < String
+    def initialize(str, safe)
+      super(str)
+      @safe = safe
+    end
 
-  def initialize(str, safe)
-    super(str)
-    @safe = safe
-  end
+    def safe?()
+      @safe
+    end
 
-  def safe?()
-    @safe
-  end
+    def self.create(str, safe)
+      new(str, safe)
+    end
 
-  def self.create(str, safe)
-    new(str, safe)
-  end
+    def eql?(o)
+      super && self.class == o.class && @safe == o.safe?
+    end
+    alias == eql?
 
-  def eql?(o)
-    super && self.class == o.class && @safe == o.safe?
+    def inspect()
+      return super + '(' + @safe + ')'
+    end
   end
-  alias == eql?
 
-  def inspect()
-    return super + '(' + @safe + ')'
-  end
-end
+  class AutoStrung < String
+    attr_accessor :safe
 
-class AutoStrung < String
-  attr_accessor :safe
+    def initialize(str, safe)
+      super(str)
+      @safe = safe
+    end
 
-  def initialize(str, safe)
-    super(str)
-    @safe = safe
+    def eql?(o)
+      self.class == o.class && super(o) && @safe == o.safe
+    end
+    alias == eql?
   end
 
-  def eql?(o)
-    self.class == o.class && super(o) && @safe == o.safe
-  end
-  alias == eql?
-end
+  class AutoArray < Array
+    attr_accessor :safe
 
-class AutoArray < Array
-  attr_accessor :safe
+    def initialize(a, safe)
+      super(a)
+      @safe = safe
+    end
 
-  def initialize(a, safe)
-    super(a)
-    @safe = safe
+    def eql?(o)
+      self.class == o.class && super(o) && @safe == o.safe
+    end
+    alias == eql?
   end
 
-  def eql?(o)
-    self.class == o.class && super(o) && @safe == o.safe
-  end
-  alias == eql?
-end
+  class AutoHash < Hash
+    attr_accessor :safe
 
-class AutoHash < Hash
-  attr_accessor :safe
+    def initialize(h, safe)
+      super(h)
+      @safe = safe
+    end
 
-  def initialize(h, safe)
-    super(h)
-    @safe = safe
+    def eql?(o)
+      self.class == o.class && super(o) && @safe == o.safe
+    end
+    alias == eql?
   end
 
-  def eql?(o)
-    self.class == o.class && super(o) && @safe == o.safe
+  def setup
+    @default_options = Oj.default_options
   end
-  alias == eql?
-end
 
-def hash_eql(h1, h2)
-  return false if h1.size != h2.size
-  h1.keys.each do |k|
-    return false unless h1[k] == h2[k]
+  def teardown
+    Oj.default_options = @default_options
   end
-  true
-end
-
-class ObjectJuice < ::Test::Unit::TestCase
 
   def test_nil
     dump_and_load(nil, false)
@@ -297,7 +282,7 @@ class ObjectJuice < ::Test::Unit::TestCase
   end
 
   def test_io_file
-    filename = 'open_file_test.json'
+    filename = File.join(File.dirname(__FILE__), 'open_file_test.json')
     File.open(filename, 'w') { |f| f.write(%{{
   "x":true,
   "y":58,
@@ -414,6 +399,7 @@ class ObjectJuice < ::Test::Unit::TestCase
   end
 
   def test_mixed_hash_object
+    Oj.default_options = { :mode => :object }
     json = Oj.dump({ 1 => true, 'nil' => nil, :sim => 4 })
     h = Oj.object_load(json)
     assert_equal({ 1 => true, 'nil' => nil, :sim => 4 }, h)
diff --git a/test/test_saj.rb b/test/test_saj.rb
index 55dfbb6..a4c68ea 100755
--- a/test/test_saj.rb
+++ b/test/test_saj.rb
@@ -1,18 +1,9 @@
 #!/usr/bin/env ruby
 # encoding: UTF-8
 
-# Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
-# required. That can be set in the RUBYOPT environment variable.
-# export RUBYOPT=-w
+$: << File.dirname(__FILE__)
 
-$VERBOSE = true
-
-$: << File.join(File.dirname(__FILE__), "../lib")
-$: << File.join(File.dirname(__FILE__), "../ext")
-
-require 'test/unit'
-require 'oj'
-require 'pp'
+require 'helper'
 
 $json = %{{
   "array": [
@@ -62,7 +53,16 @@ class AllSaj < Oj::Saj
 
 end # AllSaj
 
-class SajTest < ::Test::Unit::TestCase
+class SajTest < Minitest::Test
+
+  def setup
+    @default_options = Oj.default_options
+  end
+
+  def teardown
+    Oj.default_options = @default_options
+  end
+
   def test_nil
     handler = AllSaj.new()
     json = %{null}
@@ -177,8 +177,10 @@ class SajTest < ::Test::Unit::TestCase
     handler = AllSaj.new()
     json = %{12345xyz}
     Oj.saj_parse(handler, json)
-    assert_equal([[:add_value, 12345, nil],
-                  [:error, "invalid format, extra characters at line 1, column 6 [saj.c:688]", 1, 6]], handler.calls)
+    assert_equal([:add_value, 12345, nil], handler.calls.first)
+    type, message, line, column = handler.calls.last
+    assert_equal([:error, 1, 6], [type, line, column])
+    assert_match(%r{invalid format, extra characters at line 1, column 6 \[(?:[a-z\.]+/)*saj\.c:\d+\]}, message)
   end
 
 end
diff --git a/test/test_scp.rb b/test/test_scp.rb
index ecb0e1a..53bbd42 100755
--- a/test/test_scp.rb
+++ b/test/test_scp.rb
@@ -1,18 +1,9 @@
 #!/usr/bin/env ruby
 # encoding: UTF-8
 
-# Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
-# required. That can be set in the RUBYOPT environment variable.
-# export RUBYOPT=-w
+$: << File.dirname(__FILE__)
 
-$VERBOSE = true
-
-$: << File.join(File.dirname(__FILE__), "../lib")
-$: << File.join(File.dirname(__FILE__), "../ext")
-
-require 'test/unit'
-require 'oj'
-require 'pp'
+require 'helper'
 
 $json = %{{
   "array": [
@@ -66,14 +57,22 @@ class AllHandler < Oj::ScHandler
   def hash_set(h, key, value)
     @calls << [:hash_set, key, value]
   end
-  
+
   def array_append(a, value)
     @calls << [:array_append, value]
   end
 
 end # AllHandler
 
-class ScpTest < ::Test::Unit::TestCase
+class ScpTest < Minitest::Test
+
+  def setup
+    @default_options = Oj.default_options
+  end
+
+  def teardown
+    Oj.default_options = @default_options
+  end
 
   def test_nil
     handler = AllHandler.new()
@@ -233,7 +232,15 @@ class ScpTest < ::Test::Unit::TestCase
     begin
       Oj.sc_parse(handler, json)
     rescue Exception => e
-      assert_equal("unexpected character at line 1, column 6 [parse.c:637]", e.message)
+      assert_match(%r{unexpected character at line 1, column 6 \[(?:[a-z\.]+/)*parse\.c:\d+\]}, e.message)
+    end
+  end
+
+  def test_null_string
+    handler = AllHandler.new()
+    json = %{"\0"}
+    assert_raises Oj::ParseError do
+      Oj.sc_parse(handler, json)
     end
   end
 
diff --git a/test/test_strict.rb b/test/test_strict.rb
index 9068209..5074971 100755
--- a/test/test_strict.rb
+++ b/test/test_strict.rb
@@ -1,33 +1,19 @@
 #!/usr/bin/env ruby
 # encoding: UTF-8
 
-# Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
-# required. That can be set in the RUBYOPT environment variable.
-# export RUBYOPT=-w
+$: << File.dirname(__FILE__)
 
-$VERBOSE = true
+require 'helper'
 
-$: << File.join(File.dirname(__FILE__), "../lib")
-$: << File.join(File.dirname(__FILE__), "../ext")
+class StrictJuice < Minitest::Test
 
-require 'test/unit'
-require 'stringio'
-require 'date'
-require 'bigdecimal'
-require 'oj'
-
-$ruby = RUBY_DESCRIPTION.split(' ')[0]
-$ruby = 'ree' if 'ruby' == $ruby && RUBY_DESCRIPTION.include?('Ruby Enterprise Edition')
-
-def hash_eql(h1, h2)
-  return false if h1.size != h2.size
-  h1.keys.each do |k|
-    return false unless h1[k] == h2[k]
+  def setup
+    @default_options = Oj.default_options
   end
-  true
-end
 
-class StrictJuice < ::Test::Unit::TestCase
+  def teardown
+    Oj.default_options = @default_options
+  end
 
   def test_nil
     dump_and_load(nil, false)
@@ -175,7 +161,7 @@ class StrictJuice < ::Test::Unit::TestCase
   end
 
   def test_io_file
-    filename = 'open_file_test.json'
+    filename = File.join(File.dirname(__FILE__), 'open_file_test.json')
     File.open(filename, 'w') { |f| f.write(%{{
   "x":true,
   "y":58,
diff --git a/test/test_strictx.rb b/test/test_strictx.rb
deleted file mode 100755
index 6b70737..0000000
--- a/test/test_strictx.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-#!/usr/bin/env ruby
-# encoding: UTF-8
-
-# Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
-# required. That can be set in the RUBYOPT environment variable.
-# export RUBYOPT=-w
-
-$VERBOSE = true
-
-$: << File.join(File.dirname(__FILE__), "../lib")
-$: << File.join(File.dirname(__FILE__), "../ext")
-
-require 'test/unit'
-require 'stringio'
-require 'date'
-require 'oj'
-
-$ruby = RUBY_DESCRIPTION.split(' ')[0]
-$ruby = 'ree' if 'ruby' == $ruby && RUBY_DESCRIPTION.include?('Ruby Enterprise Edition')
-
-def hash_eql(h1, h2)
-  return false if h1.size != h2.size
-  h1.keys.each do |k|
-    return false unless h1[k] == h2[k]
-  end
-  true
-end
-
-class StrictJuice < ::Test::Unit::TestCase
-
-  # Stream IO
-  def test_io_string
-    json = %{{
-  "x":true,
-  "y":58,
-  "z": [1,2,3]
-}
-}
-    input = StringIO.new(json)
-    obj = Oj.strict_loadx(input)
-    assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
-  end
-
-  def xtest_io_file
-    filename = 'open_file_test.json'
-    File.open(filename, 'w') { |f| f.write(%{{
-  "x":true,
-  "y":58,
-  "z": [1,2,3]
-}
-}) }
-    f = File.new(filename)
-    obj = Oj.strict_loadx(f)
-    f.close()
-    assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
-  end
-
-end
diff --git a/test/tests.rb b/test/test_various.rb
similarity index 90%
rename from test/tests.rb
rename to test/test_various.rb
index 344280c..8f0a547 100755
--- a/test/tests.rb
+++ b/test/test_various.rb
@@ -1,125 +1,91 @@
 #!/usr/bin/env ruby
 # encoding: UTF-8
 
-# Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
-# required. That can be set in the RUBYOPT environment variable.
-# export RUBYOPT=-w
+$: << File.dirname(__FILE__)
 
-$VERBOSE = true
+require 'helper'
 
-$: << File.join(File.dirname(__FILE__), "../lib")
-$: << File.join(File.dirname(__FILE__), "../ext")
+class Juice < Minitest::Test
 
-require 'test/unit'
-require 'stringio'
-require 'date'
-require 'bigdecimal'
-require 'oj'
+  class Jam
+    attr_accessor :x, :y
 
-$ruby = RUBY_DESCRIPTION.split(' ')[0]
-$ruby = 'ree' if 'ruby' == $ruby && RUBY_DESCRIPTION.include?('Ruby Enterprise Edition')
-
-def hash_eql(h1, h2)
-  return false if h1.size != h2.size
-  h1.keys.each do |k|
-    return false unless h1[k] == h2[k]
-  end
-  true
-end
-
-class Jam
-  attr_accessor :x, :y
-
-  def initialize(x, y)
-    @x = x
-    @y = y
-  end
+    def initialize(x, y)
+      @x = x
+      @y = y
+    end
 
-  def eql?(o)
-    self.class == o.class && @x == o.x && @y == o.y
-  end
-  alias == eql?
+    def eql?(o)
+      self.class == o.class && @x == o.x && @y == o.y
+    end
+    alias == eql?
 
-end# Jam
+  end# Jam
 
-class Jeez < Jam
-  def initialize(x, y)
-    super
-  end
+  class Jeez < Jam
+    def initialize(x, y)
+      super
+    end
 
-  def to_json()
-    %{{"json_class":"#{self.class}","x":#{@x},"y":#{@y}}}
-  end
+    def to_json()
+      %{{"json_class":"#{self.class}","x":#{@x},"y":#{@y}}}
+    end
 
-  def self.json_create(h)
-    self.new(h['x'], h['y'])
-  end
-end# Jeez
+    def self.json_create(h)
+      self.new(h['x'], h['y'])
+    end
+  end# Jeez
 
-# contributed by sauliusg to fix as_json
-class Orange < Jam
-  def initialize(x, y)
-    super
-  end
+  # contributed by sauliusg to fix as_json
+  class Orange < Jam
+    def initialize(x, y)
+      super
+    end
 
-  def as_json()
-    { :json_class => self.class,
-      :x => @x,
-      :y => @y }
-  end
+    def as_json()
+      { :json_class => self.class,
+        :x => @x,
+        :y => @y }
+    end
 
-  def self.json_create(h)
-    self.new(h['x'], h['y'])
+    def self.json_create(h)
+      self.new(h['x'], h['y'])
+    end
   end
-end
 
-class Melon < Jam
-  def initialize(x, y)
-    super
-  end
+  class Melon < Jam
+    def initialize(x, y)
+      super
+    end
 
-  def as_json()
-    "#{x} #{y}"
-  end
+    def as_json()
+      "#{x} #{y}"
+    end
 
-  def self.json_create(h)
-    self.new(h['x'], h['y'])
+    def self.json_create(h)
+      self.new(h['x'], h['y'])
+    end
   end
-end
 
-class Jazz < Jam
-  def initialize(x, y)
-    super
-  end
-  def to_hash()
-    { 'json_class' => self.class.to_s, 'x' => @x, 'y' => @y }
-  end
-  def self.json_create(h)
-    self.new(h['x'], h['y'])
-  end
-end# Jazz
+  class Jazz < Jam
+    def initialize(x, y)
+      super
+    end
+    def to_hash()
+      { 'json_class' => self.class.to_s, 'x' => @x, 'y' => @y }
+    end
+    def self.json_create(h)
+      self.new(h['x'], h['y'])
+    end
+  end# Jazz
 
-class Range
-  def to_hash()
-    { 'begin' => self.begin, 'end' => self.end, 'exclude_end' => self.exclude_end? }
+  def setup
+    @default_options = Oj.default_options
   end
-end # Range
 
-# define the symbol
-class ActiveSupport
-end
-
-class RailsLike
-  attr_accessor :x
-  def initialize(x)
-    @x = x
-  end
-  def to_json(options = nil)
-    Oj.dump(self, :mode => :compat)
+  def teardown
+    Oj.default_options = @default_options
   end
-end # RailsLike
-
-class Juice < ::Test::Unit::TestCase
 
   def test0_get_options
     opts = Oj.default_options()
@@ -225,6 +191,7 @@ class Juice < ::Test::Unit::TestCase
   end
 
   def test_string_object
+    Oj.default_options = {:mode => :object}
     dump_and_load('abc', false)
     dump_and_load(':abc', false)
   end
@@ -252,6 +219,11 @@ class Juice < ::Test::Unit::TestCase
     assert_equal(json, json2)
   end
 
+  def test_null_char
+    assert_raises(Oj::ParseError) { Oj.load("\"\0\"") }
+    assert_raises(Oj::ParseError) { Oj.load("\"\\\0\"") }
+  end
+
   def test_array
     dump_and_load([], false)
     dump_and_load([true, false], false)
@@ -262,7 +234,7 @@ class Juice < ::Test::Unit::TestCase
   def test_array_not_closed
     begin
       Oj.load('[')
-    rescue Exception => e
+    rescue Exception
       assert(true)
       return
     end
@@ -271,6 +243,7 @@ class Juice < ::Test::Unit::TestCase
 
   # rails encoding tests
   def test_does_not_escape_entities_by_default
+    Oj.default_options = { :escape_mode => :ascii } # set in mimic mode
     # use Oj to create the hash since some Rubies don't deal nicely with unicode.
     json = %{{"key":"I <3 this\\u2028space"}}
     hash = Oj.load(json)
@@ -543,7 +516,7 @@ class Juice < ::Test::Unit::TestCase
   def test_hash_not_closed
     begin
       Oj.load('{')
-    rescue Exception => e
+    rescue Exception
       assert(true)
       return
     end
@@ -570,9 +543,9 @@ class Juice < ::Test::Unit::TestCase
     Oj.default_options = { :mode => :compat, :use_to_json => true }
     obj = Jeez.new(true, 58)
     json = Oj.dump(obj, :indent => 2)
-    assert(%{{"json_class":"Jeez","x":true,"y":58}
+    assert(%{{"json_class":"Juice::Jeez","x":true,"y":58}
 } == json ||
-           %{{"json_class":"Jeez","y":58,"x":true}
+           %{{"json_class":"Juice::Jeez","y":58,"x":true}
 } == json)
     dump_and_load(obj, false)
     Oj.default_options = { :mode => :compat, :use_to_json => false }
@@ -580,7 +553,7 @@ class Juice < ::Test::Unit::TestCase
   def test_json_object_create_id
     Oj.default_options = { :mode => :compat, :create_id => 'kson_class' }
     expected = Jeez.new(true, 58)
-    json = %{{"kson_class":"Jeez","x":true,"y":58}}
+    json = %{{"kson_class":"Juice::Jeez","x":true,"y":58}}
     obj = Oj.load(json)
     assert_equal(expected, obj)
     Oj.default_options = { :create_id => 'json_class' }
@@ -589,13 +562,13 @@ class Juice < ::Test::Unit::TestCase
     obj = Jeez.new(true, 58)
     json = Oj.dump(obj, :mode => :object, :indent => 2)
     assert(%{{
-  "^o":"Jeez",
+  "^o":"Juice::Jeez",
   "x":true,
   "y":58
 }
 } == json ||
 %{{
-  "^o":"Jeez",
+  "^o":"Juice::Jeez",
   "y":58,
   "x":true
 }
@@ -630,13 +603,13 @@ class Juice < ::Test::Unit::TestCase
     obj = Jazz.new(true, 58)
     json = Oj.dump(obj, :mode => :object, :indent => 2)
     assert(%{{
-  "^o":"Jazz",
+  "^o":"Juice::Jazz",
   "x":true,
   "y":58
 }
 } == json ||
 %{{
-  "^o":"Jazz",
+  "^o":"Juice::Jazz",
   "y":58,
   "x":true
 }
@@ -682,13 +655,13 @@ class Juice < ::Test::Unit::TestCase
     obj = Orange.new(true, 58)
     json = Oj.dump(obj, :mode => :object, :indent => 2)
     assert(%{{
-  "^o":"Orange",
+  "^o":"Juice::Orange",
   "x":true,
   "y":58
 }
 } == json ||
 %{{
-  "^o":"Orange",
+  "^o":"Juice::Orange",
   "y":58,
   "x":true
 }
@@ -731,13 +704,13 @@ class Juice < ::Test::Unit::TestCase
     obj = Jam.new(true, 58)
     json = Oj.dump(obj, :mode => :object, :indent => 2)
     assert(%{{
-  "^o":"Jam",
+  "^o":"Juice::Jam",
   "x":true,
   "y":58
 }
 } == json ||
 %{{
-  "^o":"Jam",
+  "^o":"Juice::Jam",
   "y":58,
   "x":true
 }
@@ -750,13 +723,13 @@ class Juice < ::Test::Unit::TestCase
     obj = Jam.new(true, 58)
     json = Oj.dump(obj, :mode => :object, :indent => 2)
     assert(%{{
-  "^o":"Jam",
+  "^o":"Juice::Jam",
   "x":true,
   "y":58
 }
 } == json ||
 %{{
-  "^o":"Jam",
+  "^o":"Juice::Jam",
   "y":58,
   "x":true
 }
@@ -932,6 +905,7 @@ class Juice < ::Test::Unit::TestCase
     end
   end
   def test_date_object
+    Oj.default_options = {:mode => :object}
     dump_and_load(Date.new(2012, 6, 19), false)
   end
 
@@ -958,17 +932,18 @@ class Juice < ::Test::Unit::TestCase
     assert_equal(orig.to_s, x)
   end
   def test_datetime_object
+    Oj.default_options = {:mode => :object}
     dump_and_load(DateTime.new(2012, 6, 19), false)
   end
 
   # autodefine Oj::Bag
   def test_bag
     json = %{{
-  "^o":"Jem",
+  "^o":"Juice::Jem",
   "x":true,
   "y":58 }}
     obj = Oj.load(json, :mode => :object, :auto_define => true)
-    assert_equal('Jem', obj.class.name)
+    assert_equal('Juice::Jem', obj.class.name)
     assert_equal(true, obj.x)
     assert_equal(58, obj.y)
   end
@@ -979,14 +954,14 @@ class Juice < ::Test::Unit::TestCase
     obj.x = obj
     json = Oj.dump(obj, :mode => :object, :indent => 2, :circular => true)
     assert(%{{
-  "^o":"Jam",
+  "^o":"Juice::Jam",
   "^i":1,
   "x":"^r1",
   "y":58
 }
 } == json ||
 %{{
-  "^o":"Jam",
+  "^o":"Juice::Jam",
   "^i":1,
   "y":58,
   "x":"^r1"
@@ -1026,7 +1001,7 @@ class Juice < ::Test::Unit::TestCase
     obj.x['b'] = obj
     json = Oj.dump(obj, :mode => :object, :indent => 2, :circular => true)
     ha = Oj.load(json, :mode => :strict)
-    assert_equal({'^o' => 'Jam', '^i' => 1, 'x' => { '^i' => 2, 'a' => 7, 'b' => '^r1' }, 'y' => 58 }, ha)
+    assert_equal({'^o' => 'Juice::Jam', '^i' => 1, 'x' => { '^i' => 2, 'a' => 7, 'b' => '^r1' }, 'y' => 58 }, ha)
     Oj.load(json, :mode => :object, :circular => true)
     assert_equal(obj.x.__id__, h.__id__)
     assert_equal(h['b'].__id__, obj.__id__)
@@ -1048,7 +1023,7 @@ class Juice < ::Test::Unit::TestCase
       a = []
       10000.times { a << [a] }
       Oj.dump(a)
-    rescue Exception => e
+    rescue Exception
       assert(true)
       return
     end
@@ -1068,7 +1043,7 @@ class Juice < ::Test::Unit::TestCase
 
   def test_io_file
     src = { 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}
-    filename = 'open_file_test.json'
+    filename = File.join(File.dirname(__FILE__), 'open_file_test.json')
     File.open(filename, "w") { |f|
       Oj.to_stream(f, src)
     }
@@ -1129,7 +1104,7 @@ class Juice < ::Test::Unit::TestCase
   def test_nilnil_false
     begin
       Oj.load(nil)
-    rescue Exception => e
+    rescue Exception
       assert(true)
       return
     end
@@ -1141,18 +1116,10 @@ class Juice < ::Test::Unit::TestCase
     assert_equal(nil, obj)
   end
 
-# Rails re-call test. Active support recalls the json dumper when the to_json
-# method is called. This mimics that and verifies Oj detects it.
-  def test_rails_like
-    obj = RailsLike.new(3)
-    json = Oj.dump(obj, :mode => :compat)
-    assert_equal('{"x":3}', json)
-  end
-
   def dump_and_load(obj, trace=false)
     json = Oj.dump(obj, :indent => 2)
     puts json if trace
-    loaded = Oj.load(json);
+    loaded = Oj.load(json)
     assert_equal(obj, loaded)
     loaded
   end
diff --git a/test/test_writer.rb b/test/test_writer.rb
index 0338d60..c2b5e0f 100755
--- a/test/test_writer.rb
+++ b/test/test_writer.rb
@@ -1,21 +1,19 @@
 #!/usr/bin/env ruby
 # encoding: UTF-8
 
-# Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
-# required. That can be set in the RUBYOPT environment variable.
-# export RUBYOPT=-w
+$: << File.dirname(__FILE__)
 
-$VERBOSE = true
+require 'helper'
 
-$: << File.join(File.dirname(__FILE__), "../lib")
-$: << File.join(File.dirname(__FILE__), "../ext")
+class OjWriter < Minitest::Test
 
-require 'test/unit'
-require 'stringio'
-require 'date'
-require 'oj'
+  def setup
+    @default_options = Oj.default_options
+  end
 
-class OjWriter < ::Test::Unit::TestCase
+  def teardown
+    Oj.default_options = @default_options
+  end
 
   def test_string_writer_empty_array
     w = Oj::StringWriter.new(:indent => 0)
@@ -249,7 +247,7 @@ class OjWriter < ::Test::Unit::TestCase
   end
 
   def test_stream_writer_mixed_file
-    filename = 'open_file_writer_test.json'
+    filename = File.join(File.dirname(__FILE__), 'open_file_test.json')
     File.open(filename, "w") do |f|
       w = Oj::StreamWriter.new(f, :indent => 0)
       w.push_object()
diff --git a/test/write_fake_log.rb b/test/write_fake_log.rb
deleted file mode 100755
index 56c9628..0000000
--- a/test/write_fake_log.rb
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/usr/bin/env ruby -wW1
-
-$: << '.'
-$: << '../lib'
-$: << '../ext'
-
-if __FILE__ == $0
-  if (i = ARGV.index('-I'))
-    x,path = ARGV.slice!(i, 2)
-    $: << path
-  end
-end
-
-require 'optparse'
-require 'oj'
-require 'perf'
-
-$indent = 0
-$iter = 1
-
-opts = OptionParser.new
-
-opts.on("-c", "--count [Int]", Integer, "iterations")       { |i| $iter = i }
-opts.on("-i", "--indent [Int]", Integer, "indent")          { |i| $indent = i }
-
-opts.on("-h", "--help", "Show this display")                { puts opts; Process.exit!(0) }
-files = opts.parse(ARGV)
-
-$levels = [ "ERROR", "WARN", "INFO", "DEBUG", "TRACE" ]
-$entry = {
-  "bar" => "0",
-  "level" => "INFO",
-  "message" => "A message",
-  "msgType" => 1,
-  "source" => "Test",
-  "thread" => "main",
-  "version" => 1,
-  "when" => 1400000000000000000,
-}
-
-Oj.default_options = { :mode => :strict, :indent => $indent }
-
-filename = 'log.json'
-File.open(filename, "w") { |f|
-  $iter.times do |i|
-    $entry["bar"] = (1_400_000_000_000 + i * 200) / 1000
-    $entry["when"] = 1_400_000_000_000_000_000 + i * 100_000_000
-    $entry["message"] = "This is log message number #{i} out of #{$iter} entries."
-    $entry["level"] = $levels[i % $levels.size]
-    Oj.to_stream(f, $entry, :indent => $indent)
-    if 0 == $indent
-      f.flush()
-      f.write("\n")
-    end
-  end
-}
-
-$cnt = 0
-perf = Perf.new()
-perf.add('Oj.load_file', '') { Oj.load_file(filename) { |o| $cnt += 1 } }
-perf.run(1)
-
-puts "*** read #{$cnt} entries"
diff --git a/test/x.rb b/test/x.rb
deleted file mode 100755
index 5627e2f..0000000
--- a/test/x.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-#!/usr/bin/env ruby
-# encoding: UTF-8
-
-# Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
-# required. That can be set in the RUBYOPT environment variable.
-# export RUBYOPT=-w
-
-$VERBOSE = true
-
-$: << File.join(File.dirname(__FILE__), "../lib")
-$: << File.join(File.dirname(__FILE__), "../ext")
-
-require 'oj'
-
-# Oj is not able to deserialize all classes that are a subclass of a Ruby
-# Exception. Only exception that take one required string argument in the
-# initialize() method are supported. This is an example of how to write an
-# Exception subclass that supports both a single string intializer and an
-# Exception as an argument. Additional optional arguments can be added as well.
-#
-# The reason for this restriction has to do with a design decision on the part
-# of the Ruby developers. Exceptions are special Objects. They do not follow the
-# rules of other Objects. Exceptions have 'mesg' and a 'bt' attribute. Note that
-# these are not '@mesg' and '@bt'. They can not be set using the normal C or
-# Ruby calls. The only way I have found to set the 'mesg' attribute is through
-# the initializer. Unfortunately that means any subclass that provides a
-# different initializer can not be automatically decoded. A way around this is
-# to use a create function but this example shows an alternative.
-
-class WrapException < StandardError
-  attr_reader :original
-
-  def initialize(msg_or_err)
-    if msg_or_err.is_a?(Exception)
-      super(msg_or_err.message)
-      @original = msg_or_err
-      set_backtrace(msg_or_err.backtrace)
-    else
-      super(message)
-      @original = nil
-    end
-  end
-end
-
-e = WrapException.new(RuntimeError.new("Something broke."))
-
-json = Oj.dump(e, :mode => :object)
-puts "original:\n#{json}"
-# outputs:
-# original:
-# {"^o":"WrapException","original":{"^o":"RuntimeError","~mesg":"Something broke.","~bt":null},"~mesg":"Something broke.","~bt":null}
-
-e2 = Oj.load(json, :mode => :object)
-puts "dumped, loaded, and dumped again:\n#{Oj.dump(e2, :mode => :object)}"
-# outputs:
-# original: {"^o":"WrapException","original":{"^o":"RuntimeError","~mesg":"Something broke.","~bt":null},"~mesg":"Something broke.","~bt":null}
-# dumped, loaded, and dumped again:
-# {"^o":"WrapException","original":{"^o":"RuntimeError","~mesg":"Something broke.","~bt":null},"~mesg":"Something broke.","~bt":null}
-
diff --git a/test/zip.rb b/test/zip.rb
new file mode 100755
index 0000000..4dadbb6
--- /dev/null
+++ b/test/zip.rb
@@ -0,0 +1,34 @@
+#!/usr/bin/env ruby
+# encoding: UTF-8
+
+$: << File.dirname(__FILE__)
+
+require 'helper'
+
+require 'zlib'
+
+File.open('test.json.gz', 'r') do |file|
+  Zlib::GzipReader.wrap(file) do |f2|
+    puts "*** f2: #{f2}"
+    Oj.load(f2) do |val|
+      puts val
+    end
+  end
+end
+
+=begin
+And a json file with the following contents (then gzipped):
+
+{"a":2}
+{"b":2}
+The output is:
+
+{"a"=>2}
+{"b"=>2}
+bin/test:8:in `load': undefined method `new' for #<EOFError: end of file reached> (NoMethodError)
+    from bin/test:8:in `block (2 levels) in <main>'
+    from bin/test:7:in `wrap'
+    from bin/test:7:in `block in <main>'
+    from bin/test:6:in `open'
+    from bin/test:6:in `<main>'
+=end

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-oj.git



More information about the Pkg-ruby-extras-commits mailing list