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