| Name | Total Lines | Lines of Code | Total Coverage | Code Coverage | 
|---|---|---|---|---|
| spec/json_spec.rb | 126 | 101 | 100.00% | 100.00% | 
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
| 1 require File.expand_path('../spec_helper', __FILE__) | 
| 2 require 'asir/coder/json' | 
| 3 | 
| 4 describe "ASIR::Coder::JSON" do | 
| 5 before(:each) do | 
| 6 @enc = ASIR::Coder::JSON.new | 
| 7 @dec = @enc.dup | 
| 8 end | 
| 9 | 
| 10 basic_objs = [ ] | 
| 11 | 
| 12 [ | 
| 13 [ nil, 'null' ], | 
| 14 true, | 
| 15 false, | 
| 16 ].each do | x | | 
| 17 x, str = *x | 
| 18 str ||= x.inspect | 
| 19 str = "[#{str}]" | 
| 20 basic_objs << [ x, str ] | 
| 21 it "should handle #{x.inspect}" do | 
| 22 out = @enc.encode(x) | 
| 23 out.should == str | 
| 24 @dec.decode(out).should == x | 
| 25 end | 
| 26 end | 
| 27 | 
| 28 [ | 
| 29 1234, | 
| 30 1.234, | 
| 31 [ :symbol, '"symbol"' ], | 
| 32 ].each do | x | | 
| 33 x, str = *x | 
| 34 str ||= x.inspect | 
| 35 str = "[#{str}]" | 
| 36 basic_objs << [ x, str ] | 
| 37 it "should handle #{x.inspect}" do | 
| 38 out = @enc.encode(x) | 
| 39 out.should == str | 
| 40 y = @dec.decode(out) | 
| 41 y = y.to_sym if Symbol === x | 
| 42 y.should == x | 
| 43 end | 
| 44 end | 
| 45 | 
| 46 [ | 
| 47 'String', | 
| 48 ].each do | x | | 
| 49 x, str = *x | 
| 50 str ||= x.inspect | 
| 51 str = "[#{str}]" | 
| 52 basic_objs << [ x, str ] | 
| 53 it "should handle #{x.inspect}" do | 
| 54 out = @enc.encode(x) | 
| 55 out.should == str | 
| 56 y = @dec.decode(out) | 
| 57 y.should == x | 
| 58 end | 
| 59 end | 
| 60 | 
| 61 it "should handle empty Array" do | 
| 62 x = [ ] | 
| 63 out = @enc.encode(x) | 
| 64 out.should == "[[]]" | 
| 65 @dec.decode(out).should == x | 
| 66 end | 
| 67 | 
| 68 it "should handle Array" do | 
| 69 x = basic_objs.map{|e| e[0]} | 
| 70 out = @enc.encode(x) | 
| 71 out.should == "[[null,true,false,1234,1.234,\"symbol\",\"String\"]]" | 
| 72 y = @dec.decode(out) | 
| 73 y.should == x.map{|e| Symbol === e ? e.to_s : e } | 
| 74 end | 
| 75 | 
| 76 it "should handle empty Hash" do | 
| 77 x = { } | 
| 78 out = @enc.encode(x) | 
| 79 out.should == "[{}]" | 
| 80 @dec.decode(out).should == x | 
| 81 end | 
| 82 | 
| 83 it "should handle Hash" do | 
| 84 x = Hash[ *basic_objs.flatten.reverse ] | 
| 85 out = @enc.encode(x) | 
| 86 out.should =~ %r{\A\[\{} | 
| 87 out.should =~ %r{\}\]\Z} | 
| 88 basic_objs.each do | v, str | | 
| 89 # out.should =~ %r{#{k.inspect}:} | 
| 90 out.should =~ %r{#{str}} | 
| 91 end | 
| 92 y = @dec.decode(out) | 
| 93 y.should == x.inject({}){|h, (k, v)| h[k] = Symbol === v ? v.to_s : v; h } | 
| 94 end | 
| 95 | 
| 96 module ASIR::Coder::Test | 
| 97 class Object | 
| 98 attr_accessor :a, :h, :o | 
| 99 end | 
| 100 end | 
| 101 | 
| 102 it "should handle deep objects" do | 
| 103 x = ASIR::Coder::Test::Object.new | 
| 104 x.a = [ *basic_objs.map{|a| a[0]} ] | 
| 105 x.h = Hash[ *basic_objs.flatten.reverse ] | 
| 106 x.o = ASIR::Coder::Test::Object.new | 
| 107 x.o.a = 123 | 
| 108 out = @enc.encode(x) | 
| 109 # FIXME: | 
| 110 out.should =~ %r{\A\[\"#<ASIR::Coder::Test::Object:[^>]+>\"\]\Z} | 
| 111 #out.should =~ %r{<#{x.class.name.gsub('::', '.')} id=\"#{x.object_id}\" >} | 
| 112 #out.should =~ %r{</#{x.class.name.gsub('::', '.')}>} | 
| 113 y = @dec.decode(out) | 
| 114 (String === y).should == true | 
| 115 =begin | 
| 116 FIXME: | 
| 117 y.a.should == x.a | 
| 118 y.h.should == x.h | 
| 119 y.o.class.should == ASIR::Coder::Test::Object | 
| 120 y.o.a.should == x.o.a | 
| 121 x.instance_variables.sort { | a, b | a.to_s <=> b.to_s }.should == | 
| 122 y.instance_variables.sort { | a, b | a.to_s <=> b.to_s } | 
| 123 =end | 
| 124 end | 
| 125 end | 
| 126 | 
Generated on Fri Jan 27 17:37:46 -0600 2012 with rcov 0.9.8