Test::Unit::TestCase
# File lib/phusion_passenger/utils/json.rb, line 210 def parse_string(str) JSON.parse(%(["#{str}"]).gsub('\\', '\')).first end
# File lib/phusion_passenger/utils/json.rb, line 209 def parsed() PARSED end
# File lib/phusion_passenger/utils/json.rb, line 236 def test_array assert_equal ["4438f", {"a" => "b"}], parsed['head']['sha'] end
# File lib/phusion_passenger/utils/json.rb, line 229 def test_bool assert_equal true, parsed['head']['repository']['fork'] assert_equal false, parsed['head']['repository']['private'] end
# File lib/phusion_passenger/utils/json.rb, line 223 def test_hash assert_equal ]label ref repository sha user], parsed['head'].keys.sort end
# File lib/phusion_passenger/utils/json.rb, line 239 def test_invalid assert_raises(RuntimeError) { JSON.parse %({) } assert_raises(RuntimeError) { JSON.parse %({ "foo": }) } assert_raises(RuntimeError) { JSON.parse %([ "foo": "bar" ]) } assert_raises(RuntimeError) { JSON.parse %([ ~"foo" ]) } assert_raises(RuntimeError) { JSON.parse %([ "foo ]) } assert_raises(RuntimeError) { JSON.parse %([ "foo\\" ]) } assert_raises(RuntimeError) { JSON.parse %([ "foo\\uabGd" ]) } end
# File lib/phusion_passenger/utils/json.rb, line 269 def test_multi_line_comments source = %{ /* comment before * document */ { /* comment */ "foo": "1", "bar": "2", /* another comment */ "baz": "3", "array": [ /* comment inside array */ 1, 2, 3, 4, /* comment inside an array */ 5, /* // "nested" comments { "faux json": "inside comment" } */ 6, 7 /** * comment at end of array */ ] /************************** comment at end of hash **************************/ } /* comment after document */ } doc = { "foo" => "1", "bar" => "2", "baz" => "3", "array" => [1, 2, 3, 4, 5, 6, 7] } assert_equal(doc, JSON.parse(source)) end
# File lib/phusion_passenger/utils/json.rb, line 233 def test_nil assert_nil parsed['head']['user']['company'] end
# File lib/phusion_passenger/utils/json.rb, line 226 def test_number assert_equal 124.3e2, parsed['head']['repository']['size'] end
# File lib/phusion_passenger/utils/json.rb, line 248 def test_single_line_comments source = %{ // comment before document { // comment "foo": "1", "bar": "2", // another comment "baz": "3", "array": [ // comment inside array 1, 2, 3 // comment at end of array ] // comment at end of hash } // comment after document } doc = { "foo" => "1", "bar" => "2", "baz" => "3", "array" => [1, 2, 3] } assert_equal(doc, JSON.parse(source)) end
# File lib/phusion_passenger/utils/json.rb, line 211 def test_string assert_equal "Pagination library for \"Rails 3\", Sinatra, Merb, DataMapper, and more", parsed['head']['repository']['description'] end
# File lib/phusion_passenger/utils/json.rb, line 215 def test_string_specials assert_equal "\r\n\t\f\b", parse_string('\r\n\t\f\b') assert_equal "aA", parse_string('\u0061\u0041') assert_equal "\e", parse_string('\u001B') assert_equal "xyz", parse_string('\x\y\z') assert_equal '"\/', parse_string('\"\\\/') assert_equal 'no #{interpolation}', parse_string('no #{interpolation}') end
Generated with the Darkfish Rdoc Generator 2.