oj 3.11.0 → 3.16.5

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