Sha256: b7de55ba44c2183e319501604c6f9e916353d08d1420e082845e0cba56f973c2

Contents?: true

Size: 1.88 KB

Versions: 1

Compression:

Stored size: 1.88 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
      parser = Yajl::Parser.new
      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
    parser = Yajl::Parser.new(:allow_comments => false)
    json = StringIO.new('{"key": /* this is a comment */ "value"}')
    lambda {
      parser.parse(json)
    }.should raise_error(Yajl::ParseError)
  end
  
  it "should parse JSON with a comment, with :allow_comments set to true" do
    parser = Yajl::Parser.new(:allow_comments => true)
    json = StringIO.new('{"key": /* this is a comment */ "value"}')
    lambda {
      parser.parse(json)
    }.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 string keys" do
    parser = Yajl::Parser.new(:symbolize_keys => true)
    parser.parse('{"key": 1234}').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

1 entries across 1 versions & 1 rubygems

Version Path
brianmario-yajl-ruby-0.5.3 spec/parsing/one_off_spec.rb