require "minitest/spec" require "minitest/autorun" require "fossyl" describe Fossyl do it "encodes bytes" do Fossyl.dump("Fossyl\x9B").must_equal("7:Fossyl\x9B") end it "encodes integers" do Fossyl.dump(12).must_equal("i12e") Fossyl.dump(-12).must_equal("i-12e") Fossyl.dump(0).must_equal("i0e") Fossyl.dump(-0).must_equal("i0e") end it "encodes lists" do Fossyl.dump([1, "Fossyl", -12]).must_equal("li1e6:Fossyli-12ee") end it "encodes dictionaries" do Fossyl.dump(string: "Fossyl", integer: -12, list: [0, 12]).must_equal("d7:integeri-12e4:listli0ei12ee6:string6:Fossyle") end it "decodes bytes" do Fossyl.load("7:Fossyl\x9B").must_equal("Fossyl\x9B".b) end it "decodes integers" do Fossyl.load("i12e").must_equal(12) Fossyl.load("i-12e").must_equal(-12) Fossyl.load("i0e").must_equal(0) end it "decodes lists" do Fossyl.load("li1e6:Fossyli-12ee").must_equal([1, "Fossyl", -12]) end it "decodes dictionaries" do Fossyl.load("d7:integeri-12e4:listli0ei12ee6:string6:Fossyle").must_equal("string" => "Fossyl", "integer" => -12, "list" => [0, 12]) end it "does not decode invalid data" do ->{ Fossyl.load("d6:invalidli0e6:stringe") }.must_raise Fossyl::InvalidBencoding end end