aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/test_json.rb
blob: 14d2f2b4c90a8c075329440a94a5ea631ae3eec5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
require "testing_env"
require "utils/json"

class JsonSmokeTest < Homebrew::TestCase
  def test_encode
    hash = { "foo" => ["bar", "baz"] }
    json = '{"foo":["bar","baz"]}'
    assert_equal json, Utils::JSON.dump(hash)
  end

  def test_decode
    hash = { "foo" => ["bar", "baz"], "qux" => 1 }
    json = '{"foo":["bar","baz"],"qux":1}'
    assert_equal hash, Utils::JSON.load(json)
  end

  def test_decode_failure
    assert_raises(Utils::JSON::Error) { Utils::JSON.load("nope") }
  end
end