oj 3.11.5 → 3.16.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1421 -0
  3. data/README.md +19 -5
  4. data/RELEASE_NOTES.md +61 -0
  5. data/ext/oj/buf.h +20 -6
  6. data/ext/oj/cache.c +329 -0
  7. data/ext/oj/cache.h +22 -0
  8. data/ext/oj/cache8.c +10 -9
  9. data/ext/oj/circarray.c +8 -6
  10. data/ext/oj/circarray.h +2 -2
  11. data/ext/oj/code.c +19 -33
  12. data/ext/oj/code.h +2 -2
  13. data/ext/oj/compat.c +27 -77
  14. data/ext/oj/custom.c +86 -179
  15. data/ext/oj/debug.c +126 -0
  16. data/ext/oj/dump.c +256 -249
  17. data/ext/oj/dump.h +26 -12
  18. data/ext/oj/dump_compat.c +565 -642
  19. data/ext/oj/dump_leaf.c +17 -63
  20. data/ext/oj/dump_object.c +65 -187
  21. data/ext/oj/dump_strict.c +27 -51
  22. data/ext/oj/encoder.c +43 -0
  23. data/ext/oj/err.c +2 -13
  24. data/ext/oj/err.h +24 -8
  25. data/ext/oj/extconf.rb +21 -6
  26. data/ext/oj/fast.c +149 -149
  27. data/ext/oj/intern.c +313 -0
  28. data/ext/oj/intern.h +22 -0
  29. data/ext/oj/mem.c +318 -0
  30. data/ext/oj/mem.h +53 -0
  31. data/ext/oj/mimic_json.c +121 -106
  32. data/ext/oj/object.c +85 -162
  33. data/ext/oj/odd.c +89 -67
  34. data/ext/oj/odd.h +15 -15
  35. data/ext/oj/oj.c +542 -411
  36. data/ext/oj/oj.h +99 -73
  37. data/ext/oj/parse.c +175 -187
  38. data/ext/oj/parse.h +26 -24
  39. data/ext/oj/parser.c +1600 -0
  40. data/ext/oj/parser.h +101 -0
  41. data/ext/oj/rails.c +112 -159
  42. data/ext/oj/rails.h +1 -1
  43. data/ext/oj/reader.c +11 -14
  44. data/ext/oj/reader.h +4 -2
  45. data/ext/oj/resolve.c +5 -24
  46. data/ext/oj/rxclass.c +7 -6
  47. data/ext/oj/rxclass.h +1 -1
  48. data/ext/oj/saj.c +22 -33
  49. data/ext/oj/saj2.c +584 -0
  50. data/ext/oj/saj2.h +23 -0
  51. data/ext/oj/scp.c +5 -28
  52. data/ext/oj/sparse.c +28 -72
  53. data/ext/oj/stream_writer.c +50 -40
  54. data/ext/oj/strict.c +56 -61
  55. data/ext/oj/string_writer.c +72 -39
  56. data/ext/oj/trace.h +31 -4
  57. data/ext/oj/usual.c +1218 -0
  58. data/ext/oj/usual.h +69 -0
  59. data/ext/oj/util.h +1 -1
  60. data/ext/oj/val_stack.c +14 -3
  61. data/ext/oj/val_stack.h +8 -7
  62. data/ext/oj/validate.c +46 -0
  63. data/ext/oj/wab.c +63 -88
  64. data/lib/oj/active_support_helper.rb +1 -3
  65. data/lib/oj/bag.rb +7 -1
  66. data/lib/oj/easy_hash.rb +4 -5
  67. data/lib/oj/error.rb +1 -2
  68. data/lib/oj/json.rb +162 -150
  69. data/lib/oj/mimic.rb +9 -7
  70. data/lib/oj/saj.rb +20 -6
  71. data/lib/oj/schandler.rb +5 -4
  72. data/lib/oj/state.rb +12 -8
  73. data/lib/oj/version.rb +1 -2
  74. data/lib/oj.rb +2 -0
  75. data/pages/Compatibility.md +1 -1
  76. data/pages/InstallOptions.md +20 -0
  77. data/pages/JsonGem.md +15 -0
  78. data/pages/Modes.md +8 -3
  79. data/pages/Options.md +43 -5
  80. data/pages/Parser.md +309 -0
  81. data/pages/Rails.md +14 -2
  82. data/test/_test_active.rb +8 -9
  83. data/test/_test_active_mimic.rb +7 -8
  84. data/test/_test_mimic_rails.rb +17 -20
  85. data/test/activerecord/result_test.rb +5 -6
  86. data/test/activesupport6/encoding_test.rb +63 -28
  87. data/test/{activesupport5 → activesupport7}/abstract_unit.rb +16 -12
  88. data/test/{activesupport5 → activesupport7}/decoding_test.rb +2 -10
  89. data/test/{activesupport5 → activesupport7}/encoding_test.rb +86 -50
  90. data/test/{activesupport5 → activesupport7}/encoding_test_cases.rb +6 -0
  91. data/test/{activesupport5 → activesupport7}/time_zone_test_helpers.rb +8 -0
  92. data/test/files.rb +15 -15
  93. data/test/foo.rb +16 -45
  94. data/test/helper.rb +11 -8
  95. data/test/isolated/shared.rb +3 -2
  96. data/test/json_gem/json_addition_test.rb +2 -2
  97. data/test/json_gem/json_common_interface_test.rb +8 -6
  98. data/test/json_gem/json_encoding_test.rb +0 -0
  99. data/test/json_gem/json_ext_parser_test.rb +1 -0
  100. data/test/json_gem/json_fixtures_test.rb +3 -2
  101. data/test/json_gem/json_generator_test.rb +56 -38
  102. data/test/json_gem/json_generic_object_test.rb +11 -11
  103. data/test/json_gem/json_parser_test.rb +54 -47
  104. data/test/json_gem/json_string_matching_test.rb +9 -9
  105. data/test/json_gem/test_helper.rb +7 -3
  106. data/test/mem.rb +34 -0
  107. data/test/perf.rb +22 -27
  108. data/test/perf_compat.rb +31 -33
  109. data/test/perf_dump.rb +50 -0
  110. data/test/perf_fast.rb +80 -82
  111. data/test/perf_file.rb +27 -29
  112. data/test/perf_object.rb +65 -69
  113. data/test/perf_once.rb +59 -0
  114. data/test/perf_parser.rb +183 -0
  115. data/test/perf_saj.rb +46 -54
  116. data/test/perf_scp.rb +58 -69
  117. data/test/perf_simple.rb +41 -39
  118. data/test/perf_strict.rb +74 -82
  119. data/test/perf_wab.rb +67 -69
  120. data/test/prec.rb +5 -5
  121. data/test/sample/change.rb +0 -1
  122. data/test/sample/dir.rb +0 -1
  123. data/test/sample/doc.rb +0 -1
  124. data/test/sample/file.rb +0 -1
  125. data/test/sample/group.rb +0 -1
  126. data/test/sample/hasprops.rb +0 -1
  127. data/test/sample/layer.rb +0 -1
  128. data/test/sample/rect.rb +0 -1
  129. data/test/sample/shape.rb +0 -1
  130. data/test/sample/text.rb +0 -1
  131. data/test/sample.rb +16 -16
  132. data/test/sample_json.rb +8 -8
  133. data/test/test_compat.rb +95 -43
  134. data/test/test_custom.rb +73 -51
  135. data/test/test_debian.rb +7 -10
  136. data/test/test_fast.rb +135 -79
  137. data/test/test_file.rb +41 -30
  138. data/test/test_gc.rb +16 -5
  139. data/test/test_generate.rb +5 -5
  140. data/test/test_hash.rb +5 -5
  141. data/test/test_integer_range.rb +9 -9
  142. data/test/test_null.rb +20 -20
  143. data/test/test_object.rb +99 -96
  144. data/test/test_parser.rb +11 -0
  145. data/test/test_parser_debug.rb +27 -0
  146. data/test/test_parser_saj.rb +337 -0
  147. data/test/test_parser_usual.rb +251 -0
  148. data/test/test_rails.rb +2 -2
  149. data/test/test_saj.rb +10 -8
  150. data/test/test_scp.rb +37 -39
  151. data/test/test_strict.rb +40 -32
  152. data/test/test_various.rb +165 -84
  153. data/test/test_wab.rb +48 -44
  154. data/test/test_writer.rb +47 -47
  155. data/test/tests.rb +13 -5
  156. data/test/tests_mimic.rb +12 -3
  157. data/test/tests_mimic_addition.rb +12 -3
  158. metadata +74 -128
  159. data/ext/oj/hash.c +0 -131
  160. data/ext/oj/hash.h +0 -19
  161. data/ext/oj/hash_test.c +0 -491
  162. data/test/activesupport4/decoding_test.rb +0 -108
  163. data/test/activesupport4/encoding_test.rb +0 -531
  164. data/test/activesupport4/test_helper.rb +0 -41
  165. data/test/activesupport5/test_helper.rb +0 -72
  166. data/test/bar.rb +0 -35
  167. data/test/baz.rb +0 -16
  168. data/test/zoo.rb +0 -13
data/ext/oj/hash_test.c DELETED
@@ -1,491 +0,0 @@
1
- // Copyright (c) 2011 Peter Ohler. All rights reserved.
2
- // Licensed under the MIT License. See LICENSE file in the project root for license details.
3
-
4
- // if windows, comment out the whole file. It's only a performance test.
5
- #ifndef _WIN32
6
- #include "hash.h"
7
-
8
- #include <stdint.h>
9
- #include <sys/time.h>
10
- #include <time.h>
11
-
12
- /* Define printf formats for standard types, like PRIu64 for uint64_t. */
13
- #define __STDC_FORMAT_MACROS
14
- #include <inttypes.h>
15
-
16
- typedef struct _strLen {
17
- const char *str;
18
- size_t len;
19
- } * StrLen;
20
-
21
- static struct _strLen data[] = {{"Gem::Version", 12},
22
- {"TracePoint", 10},
23
- {"Complex::compatible", 19},
24
- {"Complex", 7},
25
- {"Rational::compatible", 20},
26
- {"Rational", 8},
27
- {"FiberError", 10},
28
- {"Fiber", 5},
29
- {"ThreadError", 11},
30
- {"Mutex", 5},
31
- {"ThreadGroup", 11},
32
- {"RubyVM::InstructionSequence", 27},
33
- {"Thread::Backtrace::Location", 27},
34
- {"Thread::Backtrace", 17},
35
- {"Thread", 6},
36
- {"RubyVM::Env", 11},
37
- {"RubyVM", 6},
38
- {"Enumerator::Yielder", 19},
39
- {"Enumerator::Generator", 21},
40
- {"StopIteration", 13},
41
- {"Enumerator::Lazy", 16},
42
- {"Enumerator", 10},
43
- {"ObjectSpace::WeakMap", 20},
44
- {"Math::DomainError", 17},
45
- {"Binding", 7},
46
- {"UnboundMethod", 13},
47
- {"Method", 6},
48
- {"SystemStackError", 16},
49
- {"LocalJumpError", 14},
50
- {"Proc", 4},
51
- {"Struct::Tms", 11},
52
- {"Process::Status", 15},
53
- {"Random", 6},
54
- {"Time", 4},
55
- {"Dir", 3},
56
- {"File::Stat", 10},
57
- {"File", 4},
58
- {"ARGF.class", 10},
59
- {"IO", 2},
60
- {"EOFError", 8},
61
- {"IOError", 7},
62
- {"Range", 5},
63
- {"Encoding::Converter", 19},
64
- {"Encoding::ConverterNotFoundError", 32},
65
- {"Encoding::InvalidByteSequenceError", 34},
66
- {"Encoding::UndefinedConversionError", 34},
67
- {"MatchData", 9},
68
- {"Regexp", 6},
69
- {"RegexpError", 11},
70
- {"Struct", 6},
71
- {"Hash", 4},
72
- {"Array", 5},
73
- {"Errno::ERPCMISMATCH", 19},
74
- {"Errno::EPROGUNAVAIL", 19},
75
- {"Errno::EPROGMISMATCH", 20},
76
- {"Errno::EPROCUNAVAIL", 19},
77
- {"Errno::EPROCLIM", 15},
78
- {"Errno::ENOTSUP", 14},
79
- {"Errno::ENOATTR", 14},
80
- {"Errno::ENEEDAUTH", 16},
81
- {"Errno::EFTYPE", 13},
82
- {"Errno::EBADRPC", 14},
83
- {"Errno::EAUTH", 12},
84
- {"Errno::EOWNERDEAD", 17},
85
- {"Errno::ENOTRECOVERABLE", 22},
86
- {"Errno::ECANCELED", 16},
87
- {"Errno::EDQUOT", 13},
88
- {"Errno::ESTALE", 13},
89
- {"Errno::EINPROGRESS", 18},
90
- {"Errno::EALREADY", 15},
91
- {"Errno::EHOSTUNREACH", 19},
92
- {"Errno::EHOSTDOWN", 16},
93
- {"Errno::ECONNREFUSED", 19},
94
- {"Errno::ETIMEDOUT", 16},
95
- {"Errno::ETOOMANYREFS", 19},
96
- {"Errno::ESHUTDOWN", 16},
97
- {"Errno::ENOTCONN", 15},
98
- {"Errno::EISCONN", 14},
99
- {"Errno::ENOBUFS", 14},
100
- {"Errno::ECONNRESET", 17},
101
- {"Errno::ECONNABORTED", 19},
102
- {"Errno::ENETRESET", 16},
103
- {"Errno::ENETUNREACH", 18},
104
- {"Errno::ENETDOWN", 15},
105
- {"Errno::EADDRNOTAVAIL", 20},
106
- {"Errno::EADDRINUSE", 17},
107
- {"Errno::EAFNOSUPPORT", 19},
108
- {"Errno::EPFNOSUPPORT", 19},
109
- {"Errno::EOPNOTSUPP", 17},
110
- {"Errno::ESOCKTNOSUPPORT", 22},
111
- {"Errno::EPROTONOSUPPORT", 22},
112
- {"Errno::ENOPROTOOPT", 18},
113
- {"Errno::EPROTOTYPE", 17},
114
- {"Errno::EMSGSIZE", 15},
115
- {"Errno::EDESTADDRREQ", 19},
116
- {"Errno::ENOTSOCK", 15},
117
- {"Errno::EUSERS", 13},
118
- {"Errno::EILSEQ", 13},
119
- {"Errno::EOVERFLOW", 16},
120
- {"Errno::EBADMSG", 14},
121
- {"Errno::EMULTIHOP", 16},
122
- {"Errno::EPROTO", 13},
123
- {"Errno::ENOLINK", 14},
124
- {"Errno::EREMOTE", 14},
125
- {"Errno::ENOSR", 12},
126
- {"Errno::ETIME", 12},
127
- {"Errno::ENODATA", 14},
128
- {"Errno::ENOSTR", 13},
129
- {"Errno::EIDRM", 12},
130
- {"Errno::ENOMSG", 13},
131
- {"Errno::ELOOP", 12},
132
- {"Errno::ENOTEMPTY", 16},
133
- {"Errno::ENOSYS", 13},
134
- {"Errno::ENOLCK", 13},
135
- {"Errno::ENAMETOOLONG", 19},
136
- {"Errno::EDEADLK", 14},
137
- {"Errno::ERANGE", 13},
138
- {"Errno::EDOM", 11},
139
- {"Errno::EPIPE", 12},
140
- {"Errno::EMLINK", 13},
141
- {"Errno::EROFS", 12},
142
- {"Errno::ESPIPE", 13},
143
- {"Errno::ENOSPC", 13},
144
- {"Errno::EFBIG", 12},
145
- {"Errno::ETXTBSY", 14},
146
- {"Errno::ENOTTY", 13},
147
- {"Errno::EMFILE", 13},
148
- {"Errno::ENFILE", 13},
149
- {"Errno::EINVAL", 13},
150
- {"Errno::EISDIR", 13},
151
- {"Errno::ENOTDIR", 14},
152
- {"Errno::ENODEV", 13},
153
- {"Errno::EXDEV", 12},
154
- {"Errno::EEXIST", 13},
155
- {"Errno::EBUSY", 12},
156
- {"Errno::ENOTBLK", 14},
157
- {"Errno::EFAULT", 13},
158
- {"Errno::EACCES", 13},
159
- {"Errno::ENOMEM", 13},
160
- {"Errno::EAGAIN", 13},
161
- {"Errno::ECHILD", 13},
162
- {"Errno::EBADF", 12},
163
- {"Errno::ENOEXEC", 14},
164
- {"Errno::E2BIG", 12},
165
- {"Errno::ENXIO", 12},
166
- {"Errno::EIO", 10},
167
- {"Errno::EINTR", 12},
168
- {"Errno::ESRCH", 12},
169
- {"Errno::ENOENT", 13},
170
- {"Errno::EPERM", 12},
171
- {"Errno::NOERROR", 14},
172
- {"Bignum", 6},
173
- {"Float", 5},
174
- {"Fixnum", 6},
175
- {"Integer", 7},
176
- {"Numeric", 7},
177
- {"FloatDomainError", 16},
178
- {"ZeroDivisionError", 17},
179
- {"SystemCallError", 15},
180
- {"Encoding::CompatibilityError", 28},
181
- {"EncodingError", 13},
182
- {"NoMemoryError", 13},
183
- {"SecurityError", 13},
184
- {"RuntimeError", 12},
185
- {"NoMethodError", 13},
186
- {"NameError::message", 18},
187
- {"NameError", 9},
188
- {"NotImplementedError", 19},
189
- {"LoadError", 9},
190
- {"SyntaxError", 11},
191
- {"ScriptError", 11},
192
- {"RangeError", 10},
193
- {"KeyError", 8},
194
- {"IndexError", 10},
195
- {"ArgumentError", 13},
196
- {"TypeError", 9},
197
- {"StandardError", 13},
198
- {"Interrupt", 9},
199
- {"SignalException", 15},
200
- {"SystemExit", 10},
201
- {"Exception", 9},
202
- {"Symbol", 6},
203
- {"String", 6},
204
- {"Encoding", 8},
205
- {"FalseClass", 10},
206
- {"TrueClass", 9},
207
- {"Data", 4},
208
- {"NilClass", 8},
209
- {"Class", 5},
210
- {"Module", 6},
211
- {"Object", 6},
212
- {"BasicObject", 11},
213
- {"Gem::Requirement::BadRequirementError", 37},
214
- {"Gem::Requirement", 16},
215
- {"Gem::SourceFetchProblem", 23},
216
- {"Gem::PlatformMismatch", 21},
217
- {"Gem::ErrorReason", 16},
218
- {"Gem::LoadError", 14},
219
- {"Gem::RemoteSourceException", 26},
220
- {"Gem::RemoteInstallationSkipped", 30},
221
- {"Gem::RemoteInstallationCancelled", 32},
222
- {"Gem::RemoteError", 16},
223
- {"Gem::OperationNotSupportedError", 31},
224
- {"Gem::InvalidSpecificationException", 34},
225
- {"Gem::InstallError", 17},
226
- {"Gem::Specification", 18},
227
- {"Date", 4},
228
- {"Gem::Platform", 13},
229
- {"Gem::SpecificGemNotFoundException", 33},
230
- {"Gem::GemNotFoundException", 25},
231
- {"Gem::FormatException", 20},
232
- {"Gem::FilePermissionError", 24},
233
- {"Gem::EndOfYAMLException", 23},
234
- {"Gem::DocumentError", 18},
235
- {"Gem::GemNotInHomeException", 26},
236
- {"Gem::DependencyRemovalException", 31},
237
- {"Gem::DependencyError", 20},
238
- {"Gem::CommandLineError", 21},
239
- {"Gem::Exception", 14},
240
- {"IRB::SLex", 9},
241
- {"IRB::Notifier::NoMsgNotifier", 28},
242
- {"IRB::Notifier::LeveledNotifier", 30},
243
- {"IRB::Notifier::CompositeNotifier", 32},
244
- {"IRB::Notifier::AbstractNotifier", 31},
245
- {"IRB::Notifier::ErrUnrecognizedLevel", 35},
246
- {"IRB::Notifier::ErrUndefinedNotifier", 35},
247
- {"IRB::StdioOutputMethod", 22},
248
- {"IRB::OutputMethod::NotImplementedError", 38},
249
- {"IRB::OutputMethod", 17},
250
- {"IRB::IllegalRCGenerator", 23},
251
- {"IRB::UndefinedPromptMode", 24},
252
- {"IRB::CantChangeBinding", 22},
253
- {"IRB::CantShiftToMultiIrbMode", 28},
254
- {"IRB::NoSuchJob", 14},
255
- {"IRB::IrbSwitchedToCurrentThread", 31},
256
- {"IRB::IrbAlreadyDead", 19},
257
- {"IRB::IllegalParameter", 21},
258
- {"IRB::CantReturnToNormalMode", 27},
259
- {"IRB::NotImplementedError", 24},
260
- {"IRB::UnrecognizedSwitch", 23},
261
- {"IRB::Irb", 8},
262
- {"IRB::Abort", 10},
263
- {"IRB::Locale", 11},
264
- {"IRB::SLex::ErrNodeNothing", 25},
265
- {"IRB::SLex::ErrNodeAlreadyExists", 31},
266
- {"RubyLex", 7},
267
- {"IRB::SLex::Node", 15},
268
- {"Gem::SystemExitException", 24},
269
- {"Gem::VerificationError", 22},
270
- {"RubyToken::TkError", 18},
271
- {"RubyToken::TkUnknownChar", 24},
272
- {"RubyToken::TkOPASGN", 19},
273
- {"RubyToken::TkOp", 15},
274
- {"RubyToken::TkVal", 16},
275
- {"RubyToken::TkId", 15},
276
- {"RubyToken::TkNode", 17},
277
- {"RubyToken::Token", 16},
278
- {"RubyToken::TkUNDEF", 18},
279
- {"RubyToken::TkDEF", 16},
280
- {"RubyToken::TkMODULE", 19},
281
- {"RubyToken::TkCLASS", 18},
282
- {"RubyToken::TkWHILE", 18},
283
- {"RubyToken::TkWHEN", 17},
284
- {"RubyToken::TkCASE", 17},
285
- {"RubyToken::TkELSE", 17},
286
- {"RubyToken::TkELSIF", 18},
287
- {"RubyToken::TkTHEN", 17},
288
- {"RubyToken::TkUNLESS", 19},
289
- {"RubyToken::TkIF", 15},
290
- {"RubyToken::TkEND", 16},
291
- {"RubyToken::TkENSURE", 19},
292
- {"RubyToken::TkRESCUE", 19},
293
- {"RubyToken::TkBEGIN", 18},
294
- {"RubyToken::TkDO", 15},
295
- {"RubyToken::TkIN", 15},
296
- {"RubyToken::TkRETRY", 18},
297
- {"RubyToken::TkREDO", 17},
298
- {"RubyToken::TkNEXT", 17},
299
- {"RubyToken::TkBREAK", 18},
300
- {"RubyToken::TkFOR", 16},
301
- {"RubyToken::TkUNTIL", 18},
302
- {"RubyToken::TkTRUE", 17},
303
- {"RubyToken::TkNIL", 16},
304
- {"RubyToken::TkSELF", 17},
305
- {"RubyToken::TkSUPER", 18},
306
- {"RubyToken::TkYIELD", 18},
307
- {"RubyToken::TkRETURN", 19},
308
- {"RubyToken::TkAND", 16},
309
- {"RubyToken::TkFALSE", 18},
310
- {"RubyToken::TkUNLESS_MOD", 23},
311
- {"RubyToken::TkIF_MOD", 19},
312
- {"RubyToken::TkNOT", 16},
313
- {"RubyToken::TkOR", 15},
314
- {"RubyToken::TkALIAS", 18},
315
- {"RubyToken::TkUNTIL_MOD", 22},
316
- {"RubyToken::TkWHILE_MOD", 22},
317
- {"RubyToken::TkGVAR", 17},
318
- {"RubyToken::TkFID", 16},
319
- {"RubyToken::TkIDENTIFIER", 23},
320
- {"RubyToken::Tk__FILE__", 21},
321
- {"RubyToken::Tk__LINE__", 21},
322
- {"RubyToken::TklEND", 17},
323
- {"RubyToken::TklBEGIN", 19},
324
- {"RubyToken::TkDEFINED", 20},
325
- {"RubyToken::TkDREGEXP", 20},
326
- {"RubyToken::TkDXSTRING", 21},
327
- {"RubyToken::TkDSTRING", 20},
328
- {"RubyToken::TkSYMBOL", 19},
329
- {"RubyToken::TkREGEXP", 19},
330
- {"RubyToken::TkXSTRING", 20},
331
- {"RubyToken::TkSTRING", 19},
332
- {"RubyToken::TkFLOAT", 18},
333
- {"RubyToken::TkINTEGER", 20},
334
- {"RubyToken::TkCONSTANT", 21},
335
- {"RubyToken::TkIVAR", 17},
336
- {"RubyToken::TkCVAR", 17},
337
- {"RubyToken::TkNEQ", 16},
338
- {"RubyToken::TkEQQ", 16},
339
- {"RubyToken::TkEQ", 15},
340
- {"RubyToken::TkCMP", 16},
341
- {"RubyToken::TkPOW", 16},
342
- {"RubyToken::TkUMINUS", 19},
343
- {"RubyToken::TkUPLUS", 18},
344
- {"Exception2MessageMapper::ErrNotRegisteredException", 50},
345
- {"RubyToken::TkBACK_REF", 21},
346
- {"RubyToken::TkNTH_REF", 20},
347
- {"RubyToken::TkLSHFT", 18},
348
- {"RubyToken::TkASET", 17},
349
- {"RubyToken::TkAREF", 17},
350
- {"RubyToken::TkDOT3", 17},
351
- {"RubyToken::TkDOT2", 17},
352
- {"RubyToken::TkNMATCH", 19},
353
- {"RubyToken::TkMATCH", 18},
354
- {"RubyToken::TkOROP", 17},
355
- {"RubyToken::TkANDOP", 18},
356
- {"RubyToken::TkLEQ", 16},
357
- {"RubyToken::TkGEQ", 16},
358
- {"RubyToken::TkAMPER", 18},
359
- {"RubyToken::TkSTAR", 17},
360
- {"RubyToken::TkfLBRACE", 20},
361
- {"RubyToken::TkfLBRACK", 20},
362
- {"RubyToken::TkfLPAREN", 20},
363
- {"RubyToken::TkCOLON", 18},
364
- {"RubyToken::TkQUESTION", 21},
365
- {"RubyToken::TkASSOC", 18},
366
- {"RubyToken::TkCOLON3", 19},
367
- {"RubyToken::TkCOLON2", 19},
368
- {"RubyToken::TkRSHFT", 18},
369
- {"RubyToken::TkBITAND", 19},
370
- {"RubyToken::TkBITXOR", 19},
371
- {"RubyToken::TkBITOR", 18},
372
- {"RubyToken::TkMOD", 16},
373
- {"RubyToken::TkDIV", 16},
374
- {"RubyToken::TkMULT", 17},
375
- {"RubyToken::TkMINUS", 18},
376
- {"RubyToken::TkPLUS", 17},
377
- {"RubyToken::TkLT", 15},
378
- {"RubyToken::TkGT", 15},
379
- {"RubyToken::TkSYMBEG", 19},
380
- {"IRB::DefaultEncodings", 21},
381
- {"RubyToken::TkRPAREN", 19},
382
- {"RubyToken::TkLBRACE", 19},
383
- {"RubyToken::TkLBRACK", 19},
384
- {"RubyToken::TkLPAREN", 19},
385
- {"RubyToken::TkDOT", 16},
386
- {"RubyToken::TkASSIGN", 19},
387
- {"RubyToken::TkBACKQUOTE", 22},
388
- {"RubyToken::TkNOTOP", 18},
389
- {"RubyToken::TkBITNOT", 19},
390
- {"RubyToken::TkDOLLAR", 19},
391
- {"RubyToken::TkAT", 15},
392
- {"RubyToken::TkBACKSLASH", 22},
393
- {"RubyToken::TkEND_OF_SCRIPT", 26},
394
- {"RubyToken::TkNL", 15},
395
- {"RubyToken::TkSPACE", 18},
396
- {"RubyToken::TkRD_COMMENT", 23},
397
- {"RubyToken::TkCOMMENT", 20},
398
- {"RubyToken::TkSEMICOLON", 22},
399
- {"RubyToken::TkCOMMA", 18},
400
- {"RubyToken::TkRBRACE", 19},
401
- {"RubyToken::TkRBRACK", 19},
402
- {"RubyLex::TerminateLineInput", 27},
403
- {"RubyLex::SyntaxError", 20},
404
- {"RubyLex::TkReading2TokenDuplicateError", 38},
405
- {"RubyLex::TkSymbol2TokenNoKey", 28},
406
- {"RubyLex::TkReading2TokenNoKey", 29},
407
- {"RubyLex::AlreadyDefinedToken", 28},
408
- {"IRB::FileInputMethod", 20},
409
- {"IRB::StdioInputMethod", 21},
410
- {"IRB::InputMethod", 16},
411
- {"IRB::ReadlineInputMethod", 24},
412
- {"IRB::Context", 12},
413
- {"IRB::Inspector", 14},
414
- {"IRB::WorkSpace", 14},
415
- {0, 0}};
416
-
417
- static uint64_t micro_time() {
418
- struct timeval tv;
419
-
420
- gettimeofday(&tv, NULL);
421
-
422
- return (uint64_t)tv.tv_sec * 1000000ULL + (uint64_t)tv.tv_usec;
423
- }
424
-
425
- static void perf() {
426
- StrLen d;
427
- VALUE v;
428
- VALUE * slot = 0;
429
- uint64_t dt, start;
430
- int i, iter = 1000000;
431
- int dataCnt = sizeof(data) / sizeof(*data);
432
-
433
- oj_hash_init();
434
- start = micro_time();
435
- for (i = iter; 0 < i; i--) {
436
- for (d = data; 0 != d->str; d++) {
437
- v = oj_class_hash_get(d->str, d->len, &slot);
438
- if (Qundef == v) {
439
- if (0 != slot) {
440
- v = ID2SYM(rb_intern(d->str));
441
- *slot = v;
442
- }
443
- }
444
- }
445
- }
446
- dt = micro_time() - start;
447
- #if IS_WINDOWS
448
- printf("%d iterations took %ld msecs, %ld gets/msec\n",
449
- iter,
450
- (long)(dt / 1000),
451
- (long)(iter * dataCnt / (dt / 1000)));
452
- #else
453
- printf("%d iterations took %" PRIu64 " msecs, %ld gets/msec\n",
454
- iter,
455
- dt / 1000,
456
- (long)(iter * dataCnt / (dt / 1000)));
457
- #endif
458
- }
459
-
460
- void oj_hash_test() {
461
- StrLen d;
462
- VALUE v;
463
- VALUE *slot = 0;
464
- ;
465
-
466
- oj_hash_init();
467
- for (d = data; 0 != d->str; d++) {
468
- char *s = oj_strndup(d->str, d->len);
469
- v = oj_class_hash_get(d->str, d->len, &slot);
470
- if (Qnil == v) {
471
- if (0 == slot) {
472
- printf("*** failed to get a slot for %s\n", s);
473
- } else {
474
- v = ID2SYM(rb_intern(d->str));
475
- *slot = v;
476
- }
477
- } else {
478
- VALUE rs = rb_funcall2(v, rb_intern("to_s"), 0, 0);
479
-
480
- printf("*** get on '%s' returned '%s' (%s)\n",
481
- s,
482
- StringValuePtr(rs),
483
- rb_class2name(rb_obj_class(v)));
484
- }
485
- /*oj_hash_print(c);*/
486
- }
487
- printf("*** ---------- hash table ------------\n");
488
- oj_hash_print();
489
- perf();
490
- }
491
- #endif
@@ -1,108 +0,0 @@
1
- # encoding: utf-8
2
- require 'activesupport4/test_helper'
3
- require 'active_support/json'
4
- require 'active_support/time'
5
-
6
- class TestJSONDecoding < ActiveSupport::TestCase
7
- class Foo
8
- def self.json_create(object)
9
- "Foo"
10
- end
11
- end
12
-
13
- TESTS = {
14
- %q({"returnTo":{"\/categories":"\/"}}) => {"returnTo" => {"/categories" => "/"}},
15
- %q({"return\\"To\\":":{"\/categories":"\/"}}) => {"return\"To\":" => {"/categories" => "/"}},
16
- %q({"returnTo":{"\/categories":1}}) => {"returnTo" => {"/categories" => 1}},
17
- %({"returnTo":[1,"a"]}) => {"returnTo" => [1, "a"]},
18
- %({"returnTo":[1,"\\"a\\",", "b"]}) => {"returnTo" => [1, "\"a\",", "b"]},
19
- %({"a": "'", "b": "5,000"}) => {"a" => "'", "b" => "5,000"},
20
- %({"a": "a's, b's and c's", "b": "5,000"}) => {"a" => "a's, b's and c's", "b" => "5,000"},
21
- # multibyte
22
- %({"matzue": "松江", "asakusa": "浅草"}) => {"matzue" => "松江", "asakusa" => "浅草"},
23
- %({"a": "2007-01-01"}) => {'a' => Date.new(2007, 1, 1)},
24
- %({"a": "2007-01-01 01:12:34 Z"}) => {'a' => Time.utc(2007, 1, 1, 1, 12, 34)},
25
- %(["2007-01-01 01:12:34 Z"]) => [Time.utc(2007, 1, 1, 1, 12, 34)],
26
- %(["2007-01-01 01:12:34 Z", "2007-01-01 01:12:35 Z"]) => [Time.utc(2007, 1, 1, 1, 12, 34), Time.utc(2007, 1, 1, 1, 12, 35)],
27
- # no time zone
28
- %({"a": "2007-01-01 01:12:34"}) => {'a' => "2007-01-01 01:12:34"},
29
- # invalid date
30
- %({"a": "1089-10-40"}) => {'a' => "1089-10-40"},
31
- # xmlschema date notation
32
- %({"a": "2009-08-10T19:01:02Z"}) => {'a' => Time.utc(2009, 8, 10, 19, 1, 2)},
33
- %({"a": "2009-08-10T19:01:02+02:00"}) => {'a' => Time.utc(2009, 8, 10, 17, 1, 2)},
34
- %({"a": "2009-08-10T19:01:02-05:00"}) => {'a' => Time.utc(2009, 8, 11, 00, 1, 2)},
35
- # needs to be *exact*
36
- %({"a": " 2007-01-01 01:12:34 Z "}) => {'a' => " 2007-01-01 01:12:34 Z "},
37
- %({"a": "2007-01-01 : it's your birthday"}) => {'a' => "2007-01-01 : it's your birthday"},
38
- %([]) => [],
39
- %({}) => {},
40
- %({"a":1}) => {"a" => 1},
41
- %({"a": ""}) => {"a" => ""},
42
- %({"a":"\\""}) => {"a" => "\""},
43
- %({"a": null}) => {"a" => nil},
44
- %({"a": true}) => {"a" => true},
45
- %({"a": false}) => {"a" => false},
46
- %q({"bad":"\\\\","trailing":""}) => {"bad" => "\\", "trailing" => ""},
47
- %q({"a": "http:\/\/test.host\/posts\/1"}) => {"a" => "http://test.host/posts/1"},
48
- %q({"a": "\u003cunicode\u0020escape\u003e"}) => {"a" => "<unicode escape>"},
49
- %q({"a": "\\\\u0020skip double backslashes"}) => {"a" => "\\u0020skip double backslashes"},
50
- %q({"a": "\u003cbr /\u003e"}) => {'a' => "<br />"},
51
- %q({"b":["\u003ci\u003e","\u003cb\u003e","\u003cu\u003e"]}) => {'b' => ["<i>","<b>","<u>"]},
52
- # test combination of dates and escaped or unicode encoded data in arrays
53
- %q([{"d":"1970-01-01", "s":"\u0020escape"},{"d":"1970-01-01", "s":"\u0020escape"}]) =>
54
- [{'d' => Date.new(1970, 1, 1), 's' => ' escape'},{'d' => Date.new(1970, 1, 1), 's' => ' escape'}],
55
- %q([{"d":"1970-01-01","s":"http:\/\/example.com"},{"d":"1970-01-01","s":"http:\/\/example.com"}]) =>
56
- [{'d' => Date.new(1970, 1, 1), 's' => 'http://example.com'},
57
- {'d' => Date.new(1970, 1, 1), 's' => 'http://example.com'}],
58
- # tests escaping of "\n" char with Yaml backend
59
- %q({"a":"\n"}) => {"a"=>"\n"},
60
- %q({"a":"\u000a"}) => {"a"=>"\n"},
61
- %q({"a":"Line1\u000aLine2"}) => {"a"=>"Line1\nLine2"},
62
- # prevent json unmarshalling
63
- %q({"json_class":"TestJSONDecoding::Foo"}) => {"json_class"=>"TestJSONDecoding::Foo"},
64
- # json "fragments" - these are invalid JSON, but ActionPack relies on this
65
- %q("a string") => "a string",
66
- %q(1.1) => 1.1,
67
- %q(1) => 1,
68
- %q(-1) => -1,
69
- %q(true) => true,
70
- %q(false) => false,
71
- %q(null) => nil
72
- }
73
-
74
- TESTS.each_with_index do |(json, expected), index|
75
- test "json decodes #{index}" do
76
- prev = ActiveSupport.parse_json_times
77
- ActiveSupport.parse_json_times = true
78
- silence_warnings do
79
- if expected.nil?
80
- assert_nil ActiveSupport::JSON.decode(json), "JSON decoding failed for #{json}"
81
- else
82
- assert_equal expected, ActiveSupport::JSON.decode(json), "JSON decoding failed for #{json}"
83
- end
84
- end
85
- ActiveSupport.parse_json_times = prev
86
- end
87
- end
88
-
89
- test "json decodes time json with time parsing disabled" do
90
- prev = ActiveSupport.parse_json_times
91
- ActiveSupport.parse_json_times = false
92
- expected = {"a" => "2007-01-01 01:12:34 Z"}
93
- assert_equal expected, ActiveSupport::JSON.decode(%({"a": "2007-01-01 01:12:34 Z"}))
94
- ActiveSupport.parse_json_times = prev
95
- end
96
-
97
- def test_failed_json_decoding
98
- assert_raise(ActiveSupport::JSON.parse_error) { ActiveSupport::JSON.decode(%(undefined)) }
99
- assert_raise(ActiveSupport::JSON.parse_error) { ActiveSupport::JSON.decode(%({a: 1})) }
100
- assert_raise(ActiveSupport::JSON.parse_error) { ActiveSupport::JSON.decode(%({: 1})) }
101
- assert_raise(ActiveSupport::JSON.parse_error) { ActiveSupport::JSON.decode(%()) }
102
- end
103
-
104
- def test_cannot_pass_unsupported_options
105
- assert_raise(ArgumentError) { ActiveSupport::JSON.decode("", create_additions: true) }
106
- end
107
- end
108
-