Class: PhusionPassenger::Utils::ParserTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- PhusionPassenger::Utils::ParserTest
- Defined in:
- lib/phusion_passenger/utils/json.rb
Constant Summary collapse
Instance Method Summary collapse
- #parse_string(str) ⇒ Object
- #parsed ⇒ Object
- #test_array ⇒ Object
- #test_bool ⇒ Object
- #test_hash ⇒ Object
- #test_invalid ⇒ Object
- #test_nil ⇒ Object
- #test_number ⇒ Object
- #test_string ⇒ Object
- #test_string_specials ⇒ Object
Instance Method Details
#parse_string(str) ⇒ Object
201 |
# File 'lib/phusion_passenger/utils/json.rb', line 201 def parse_string(str) JSON.parse(%(["#{str}"]).gsub('\\\\', '\\')).first end |
#test_array ⇒ Object
227 228 229 |
# File 'lib/phusion_passenger/utils/json.rb', line 227 def test_array assert_equal ["4438f", {"a" => "b"}], parsed['head']['sha'] end |
#test_bool ⇒ Object
220 221 222 223 |
# File 'lib/phusion_passenger/utils/json.rb', line 220 def test_bool assert_equal true, parsed['head']['repository']['fork'] assert_equal false, parsed['head']['repository']['private'] end |
#test_hash ⇒ Object
214 215 216 |
# File 'lib/phusion_passenger/utils/json.rb', line 214 def test_hash assert_equal %w[label ref repository sha user], parsed['head'].keys.sort end |
#test_invalid ⇒ Object
230 231 232 233 234 235 236 237 238 |
# File 'lib/phusion_passenger/utils/json.rb', line 230 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 |
#test_nil ⇒ Object
224 225 226 |
# File 'lib/phusion_passenger/utils/json.rb', line 224 def test_nil assert_nil parsed['head']['user']['company'] end |
#test_number ⇒ Object
217 218 219 |
# File 'lib/phusion_passenger/utils/json.rb', line 217 def test_number assert_equal 124.3e2, parsed['head']['repository']['size'] end |
#test_string ⇒ Object
202 203 204 205 |
# File 'lib/phusion_passenger/utils/json.rb', line 202 def test_string assert_equal "Pagination library for \"Rails 3\", Sinatra, Merb, DataMapper, and more", parsed['head']['repository']['description'] end |
#test_string_specials ⇒ Object
206 207 208 209 210 211 212 213 |
# File 'lib/phusion_passenger/utils/json.rb', line 206 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 |