brianmario-yajl-ruby 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/.gitignore +4 -0
  2. data/CHANGELOG.rdoc +13 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +39 -3
  5. data/Rakefile +4 -12
  6. data/VERSION.yml +2 -2
  7. data/benchmark/http.rb +28 -0
  8. data/benchmark/stream.rb +40 -0
  9. data/benchmark/subjects/contacts.json +1 -0
  10. data/benchmark/subjects/item.json +1 -0
  11. data/benchmark/subjects/ohai.json +1216 -0
  12. data/benchmark/subjects/twitter_search.json +1 -0
  13. data/benchmark/subjects/unicode.json +3315 -0
  14. data/benchmark/subjects/yelp.json +1 -0
  15. data/ext/extconf.rb +1 -0
  16. data/ext/yajl.c +86 -40
  17. data/ext/yajl.h +45 -0
  18. data/lib/yajl/http_stream.rb +67 -0
  19. data/lib/yajl.rb +32 -0
  20. data/specs/active_support_spec.rb +50 -0
  21. data/specs/fixtures/fail.15.json +1 -0
  22. data/specs/fixtures/fail.16.json +1 -0
  23. data/specs/fixtures/fail.17.json +1 -0
  24. data/specs/fixtures/fail.26.json +1 -0
  25. data/specs/fixtures/fail11.json +1 -0
  26. data/specs/fixtures/fail12.json +1 -0
  27. data/specs/fixtures/fail13.json +1 -0
  28. data/specs/fixtures/fail14.json +1 -0
  29. data/specs/fixtures/fail19.json +1 -0
  30. data/specs/fixtures/fail20.json +1 -0
  31. data/specs/fixtures/fail21.json +1 -0
  32. data/specs/fixtures/fail22.json +1 -0
  33. data/specs/fixtures/fail23.json +1 -0
  34. data/specs/fixtures/fail24.json +1 -0
  35. data/specs/fixtures/fail25.json +1 -0
  36. data/specs/fixtures/fail27.json +2 -0
  37. data/specs/fixtures/fail28.json +2 -0
  38. data/specs/fixtures/fail3.json +1 -0
  39. data/specs/fixtures/fail4.json +1 -0
  40. data/specs/fixtures/fail5.json +1 -0
  41. data/specs/fixtures/fail6.json +1 -0
  42. data/specs/fixtures/fail9.json +1 -0
  43. data/specs/fixtures/pass.array.json +6 -0
  44. data/specs/fixtures/pass.codepoints_from_unicode_org.json +1 -0
  45. data/specs/fixtures/pass.contacts.json +1 -0
  46. data/specs/fixtures/pass.db100.xml.json +1 -0
  47. data/specs/fixtures/pass.db1000.xml.json +1 -0
  48. data/specs/fixtures/pass.dc_simple_with_comments.json +11 -0
  49. data/specs/fixtures/pass.deep_arrays.json +1 -0
  50. data/specs/fixtures/pass.difficult_json_c_test_case.json +1 -0
  51. data/specs/fixtures/pass.difficult_json_c_test_case_with_comments.json +1 -0
  52. data/specs/fixtures/pass.doubles.json +1 -0
  53. data/specs/fixtures/pass.empty_array.json +1 -0
  54. data/specs/fixtures/pass.empty_string.json +1 -0
  55. data/specs/fixtures/pass.escaped_bulgarian.json +4 -0
  56. data/specs/fixtures/pass.escaped_foobar.json +1 -0
  57. data/specs/fixtures/pass.item.json +1 -0
  58. data/specs/fixtures/pass.json-org-sample1.json +23 -0
  59. data/specs/fixtures/pass.json-org-sample2.json +11 -0
  60. data/specs/fixtures/pass.json-org-sample3.json +26 -0
  61. data/specs/fixtures/pass.json-org-sample4-nows.json +88 -0
  62. data/specs/fixtures/pass.json-org-sample4.json +89 -0
  63. data/specs/fixtures/pass.json-org-sample5.json +27 -0
  64. data/specs/fixtures/pass.map-spain.xml.json +1 -0
  65. data/specs/fixtures/pass.ns-invoice100.xml.json +1 -0
  66. data/specs/fixtures/pass.ns-soap.xml.json +1 -0
  67. data/specs/fixtures/pass.numbers-fp-4k.json +6 -0
  68. data/specs/fixtures/pass.numbers-fp-64k.json +61 -0
  69. data/specs/fixtures/pass.numbers-int-4k.json +11 -0
  70. data/specs/fixtures/pass.numbers-int-64k.json +154 -0
  71. data/specs/fixtures/pass.twitter-search.json +1 -0
  72. data/specs/fixtures/pass.twitter-search2.json +1 -0
  73. data/specs/fixtures/pass.unicode.json +3315 -0
  74. data/specs/fixtures/pass.yelp.json +1 -0
  75. data/specs/fixtures/pass1.json +56 -0
  76. data/specs/fixtures/pass2.json +1 -0
  77. data/specs/fixtures/pass3.json +6 -0
  78. data/specs/fixtures_spec.rb +25 -0
  79. data/specs/one_off_spec.rb +11 -0
  80. data/specs/spec_helper.rb +4 -0
  81. data/yajl-ruby.gemspec +115 -0
  82. metadata +79 -2
@@ -0,0 +1,50 @@
1
+ # encoding: UTF-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper.rb')
3
+
4
+ describe "ActiveSupport test cases" do
5
+ TESTS = {
6
+ %q({"returnTo":{"\/categories":"\/"}}) => {"returnTo" => {"/categories" => "/"}},
7
+ %q({"return\\"To\\":":{"\/categories":"\/"}}) => {"return\"To\":" => {"/categories" => "/"}},
8
+ %q({"returnTo":{"\/categories":1}}) => {"returnTo" => {"/categories" => 1}},
9
+ %({"returnTo":[1,"a"]}) => {"returnTo" => [1, "a"]},
10
+ %({"returnTo":[1,"\\"a\\",", "b"]}) => {"returnTo" => [1, "\"a\",", "b"]},
11
+ %({"a": "'", "b": "5,000"}) => {"a" => "'", "b" => "5,000"},
12
+ %({"a": "a's, b's and c's", "b": "5,000"}) => {"a" => "a's, b's and c's", "b" => "5,000"},
13
+ # multibyte
14
+ %({"matzue": "松江", "asakusa": "浅草"}) => {"matzue" => "松江", "asakusa" => "浅草"},
15
+ %({"a": "2007-01-01"}) => {'a' => "2007-01-01"},
16
+ %({"a": "2007-01-01 01:12:34 Z"}) => {'a' => "2007-01-01 01:12:34 Z"},
17
+ # no time zone
18
+ %({"a": "2007-01-01 01:12:34"}) => {'a' => "2007-01-01 01:12:34"},
19
+ # needs to be *exact*
20
+ %({"a": " 2007-01-01 01:12:34 Z "}) => {'a' => " 2007-01-01 01:12:34 Z "},
21
+ %({"a": "2007-01-01 : it's your birthday"}) => {'a' => "2007-01-01 : it's your birthday"},
22
+ %([]) => [],
23
+ %({}) => {},
24
+ %({"a":1}) => {"a" => 1},
25
+ %({"a": ""}) => {"a" => ""},
26
+ %({"a":"\\""}) => {"a" => "\""},
27
+ %({"a": null}) => {"a" => nil},
28
+ %({"a": true}) => {"a" => true},
29
+ %({"a": false}) => {"a" => false},
30
+ %q({"a": "http:\/\/test.host\/posts\/1"}) => {"a" => "http://test.host/posts/1"},
31
+ %q({"a": "\u003cunicode\u0020escape\u003e"}) => {"a" => "<unicode escape>"},
32
+ %q({"a": "\\\\u0020skip double backslashes"}) => {"a" => "\\u0020skip double backslashes"},
33
+ %q({"a": "\u003cbr /\u003e"}) => {'a' => "<br />"},
34
+ %q({"b":["\u003ci\u003e","\u003cb\u003e","\u003cu\u003e"]}) => {'b' => ["<i>","<b>","<u>"]}
35
+ }
36
+
37
+ TESTS.each do |json, expected|
38
+ it "should be able to parse #{json}" do
39
+ lambda {
40
+ Yajl::Stream.parse(StringIO.new(json)).should == expected
41
+ }.should_not raise_error(Yajl::ParseError)
42
+ end
43
+ end
44
+
45
+ it "should fail parsing {: 1}" do
46
+ lambda {
47
+ Yajl::Stream.parse(StringIO.new("{: 1}"))
48
+ }.should raise_error(Yajl::ParseError)
49
+ end
50
+ end
@@ -0,0 +1 @@
1
+ ["Illegal backslash escape: \x15"]
@@ -0,0 +1 @@
1
+ ["Illegal backslash escape: \'"]
@@ -0,0 +1 @@
1
+ ["Illegal backslash escape: \017"]
@@ -0,0 +1 @@
1
+ ["tab\ character\ in\ string\ "]
@@ -0,0 +1 @@
1
+ {"Illegal expression": 1 + 2}
@@ -0,0 +1 @@
1
+ {"Illegal invocation": alert()}
@@ -0,0 +1 @@
1
+ {"Numbers cannot have leading zeroes": 013}
@@ -0,0 +1 @@
1
+ {"Numbers cannot be hex": 0x14}
@@ -0,0 +1 @@
1
+ {"Missing colon" null}
@@ -0,0 +1 @@
1
+ {"Double colon":: null}
@@ -0,0 +1 @@
1
+ {"Comma instead of colon", null}
@@ -0,0 +1 @@
1
+ ["Colon instead of comma": false]
@@ -0,0 +1 @@
1
+ ["Bad value", truth]
@@ -0,0 +1 @@
1
+ ['single quote']
@@ -0,0 +1 @@
1
+ ["tab character in string "]
@@ -0,0 +1,2 @@
1
+ ["line
2
+ break"]
@@ -0,0 +1,2 @@
1
+ ["line\
2
+ break"]
@@ -0,0 +1 @@
1
+ {unquoted_key: "keys must be quoted"}
@@ -0,0 +1 @@
1
+ ["extra comma",]
@@ -0,0 +1 @@
1
+ ["double extra comma",,]
@@ -0,0 +1 @@
1
+ [ , "<-- missing value"]
@@ -0,0 +1 @@
1
+ {"Extra comma": true,}
@@ -0,0 +1,6 @@
1
+ ["foo",
2
+ "bar", "baz",
3
+ true,false,null,{"key":"value"},
4
+ [null,null,null,[]],
5
+ "\n\r\\"
6
+ ]
@@ -0,0 +1 @@
1
+ "\u004d\u0430\u4e8c\ud800\udf02"