2015-08-03 13:09:07 +01:00
|
|
|
require "testing_env"
|
2016-11-20 13:00:01 -05:00
|
|
|
require "json"
|
2013-01-14 22:32:37 -06:00
|
|
|
|
2014-06-18 20:32:51 -05:00
|
|
|
class JsonSmokeTest < Homebrew::TestCase
|
2013-01-14 22:32:37 -06:00
|
|
|
def test_encode
|
2013-01-17 22:25:29 -06:00
|
|
|
hash = { "foo" => ["bar", "baz"] }
|
2015-08-03 13:09:07 +01:00
|
|
|
json = '{"foo":["bar","baz"]}'
|
2016-11-20 13:00:01 -05:00
|
|
|
assert_equal json, JSON.generate(hash)
|
2013-01-14 22:32:37 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_decode
|
|
|
|
hash = { "foo" => ["bar", "baz"], "qux" => 1 }
|
2015-08-03 13:09:07 +01:00
|
|
|
json = '{"foo":["bar","baz"],"qux":1}'
|
2016-11-20 13:00:01 -05:00
|
|
|
assert_equal hash, JSON.parse(json)
|
2013-01-14 22:32:37 -06:00
|
|
|
end
|
2015-12-19 11:54:53 +01:00
|
|
|
|
|
|
|
def test_decode_failure
|
2016-11-20 13:00:01 -05:00
|
|
|
assert_raises(JSON::ParserError) { JSON.parse("nope") }
|
2015-12-19 11:54:53 +01:00
|
|
|
end
|
2013-01-14 22:32:37 -06:00
|
|
|
end
|