ruby-json 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/README +3 -1
  2. data/{lib/json → json}/lexer.rb +4 -1
  3. data/{lib/json → json}/objects.rb +4 -4
  4. data/rakefile +61 -0
  5. data/test/objtest.rb +162 -1
  6. metadata +31 -102
  7. data/doc/classes/Array.html +0 -162
  8. data/doc/classes/Array.src/M000011.html +0 -27
  9. data/doc/classes/Array.src/M000012.html +0 -32
  10. data/doc/classes/ArrayTest.html +0 -129
  11. data/doc/classes/ArrayTest.src/M000014.html +0 -28
  12. data/doc/classes/FalseClass.html +0 -131
  13. data/doc/classes/FalseClass.src/M000013.html +0 -18
  14. data/doc/classes/Hash.html +0 -156
  15. data/doc/classes/Hash.src/M000009.html +0 -29
  16. data/doc/classes/Hash.src/M000010.html +0 -45
  17. data/doc/classes/JSON.html +0 -103
  18. data/doc/classes/JSON/Lexer.html +0 -411
  19. data/doc/classes/JSON/Lexer.src/M000022.html +0 -19
  20. data/doc/classes/JSON/Lexer.src/M000023.html +0 -18
  21. data/doc/classes/JSON/Lexer.src/M000024.html +0 -18
  22. data/doc/classes/JSON/Lexer.src/M000025.html +0 -20
  23. data/doc/classes/JSON/Lexer.src/M000026.html +0 -20
  24. data/doc/classes/JSON/Lexer.src/M000027.html +0 -21
  25. data/doc/classes/JSON/Lexer.src/M000028.html +0 -43
  26. data/doc/classes/JSON/Lexer.src/M000029.html +0 -67
  27. data/doc/classes/JSON/Lexer.src/M000030.html +0 -46
  28. data/doc/classes/JSON/Lexer.src/M000031.html +0 -26
  29. data/doc/classes/JSON/Lexer.src/M000032.html +0 -61
  30. data/doc/classes/JSON/Lexer.src/M000033.html +0 -29
  31. data/doc/classes/JSON/Lexer.src/M000034.html +0 -18
  32. data/doc/classes/JSON/Lexer.src/M000035.html +0 -19
  33. data/doc/classes/JSON/Lexer.src/M000036.html +0 -20
  34. data/doc/classes/LexerTest.html +0 -219
  35. data/doc/classes/LexerTest.src/M000002.html +0 -24
  36. data/doc/classes/LexerTest.src/M000003.html +0 -22
  37. data/doc/classes/LexerTest.src/M000004.html +0 -26
  38. data/doc/classes/LexerTest.src/M000005.html +0 -23
  39. data/doc/classes/LexerTest.src/M000006.html +0 -31
  40. data/doc/classes/LexerTest.src/M000007.html +0 -27
  41. data/doc/classes/LexerTest.src/M000008.html +0 -58
  42. data/doc/classes/NilClass.html +0 -131
  43. data/doc/classes/NilClass.src/M000017.html +0 -18
  44. data/doc/classes/Numeric.html +0 -131
  45. data/doc/classes/Numeric.src/M000016.html +0 -18
  46. data/doc/classes/Object.html +0 -176
  47. data/doc/classes/Object.src/M000018.html +0 -18
  48. data/doc/classes/ObjectTest.html +0 -129
  49. data/doc/classes/ObjectTest.src/M000015.html +0 -28
  50. data/doc/classes/String.html +0 -151
  51. data/doc/classes/String.src/M000019.html +0 -18
  52. data/doc/classes/String.src/M000020.html +0 -46
  53. data/doc/classes/TrueClass.html +0 -131
  54. data/doc/classes/TrueClass.src/M000021.html +0 -18
  55. data/doc/created.rid +0 -1
  56. data/doc/files/install_rb.html +0 -194
  57. data/doc/files/install_rb.src/M000001.html +0 -43
  58. data/doc/files/json/lexer_rb.html +0 -156
  59. data/doc/files/json/objects_rb.html +0 -154
  60. data/doc/files/test/arraytest_rb.html +0 -150
  61. data/doc/files/test/lexertest_rb.html +0 -150
  62. data/doc/files/test/objtest_rb.html +0 -150
  63. data/doc/fr_class_index.html +0 -39
  64. data/doc/fr_file_index.html +0 -32
  65. data/doc/fr_method_index.html +0 -62
  66. data/doc/index.html +0 -24
  67. data/doc/rdoc-style.css +0 -175
  68. data/ruby-json.gemspec +0 -25
data/README CHANGED
@@ -13,4 +13,6 @@ library.
13
13
 
14
14
  Thanks to Adam Kramer for some serious changes for the better.
15
15
 
16
- $Id: README,v 1.2 2005/01/28 02:46:22 didosevilla Exp $
16
+ 2006/02/08 Incorporates changes by Tim Myrtle
17
+
18
+ $Id: README,v 1.3 2006/02/08 20:02:22 tmyrtle Exp $
@@ -22,12 +22,15 @@
22
22
  # Some bugs fixed by Adam Kramer (mailto:adam@the-kramers.net)
23
23
  # Copyright:: Copyright (c) 2003,2005 Rafael R. Sevilla
24
24
  # License:: GNU Lesser General Public License
25
- # $Id: lexer.rb,v 1.7 2005/01/28 02:42:10 didosevilla Exp $
25
+ # $Id: lexer.rb,v 1.8 2006/02/09 18:14:20 tmyrtle Exp $
26
26
  #
27
27
  require 'json/objects'
28
28
  require 'cgi'
29
29
 
30
30
  module JSON
31
+
32
+ VERSION = '1.1.2'
33
+
31
34
  class Lexer
32
35
  # This method will initialize the lexer to contain a string.
33
36
  # =====Parameters
@@ -22,7 +22,7 @@
22
22
  # Heavily modified by Adam Kramer (mailto:adam@the-kramers.net)
23
23
  # Copyright:: Copyright (c) 2003,2005 Rafael R. Sevilla
24
24
  # License:: GNU Lesser General Public License
25
- # $Id: objects.rb,v 1.1 2005/01/28 02:08:45 didosevilla Exp $
25
+ # $Id: objects.rb,v 1.2 2006/02/08 20:02:23 tmyrtle Exp $
26
26
  #
27
27
 
28
28
 
@@ -70,7 +70,7 @@ class String
70
70
  |b|
71
71
  c = b.chr
72
72
  case c
73
- when /\\|\">/
73
+ when /\\|\"|\//
74
74
  newstr << "\\" + c
75
75
  when "\b"
76
76
  newstr << "\\b"
@@ -122,7 +122,7 @@ class Array
122
122
  # +lexer+:: Lexer object to use
123
123
  def from_json(lexer)
124
124
  raise "A JSON Array must begin with '['" if (lexer.nextclean != "[")
125
- return if lexer.nextclean == ']'
125
+ return (self) if lexer.nextclean == ']'
126
126
  lexer.back
127
127
  loop {
128
128
  self << lexer.nextvalue
@@ -177,7 +177,7 @@ class Hash
177
177
  when '\0'
178
178
  raise "A JSON Object must end with '}'"
179
179
  when '}'
180
- return;
180
+ return (self);
181
181
  else
182
182
  lexer.back
183
183
  key = lexer.nextvalue().to_s()
@@ -0,0 +1,61 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+
8
+ require 'json/lexer'
9
+
10
+ PKG_NAME = 'ruby-json'
11
+ PKG_VERSION = JSON::VERSION
12
+ PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
13
+
14
+ desc "Default Task"
15
+ task :default => [ :clean, :test ]
16
+
17
+ desc "Clean up directory"
18
+ task :clean do
19
+ rm_rf 'pkg'
20
+ rm_rf 'doc'
21
+ end
22
+
23
+ # Run the unit tests
24
+ Rake::TestTask.new { |t|
25
+ t.libs << "test"
26
+ t.pattern = 'test/*test.rb'
27
+ t.verbose = true
28
+ }
29
+
30
+ # Genereate the RDoc documentation
31
+ Rake::RDocTask.new { |rdoc|
32
+ rdoc.rdoc_dir = 'doc'
33
+ rdoc.rdoc_files.include('README')
34
+ rdoc.rdoc_files.include('json/*.rb')
35
+ }
36
+
37
+ # Create compressed packages
38
+ spec = Gem::Specification.new do |s|
39
+ s.platform = Gem::Platform::RUBY
40
+
41
+ s.name = PKG_NAME
42
+ s.summary = "ruby-json is a library for using JavaScript Object Notation (JSON) under Ruby."
43
+ s.description = "ruby-json is a library able to serialize and deserialize Ruby objects to and from their JSON representation."
44
+ s.version = PKG_VERSION
45
+
46
+ s.author = "Rafael R. Sevilla"
47
+ s.email = "dido@imperium.ph"
48
+ s.homepage = "http://sourceforge.net/projects/json"
49
+
50
+ s.has_rdoc = true
51
+ s.require_path = '.'
52
+ s.autorequire = 'json/lexer'
53
+
54
+ s.files = Dir.glob("**/*").delete_if { |item| item.include?("CVS") }
55
+ end
56
+
57
+ Rake::GemPackageTask.new(spec) do |p|
58
+ p.gem_spec = spec
59
+ p.need_tar = true
60
+ end
61
+
@@ -21,7 +21,7 @@
21
21
  # Author:: Rafael R. Sevilla (mailto:dido@imperium.ph)
22
22
  # Copyright:: Copyright (c) 2003 Rafael R. Sevilla
23
23
  # License:: GNU Lesser General Public License
24
- # $Id: objtest.rb,v 1.2 2005/01/28 02:59:30 didosevilla Exp $
24
+ # $Id: objtest.rb,v 1.3 2006/02/08 20:02:22 tmyrtle Exp $
25
25
  #
26
26
 
27
27
  require 'test/unit'
@@ -42,4 +42,165 @@ class ObjectTest < Test::Unit::TestCase
42
42
  assert(sobj['xyz'] == 1, "error in serialization of a FixNum to JSON")
43
43
  assert(sobj['euler'] == 0.577215665, "error in serialization of a float to JSON")
44
44
  end
45
+
46
+
47
+ def test_to_json_string
48
+ obj = { "key"=>"value" }
49
+ str = obj.to_json
50
+ assert(str == '{"key":"value"}', "basic serialization")
51
+ sobj = JSON::Lexer.new(str).nextvalue
52
+ assert(sobj["key"] == obj["key"], "basic deserialization")
53
+
54
+ obj = { "key"=>'"' }
55
+ str = obj.to_json
56
+ assert(str == '{"key":"\""}', "basic serialization-quote")
57
+ sobj = JSON::Lexer.new(str).nextvalue
58
+ assert(sobj["key"] == obj["key"], "basic deserialization-quote")
59
+
60
+ obj = { "key"=>'/' }
61
+ str = obj.to_json
62
+ assert(str == '{"key":"\/"}', "basic serialization-solidus")
63
+ sobj = JSON::Lexer.new(str).nextvalue
64
+ assert(sobj["key"] == obj["key"], "basic deserialization-solidus")
65
+
66
+ obj = { "key"=>'\\' }
67
+ str = obj.to_json
68
+ assert(str == '{"key":"\\\\"}', "basic serialization-reverse solidus")
69
+ sobj = JSON::Lexer.new(str).nextvalue
70
+ assert(sobj["key"] == obj["key"], "basic deserialization-reverse solidus")
71
+
72
+ obj = { "key"=>"\b" }
73
+ str = obj.to_json
74
+ assert(str == '{"key":"\b"}', "basic serialization-backspace")
75
+ sobj = JSON::Lexer.new(str).nextvalue
76
+ assert(sobj["key"] == obj["key"], "basic serialization-backspace")
77
+
78
+ obj = { "key"=>"\f" }
79
+ str = obj.to_json
80
+ assert(str == '{"key":"\f"}', "basic serialization-formfeed")
81
+ sobj = JSON::Lexer.new(str).nextvalue
82
+ assert(sobj["key"] == obj["key"], "basic deserialization-formfeed")
83
+
84
+ obj = { "key"=>"\n" }
85
+ str = obj.to_json
86
+ assert(str == '{"key":"\n"}', "basic serialization-newline")
87
+ sobj = JSON::Lexer.new(str).nextvalue
88
+ assert(sobj["key"] == obj["key"], "basic deserialization-newline")
89
+
90
+ obj = { "key"=>"\r" }
91
+ str = obj.to_json
92
+ assert(str == '{"key":"\r"}', "basic serialization-carriage return")
93
+ sobj = JSON::Lexer.new(str).nextvalue
94
+ assert(sobj["key"] == obj["key"], "basic deserialization-carriage return")
95
+
96
+ obj = { "key"=>"\t" }
97
+ str = obj.to_json
98
+ assert(str == '{"key":"\t"}', "basic serialization-horizontal tab")
99
+ sobj = JSON::Lexer.new(str).nextvalue
100
+ assert(sobj["key"] == obj["key"], "basic deserialization-horizontal tab")
101
+ end
102
+
103
+
104
+ def test_to_json_number
105
+ obj = { "key"=>125 }
106
+ str = obj.to_json
107
+ assert(str == '{"key":125}', "basic serialization-integer")
108
+ sobj = JSON::Lexer.new(str).nextvalue
109
+ assert(sobj["key"] == obj["key"], "basic deserialization-integer")
110
+
111
+ obj = { "key"=>-125 }
112
+ str = obj.to_json
113
+ assert(str == '{"key":-125}', "basic serialization-negative integer")
114
+ sobj = JSON::Lexer.new(str).nextvalue
115
+ assert(sobj["key"] == obj["key"], "basic deserialization-negative integer")
116
+
117
+ obj = { "key"=>125.27 }
118
+ str = obj.to_json
119
+ assert(str == '{"key":125.27}', "basic serialization-float")
120
+ sobj = JSON::Lexer.new(str).nextvalue
121
+ assert(sobj["key"] == obj["key"], "basic deserialization-float")
122
+
123
+ obj = { "key"=>-125.27 }
124
+ str = obj.to_json
125
+ assert(str == '{"key":-125.27}', "basic serialization-negative float")
126
+ sobj = JSON::Lexer.new(str).nextvalue
127
+ assert(sobj["key"] == obj["key"], "basic deserialization-negative float")
128
+ end
129
+
130
+
131
+ def test_to_json_bool
132
+ obj = { "key"=>true }
133
+ str = obj.to_json
134
+ assert(str == '{"key":true}', "basic serialization-true")
135
+ sobj = JSON::Lexer.new(str).nextvalue
136
+ assert(sobj["key"] == obj["key"], "basic deserialization-true")
137
+
138
+ obj = { "key"=>false }
139
+ str = obj.to_json
140
+ assert(str == '{"key":false}', "basic serialization-false")
141
+ sobj = JSON::Lexer.new(str).nextvalue
142
+ assert(sobj["key"] == obj["key"], "basic deserialization-false")
143
+ end
144
+
145
+
146
+ def test_to_json_null
147
+ obj = { "key"=>nil }
148
+ str = obj.to_json
149
+ assert(str == '{"key":null}', "basic serialization-null")
150
+ sobj = JSON::Lexer.new(str).nextvalue
151
+ assert(sobj["key"] == obj["key"], "basic deserialization-null")
152
+ end
153
+
154
+
155
+ def test_to_json_empty
156
+ obj = { "key"=>[] }
157
+ str = obj.to_json
158
+ assert(str == '{"key":[]}', "basic serialization-empty array")
159
+ sobj = JSON::Lexer.new(str).nextvalue
160
+ assert(sobj["key"].class==Array, "basic deserialization-empty array1")
161
+ assert(sobj["key"].length==0, "basic deserialization-empty array2")
162
+
163
+ obj = { "key"=>{} }
164
+ str = obj.to_json
165
+ assert(str == '{"key":{}}', "basic serialization-empty hash")
166
+ sobj = JSON::Lexer.new(str).nextvalue
167
+ assert(sobj["key"].class==Hash, "basic deserialization-empty hash1")
168
+ assert(sobj["key"].length==0, "basic deserialization-empty hash2")
169
+
170
+ obj = { "key"=>"" }
171
+ str = obj.to_json
172
+ assert(str == '{"key":""}', "basic serialization-empty string")
173
+ sobj = JSON::Lexer.new(str).nextvalue
174
+ assert(sobj["key"] == obj["key"], "basic deserialization-empty string")
175
+ end
176
+
177
+
178
+ def test_to_json_subobject
179
+ obj = { "key"=>{ "key"=>"value" } }
180
+ str = obj.to_json
181
+ assert(str == '{"key":{"key":"value"}}', "basic serialization-subobject hash")
182
+ sobj = JSON::Lexer.new(str).nextvalue
183
+ assert(sobj["key"] == obj["key"], "basic deserialization-subobject hash")
184
+
185
+ obj = { "key"=>[1,2,3] }
186
+ str = obj.to_json
187
+ assert(str == '{"key":[1,2,3]}', "basic serialization-subobject array")
188
+ sobj = JSON::Lexer.new(str).nextvalue
189
+ assert(sobj["key"] == obj["key"], "basic deserialization-subobject array")
190
+
191
+ obj = { "key"=>[1,2,[4,5]] }
192
+ str = obj.to_json
193
+ assert(str == '{"key":[1,2,[4,5]]}', "basic serialization-subobject array")
194
+ sobj = JSON::Lexer.new(str).nextvalue
195
+ assert(sobj["key"] == obj["key"], "basic deserialization-subobject array")
196
+
197
+ obj = { "key"=>[1,2,{"key"=>"value"}] }
198
+ str = obj.to_json
199
+ assert(str == '{"key":[1,2,{"key":"value"}]}', "basic serialization-subobject array/hash")
200
+ sobj = JSON::Lexer.new(str).nextvalue
201
+ assert(sobj["key"] == obj["key"], "basic deserialization-subobject array/hash")
202
+
203
+
204
+ end
205
+
45
206
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.5
2
+ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: ruby-json
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.1.1
7
- date: 2005-01-28
8
- summary: ruby-json is a library for using the JavaScript Object Notation (JSON) under Ruby.
6
+ version: 1.1.2
7
+ date: 2006-02-09 00:00:00 -08:00
8
+ summary: ruby-json is a library for using JavaScript Object Notation (JSON) under Ruby.
9
9
  require_paths:
10
- - lib
10
+ - .
11
11
  email: dido@imperium.ph
12
12
  homepage: http://sourceforge.net/projects/json
13
13
  rubyforge_project:
@@ -18,109 +18,38 @@ bindir: bin
18
18
  has_rdoc: true
19
19
  required_ruby_version: !ruby/object:Gem::Version::Requirement
20
20
  requirements:
21
- -
22
- - ">"
23
- - !ruby/object:Gem::Version
24
- version: 0.0.0
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
25
24
  version:
26
25
  platform: ruby
27
- authors: []
26
+ signing_key:
27
+ cert_chain:
28
+ authors:
29
+ - Rafael R. Sevilla
28
30
  files:
29
- - doc
30
- - lib/json
31
- - test
32
- - README
33
- - ruby-json.gemspec
34
- - install.rb
35
- - COPYING
36
- - doc/files
37
- - doc/index.html
38
- - doc/rdoc-style.css
39
- - doc/fr_method_index.html
40
- - doc/fr_class_index.html
41
- - doc/fr_file_index.html
42
- - doc/created.rid
43
- - doc/classes
44
- - doc/files/json
45
- - doc/files/test
46
- - doc/files/install_rb.html
47
- - doc/files/install_rb.src
48
- - doc/files/json/lexer_rb.html
49
- - doc/files/json/objects_rb.html
50
- - doc/files/test/lexertest_rb.html
51
- - doc/files/test/objtest_rb.html
52
- - doc/files/test/arraytest_rb.html
53
- - doc/files/install_rb.src/M000001.html
54
- - doc/classes/JSON
55
- - doc/classes/Hash.html
56
- - doc/classes/ObjectTest.html
57
- - doc/classes/JSON.html
58
- - doc/classes/String.html
59
- - doc/classes/Array.src
60
- - doc/classes/Numeric.src
61
- - doc/classes/Hash.src
62
- - doc/classes/NilClass.html
63
- - doc/classes/LexerTest.src
64
- - doc/classes/String.src
65
- - doc/classes/Object.src
66
- - doc/classes/Object.html
67
- - doc/classes/FalseClass.src
68
- - doc/classes/Array.html
69
- - doc/classes/ObjectTest.src
70
- - doc/classes/TrueClass.src
71
- - doc/classes/TrueClass.html
72
- - doc/classes/FalseClass.html
73
- - doc/classes/LexerTest.html
74
- - doc/classes/NilClass.src
75
- - doc/classes/ArrayTest.html
76
- - doc/classes/Numeric.html
77
- - doc/classes/ArrayTest.src
78
- - doc/classes/JSON/Lexer.src
79
- - doc/classes/JSON/Lexer.html
80
- - doc/classes/JSON/Lexer.src/M000022.html
81
- - doc/classes/JSON/Lexer.src/M000023.html
82
- - doc/classes/JSON/Lexer.src/M000024.html
83
- - doc/classes/JSON/Lexer.src/M000025.html
84
- - doc/classes/JSON/Lexer.src/M000026.html
85
- - doc/classes/JSON/Lexer.src/M000027.html
86
- - doc/classes/JSON/Lexer.src/M000028.html
87
- - doc/classes/JSON/Lexer.src/M000029.html
88
- - doc/classes/JSON/Lexer.src/M000030.html
89
- - doc/classes/JSON/Lexer.src/M000031.html
90
- - doc/classes/JSON/Lexer.src/M000032.html
91
- - doc/classes/JSON/Lexer.src/M000033.html
92
- - doc/classes/JSON/Lexer.src/M000034.html
93
- - doc/classes/JSON/Lexer.src/M000035.html
94
- - doc/classes/JSON/Lexer.src/M000036.html
95
- - doc/classes/Array.src/M000011.html
96
- - doc/classes/Array.src/M000012.html
97
- - doc/classes/Numeric.src/M000016.html
98
- - doc/classes/Hash.src/M000009.html
99
- - doc/classes/Hash.src/M000010.html
100
- - doc/classes/LexerTest.src/M000008.html
101
- - doc/classes/LexerTest.src/M000002.html
102
- - doc/classes/LexerTest.src/M000003.html
103
- - doc/classes/LexerTest.src/M000004.html
104
- - doc/classes/LexerTest.src/M000005.html
105
- - doc/classes/LexerTest.src/M000006.html
106
- - doc/classes/LexerTest.src/M000007.html
107
- - doc/classes/String.src/M000019.html
108
- - doc/classes/String.src/M000020.html
109
- - doc/classes/Object.src/M000018.html
110
- - doc/classes/FalseClass.src/M000013.html
111
- - doc/classes/ObjectTest.src/M000015.html
112
- - doc/classes/TrueClass.src/M000021.html
113
- - doc/classes/NilClass.src/M000017.html
114
- - doc/classes/ArrayTest.src/M000014.html
115
- - lib/json/objects.rb
116
- - lib/json/lexer.rb
117
- - test/lexertest.rb
118
- - test/objtest.rb
119
- - test/arraytest.rb
31
+ - COPYING
32
+ - README
33
+ - install.rb
34
+ - json
35
+ - test
36
+ - rakefile
37
+ - json/lexer.rb
38
+ - json/objects.rb
39
+ - test/arraytest.rb
40
+ - test/lexertest.rb
41
+ - test/objtest.rb
120
42
  test_files: []
43
+
121
44
  rdoc_options: []
45
+
122
46
  extra_rdoc_files: []
47
+
123
48
  executables: []
49
+
124
50
  extensions: []
51
+
125
52
  requirements: []
126
- dependencies: []
53
+
54
+ dependencies: []
55
+