test/tests.rb in oj-1.0.2 vs test/tests.rb in oj-1.0.3

- old
+ new

@@ -3,10 +3,11 @@ $: << File.join(File.dirname(__FILE__), "../lib") $: << File.join(File.dirname(__FILE__), "../ext") require 'test/unit' +require 'stringio' require 'oj' def hash_eql(h1, h2) return false if h1.size != h2.size h1.keys.each do |k| @@ -68,25 +69,28 @@ opts = Oj.default_options() assert_equal({ :encoding=>nil, :indent=>0, :circular=>false, :auto_define=>true, + :symbol_keys=>false, :mode=>:object}, opts) end def test0_set_options orig = { :encoding=>nil, :indent=>0, :circular=>false, :auto_define=>true, + :symbol_keys=>false, :mode=>:object} o2 = { :encoding=>"UTF-8", :indent=>4, :circular=>true, :auto_define=>false, + :symbol_keys=>false, :mode=>:compat} o3 = { :indent => 4 } Oj.default_options = o2 opts = Oj.default_options() assert_equal(opts, o2); @@ -467,9 +471,33 @@ ha = Oj.load(json, :mode => :strict) assert_equal({'^o' => 'Jam', '^i' => 1, 'x' => { '^i' => 2, 'a' => 7, 'b' => '^r1' }, 'y' => 58 }, ha) obj2 = Oj.load(json, :mode => :object, :circular => true) assert_equal(obj.x.__id__, h.__id__) assert_equal(h['b'].__id__, obj.__id__) + end + +# Stream IO + def test_string_io + json = %{{ + "x":true, + "y":58, + "z": [1,2,3] +} +} + input = StringIO.new(json) + obj = Oj.load(input, :mode => :strict) + assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj) + end + + def test_symbol_keys + json = %{{ + "x":true, + "y":58, + "z": [1,2,3] +} +} + obj = Oj.load(json, :mode => :strict, :symbol_keys => true) + assert_equal({ :x => true, :y => 58, :z => [1, 2, 3]}, obj) end def dump_and_load(obj, trace=false) json = Oj.dump(obj, :indent => 2) puts json if trace