Sha256: d4540318cc679e08d95ee9f7e391e1ae34adf3ec80ca67026322bf6fe2d870f4

Contents?: true

Size: 1.79 KB

Versions: 22

Compression:

Stored size: 1.79 KB

Contents

# encoding: UTF-8
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')

describe "One-off JSON examples" do
  it "should parse 23456789012E666 and return Infinity" do
    infinity = (1.0/0)
    silence_warnings do
      Yajl::Parser.parse(StringIO.new('{"key": 23456789012E666}')).should == {"key" => infinity}
    end
  end
  
  it "should not parse JSON with a comment, with :allow_comments set to false" do
    json = StringIO.new('{"key": /* this is a comment */ "value"}')
    lambda {
      Yajl::Parser.parse(json, :allow_comments => false)
    }.should raise_error(Yajl::ParseError)
  end
  
  it "should parse JSON with a comment, with :allow_comments set to true" do
    json = StringIO.new('{"key": /* this is a comment */ "value"}')
    lambda {
      Yajl::Parser.parse(json, :allow_comments => true)
    }.should_not raise_error(Yajl::ParseError)
  end
  
  it "should not parse invalid UTF8 with :check_utf8 set to true" do
    pending "not sure how to write this test yet"
  end
  
  it "should parse invalid UTF8 with :check_utf8 set to false" do
    pending "not sure how to write this test yet"
  end
  
  it "should parse using it's class method, from an IO" do
    io = StringIO.new('{"key": 1234}')
    Yajl::Parser.parse(io).should == {"key" => 1234}
  end
  
  it "should parse using it's class method, from an IO with symbolized keys" do
    Yajl::Parser.parse('{"key": 1234}', :symbolize_keys => true).should == {:key => 1234}
  end
  
  it "should parse using it's class method, from a string" do
    Yajl::Parser.parse('{"key": 1234}').should == {"key" => 1234}
  end
  
  it "should parse using it's class method, from a string with a block" do
    output = nil
    Yajl::Parser.parse('{"key": 1234}') do |obj|
      output = obj
    end
    output.should == {"key" => 1234}
  end
end

Version data entries

22 entries across 22 versions & 5 rubygems

Version Path
brianmario-yajl-ruby-0.5.10 spec/parsing/one_off_spec.rb
brianmario-yajl-ruby-0.5.11 spec/parsing/one_off_spec.rb
brianmario-yajl-ruby-0.5.12 spec/parsing/one_off_spec.rb
brianmario-yajl-ruby-0.5.7 spec/parsing/one_off_spec.rb
brianmario-yajl-ruby-0.5.8 spec/parsing/one_off_spec.rb
brianmario-yajl-ruby-0.5.9 spec/parsing/one_off_spec.rb
brianmario-yajl-ruby-0.6.0 spec/parsing/one_off_spec.rb
brianmario-yajl-ruby-0.6.1 spec/parsing/one_off_spec.rb
brianmario-yajl-ruby-0.6.3 spec/parsing/one_off_spec.rb
jdg-yajl-ruby-0.5.12 spec/parsing/one_off_spec.rb
oortle-yajl-ruby-0.5.8 spec/parsing/one_off_spec.rb
filipegiusti-yajl-ruby-0.6.4 spec/parsing/one_off_spec.rb
yajl-ruby-0.6.3 spec/parsing/one_off_spec.rb
yajl-ruby-0.6.2 spec/parsing/one_off_spec.rb
yajl-ruby-0.6.0 spec/parsing/one_off_spec.rb
yajl-ruby-0.6.1 spec/parsing/one_off_spec.rb
yajl-ruby-0.5.7 spec/parsing/one_off_spec.rb
yajl-ruby-0.5.8 spec/parsing/one_off_spec.rb
yajl-ruby-0.5.9 spec/parsing/one_off_spec.rb
yajl-ruby-0.5.10 spec/parsing/one_off_spec.rb