Sha256: 28b668b57ada061d1f8ceea57bf785c3ba3e3bac5e5518d39d1d502535c2010b

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

require 'test_helper'

class WankelTest < ::Test::Unit::TestCase

  test "dump should exist as a class-method" do
    assert(Wankel.respond_to?(:dump))
  end

  test "dump should be able to encode to a string" do
    assert_equal('{"a":1234}', Wankel.dump({:a => 1234}))
  end

  test "dump should be able to encode to an IO" do
    io = StringIO.new
    Wankel.dump({:a => 1234}, io)
    io.rewind
    assert_equal('{"a":1234}', io.read)
  end

  test "load should exist as a class-method" do
    assert(Wankel.respond_to?(:load))
  end

  test "load should be able to parse from a string" do
    assert_equal({"a" => 1234}, Wankel.load('{"a":1234}'))
  end

  test "load should be able to parse from an IO" do
    io = StringIO.new('{"a":1234}')
    assert_equal({"a" => 1234}, Wankel.load(io))
  end

  test "load should be able to parse from a string with a block supplied" do
    Wankel.load('{"a":1234}') do |h|
      assert_equal({"a" => 1234}, h)
    end
  end

  test "load should be able to parse from an IO with a block supplied" do
    io = StringIO.new('{"a":1234}')
    Wankel.load(io) do |h|
      assert_equal({"a" => 1234}, h)
    end
  end
  
  test "If I cause a segfault after GC runs I've failed" do
    io = StringIO.new
    assert_raises TypeError do
      Wankel.parse({:a => 1234}, io)
    end
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wankel-0.1.0 test/wankel_test.rb