Skip to content

Commit

Permalink
making oj jruby 1.7 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
ohler55 committed Dec 1, 2012
1 parent 390a416 commit 2d3dae9
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Expand Up @@ -2,7 +2,8 @@ rvm:
- 1.8.7
- 1.9.2
- 1.9.3
- jruby
- jruby-18mode
- jruby-19mode
- rbx
- rbx-19mode
- ree
Expand Down
6 changes: 4 additions & 2 deletions README.md
Expand Up @@ -32,9 +32,11 @@ A fast JSON parser and Object marshaller as a Ruby gem.

## <a name="release">Release Notes</a>

### Release 1.4.5
### Release 1.4.6

- Adds the old deprecated methods of unparse(), fast_unparse(), and pretty_unparse() to JSON_mimic.
- Silently ignores BOM on files and Strings.

-

## <a name="description">Description</a>

Expand Down
3 changes: 3 additions & 0 deletions build_test.sh
@@ -1,9 +1,12 @@
#!/bin/sh

JRUBY_OPTS="-Xcext.enabled=true"

for ruby in \
1.8.7-p358\
1.9.2-p290\
jruby-1.6.7\
jruby-1.7.0\
rbx-1.2.4\
rbx-2.0.0-dev\
ree-1.8.7-2012.02\
Expand Down
13 changes: 12 additions & 1 deletion ext/oj/oj.c
Expand Up @@ -126,7 +126,7 @@ struct _Options oj_default_options = {
};

static VALUE define_mimic_json(int argc, VALUE *argv, VALUE self);
static struct _Odd odds[4]; // bump up if new Odd classes are added
static struct _Odd odds[5]; // bump up if new Odd classes are added

Odd
oj_get_odd(VALUE clas) {
Expand Down Expand Up @@ -970,8 +970,19 @@ void Init_oj() {
*idp++ = rb_intern("offset");
*idp++ = rb_intern("start");
*idp++ = 0;
// Range
odd++;
idp = odd->attrs;
odd->clas = rb_const_get(rb_cObject, rb_intern("Range"));
odd->create_obj = odd->clas;
odd->create_op = oj_new_id;
odd->attr_cnt = 3;
*idp++ = rb_intern("begin");
*idp++ = rb_intern("end");
*idp++ = rb_intern("exclude_end?");
*idp++ = 0;
// The end. bump up the size of odds if a new class is added.
odd++;
odd->clas = Qundef;

#if SAFE_CACHE
Expand Down
16 changes: 12 additions & 4 deletions test/test_mimic.rb
Expand Up @@ -76,6 +76,7 @@ def test_load_io
end

def test_load_proc
Oj.mimic_JSON # TBD
children = []
json = %{{"a":1,"b":[true,false]}}
if 'rubinius' == $ruby || 'jruby' == $ruby || '1.8.7' == RUBY_VERSION
Expand All @@ -85,8 +86,12 @@ def test_load_proc
obj = JSON.load(json, p)
end
assert_equal({ 'a' => 1, 'b' => [true, false]}, obj)
assert([1, true, false, [true, false], { 'a' => 1, 'b' => [true, false]}] == children ||
[true, false, [true, false], 1, { 'a' => 1, 'b' => [true, false]}] == children)
# JRuby 1.7.0 rb_yield() is broken and converts the [true, falser] array into true
unless 'jruby' == $ruby && '1.9.3' == RUBY_VERSION
assert([1, true, false, [true, false], { 'a' => 1, 'b' => [true, false]}] == children ||
[true, false, [true, false], 1, { 'a' => 1, 'b' => [true, false]}] == children,
"children don't match")
end
end

# []
Expand Down Expand Up @@ -193,8 +198,11 @@ def test_parse_bang
def test_recurse_proc
children = []
JSON.recurse_proc({ 'a' => 1, 'b' => [true, false]}) { |x| children << x }
assert([1, true, false, [true, false], { 'a' => 1, 'b' => [true, false]}] == children ||
[true, false, [true, false], 1, { 'b' => [true, false], 'a' => 1}] == children)
# JRuby 1.7.0 rb_yield() is broken and converts the [true, falser] array into true
unless 'jruby' == $ruby && '1.9.3' == RUBY_VERSION
assert([1, true, false, [true, false], { 'a' => 1, 'b' => [true, false]}] == children ||
[true, false, [true, false], 1, { 'b' => [true, false], 'a' => 1}] == children)
end
end

end # Mimic
10 changes: 8 additions & 2 deletions test/tests.rb
Expand Up @@ -192,11 +192,15 @@ def test_string_object
def test_encode
opts = Oj.default_options
Oj.default_options = { :ascii_only => false }
dump_and_load("ぴーたー", false)
unless 'jruby' == $ruby
dump_and_load("ぴーたー", false)
end
Oj.default_options = { :ascii_only => true }
json = Oj.dump("ぴーたー")
assert_equal(%{"\\u3074\\u30fc\\u305f\\u30fc"}, json)
dump_and_load("ぴーたー", false)
unless 'jruby' == $ruby
dump_and_load("ぴーたー", false)
end
Oj.default_options = opts
end

Expand Down Expand Up @@ -623,6 +627,8 @@ def test_range_object
if 'rubinius' == $ruby
assert(%{{"^o":"Range","excl":false,"begin":1,"end":7}} == json ||
%{{"^o":"Range","begin":1,"end":7,"excl":false}} == json)
elsif 'jruby' == $ruby
assert(%{{"^O":"Range","begin":1,"end":7,"exclude_end?":false}} == json)
else
assert_equal(%{{"^u":["Range",1,7,false]}}, json)
end
Expand Down

0 comments on commit 2d3dae9

Please sign in to comment.