Skip to content

Commit

Permalink
modified tests for more consistent results
Browse files Browse the repository at this point in the history
  • Loading branch information
ohler55 committed Mar 21, 2012
1 parent 4a5c71f commit badd659
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ext/oj/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion ext/oj/fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ doc_where(VALUE self) {
*p++ = '/';
}
*--p = '\0';
return rb_str_new2(path);
return rb_str_new(path, p - path);
}
}

Expand Down
26 changes: 26 additions & 0 deletions ext/oj/oj.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit badd659

Please sign in to comment.