Permalink
Browse files

modified tests for more consistent results

  • Loading branch information...
1 parent 4a5c71f commit badd65904cb0283a2d6cfa43aeb740a9c94ee989 Peter Ohler committed Mar 21, 2012
Showing with 28 additions and 2 deletions.
  1. +1 −1 ext/oj/dump.c
  2. +1 −1 ext/oj/fast.c
  3. +26 −0 ext/oj/oj.c
View
@@ -1034,7 +1034,7 @@ dump_val(VALUE obj, int depth, Out out) {
default: dump_sym_obj(obj, out); break;
}
break;
- case T_ARRAY: dump_array(obj, depth, out); break;
+ case T_ARRAY: dump_array(obj, depth, out); break;
case T_HASH: dump_hash(obj, depth, out->opts->mode, out); break;
case T_CLASS:
switch (out->opts->mode) {
View
@@ -1116,7 +1116,7 @@ doc_where(VALUE self) {
*p++ = '/';
}
*--p = '\0';
- return rb_str_new2(path);
+ return rb_str_new(path, p - path);
}
}
View
@@ -78,6 +78,8 @@ static VALUE object_sym;
static VALUE strict_sym;
static VALUE symbol_keys_sym;
+static VALUE mimic = Qnil;
+
Cache oj_class_cache = 0;
Cache oj_attr_cache = 0;
@@ -91,6 +93,8 @@ struct _Options oj_default_options = {
ObjectMode, // mode
};
+static VALUE define_mimic_json(VALUE self);
+
/* call-seq: default_options() => Hash
*
* Returns the default load and dump options as a Hash. The options are
@@ -411,6 +415,7 @@ void Init_oj() {
rb_define_module_function(Oj, "default_options", get_def_opts, 0);
rb_define_module_function(Oj, "default_options=", set_def_opts, 1);
+ rb_define_module_function(Oj, "mimic_JSON", define_mimic_json, 0);
rb_define_module_function(Oj, "load", load_str, -1);
rb_define_module_function(Oj, "load_file", load_file, -1);
rb_define_module_function(Oj, "dump", dump, -1);
@@ -457,6 +462,27 @@ void Init_oj() {
oj_init_doc();
}
+static VALUE
+define_mimic_json(VALUE self) {
+ if (Qnil == mimic) {
+ mimic = rb_define_module("JSON");
+ // TBD add methods to mimic
+ // [](object, opts={})
+ // restore(source, proc=nil) - alias for load
+ // load(source, proc=nil)
+ // dump(obj, io=nil, limit=nil)
+ // fast_generate(obj, opts=nil)
+ // generate(obj, opts=nil)
+ // parse(source, opts={})
+ // parse!(sournce, opts={})
+ // pretty_generate(obj, opts=nil)
+ // recurse_proc(result, &proc)
+
+ // TBD mode for mimic maps to :compat or :object for higher performance
+ }
+ return mimic;
+}
+
void
_oj_raise_error(const char *msg, const char *xml, const char *current, const char* file, int line) {
int xline = 1;

0 comments on commit badd659

Please sign in to comment.