wankel 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/README.md +202 -7
- data/ext/wankel/extconf.rb +0 -2
- data/ext/wankel/wankel_parser.c +11 -12
- data/ext/wankel/yajl_helpers.c +9 -9
- data/lib/wankel.rb +1 -1
- data/logo.png +0 -0
- data/test/encoding/encoding_test.rb +19 -1
- data/test/encoding/sax_encoder_test.rb +2 -2
- data/test/parsing/active_support_test.rb +5 -9
- data/test/parsing/fixtures_test.rb +5 -9
- data/test/parsing/multiple_values_test.rb +2 -2
- data/test/parsing/one_off_test.rb +20 -7
- data/test/parsing/sax_parser_test.rb +1 -1
- data/test/performance.rb +1 -1
- data/test/test_helper.rb +5 -3
- data/test/wankel_test.rb +1 -1
- data/wankel.gemspec +13 -14
- metadata +28 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6c72e99e43dc80c261cb7de98acfe8a2722eaeb
|
4
|
+
data.tar.gz: 9c1ca0c3bed80cd83815309d8bd8f98743c67a4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 955623a08d6970492669a8fe10d15e1417bf1d42e097742ce2807b9110dc51bd185e86ad9b46dba49bb5d19008cb96b90567fa396d93c11645356f289b7caea0
|
7
|
+
data.tar.gz: 6e66f495681a0501fc9fd56efaf117687c7ce8c3e3940e184f7db184b89f72e6b1153cfd12bd3c79ad76df1dcbd374689993f68ee50780cb4f6ea43675a2006d
|
data/README.md
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
<a href="
|
1
|
+
<a href="http://wanklerb.com"></a>
|
2
2
|
|
3
|
-
Wankel is a Ruby gem that provides C bindings to the
|
4
|
-
C Library.
|
3
|
+
**Wankel** is a Ruby gem that provides C bindings to the
|
4
|
+
[YAJL 2](http://lloyd.github.io/yajl/) C Library.
|
5
5
|
|
6
|
-
Wankel provides
|
7
|
-
|
6
|
+
Wankel provides gerneral parsing and encoding to and from
|
7
|
+
[JSON](http://json.org/), but also a SAX style parser and encoder for streaming
|
8
|
+
parsing and generation.
|
8
9
|
|
9
10
|
Features
|
10
11
|
--------
|
@@ -20,7 +21,7 @@ Features
|
|
20
21
|
Dependencies
|
21
22
|
------------
|
22
23
|
|
23
|
-
Wankel only dependency is (
|
24
|
+
Wankel only dependency is [YAJL](http://lloyd.github.io/yajl/) version 2.
|
24
25
|
|
25
26
|
You can install it with homebrew via:
|
26
27
|
|
@@ -40,4 +41,198 @@ gem install wankel
|
|
40
41
|
Examples
|
41
42
|
--------
|
42
43
|
|
43
|
-
|
44
|
+
#### Simple Usage
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
Wankel.parse('{"key": "value"}')
|
48
|
+
# => {"key" => "value"}
|
49
|
+
|
50
|
+
Wankel.encode({"key" => "value"})
|
51
|
+
# => '{"key":"value"}'
|
52
|
+
```
|
53
|
+
|
54
|
+
#### Sax Parser Example
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
class SimpleParser < Wankel::SaxParser
|
58
|
+
def on_array_start
|
59
|
+
puts "Array start"
|
60
|
+
end
|
61
|
+
def on_string(string)
|
62
|
+
puts string
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
parser = SimpleParser.new
|
67
|
+
parser.parse('["string1", null, "string2"]')
|
68
|
+
# => "Array start"
|
69
|
+
# => "string1"
|
70
|
+
# => "string2"
|
71
|
+
```
|
72
|
+
|
73
|
+
#### Sax Encoder Example
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
output = StringIO.new
|
77
|
+
encoder = Wankel::SaxEncoder.new(output)
|
78
|
+
encoder.map_open
|
79
|
+
encoder.string("key")
|
80
|
+
encoder.number(123)
|
81
|
+
encoder.map_close
|
82
|
+
encoder.complete
|
83
|
+
output.rewind
|
84
|
+
output.read
|
85
|
+
# => '{"key":123}'
|
86
|
+
```
|
87
|
+
|
88
|
+
Parsing Options
|
89
|
+
---------------
|
90
|
+
|
91
|
+
* `:symbolize_keys` (Default: `false`)
|
92
|
+
|
93
|
+
make Hash keys into Ruby symbols
|
94
|
+
|
95
|
+
``` ruby
|
96
|
+
Wankel.parse('{"key": "value"}', :symbolize_keys => true)
|
97
|
+
# => {:key => "value"}
|
98
|
+
```
|
99
|
+
|
100
|
+
* `:allow_comments` (Default: `false`)
|
101
|
+
|
102
|
+
Ignore javascript style comments in JSON input.
|
103
|
+
|
104
|
+
``` ruby
|
105
|
+
Wankel.parse('{"key": /*comment*/ "value"}', :allow_comments => false)
|
106
|
+
# => Wankel::ParseError
|
107
|
+
|
108
|
+
Wankel.parse('{"key": /*comment*/ "value"}', :allow_comments => true)
|
109
|
+
# => {"key" => "value"}
|
110
|
+
```
|
111
|
+
|
112
|
+
* `:validate_utf8` (Default: `false`)
|
113
|
+
|
114
|
+
Verify that all strings in JSON input are valid UTF8 emit a parse error if
|
115
|
+
this is not so. This option makes parsing slightly more expensive.
|
116
|
+
|
117
|
+
``` ruby
|
118
|
+
Wankel.parse("[\"\x81\x83\"]", :validate_utf8 => false)
|
119
|
+
# => ["\x81\x83"]
|
120
|
+
|
121
|
+
Wankel.parse("[\"\x81\x83\"]", :validate_utf8 => true)
|
122
|
+
# => Wankel::ParseError
|
123
|
+
```
|
124
|
+
|
125
|
+
* `:allow_trailing_garbage` (Default: `false`)
|
126
|
+
|
127
|
+
Ensure the entire input text was consumed and raise an error otherwise
|
128
|
+
|
129
|
+
``` ruby
|
130
|
+
Wankel.parse('{"key": "value"}gar', :allow_trailing_garbage => false)
|
131
|
+
# => Wankel::ParseError
|
132
|
+
|
133
|
+
Wankel.parse('{"key": "value"}gar', :allow_trailing_garbage => true)
|
134
|
+
# => {"key" => "value"}
|
135
|
+
```
|
136
|
+
|
137
|
+
* `:multiple_values` (Default: `false`)
|
138
|
+
|
139
|
+
Allow multiple values to be parsed by a single parser.
|
140
|
+
The entire text must be valid JSON, and values can be seperated
|
141
|
+
by any kind of whitespace
|
142
|
+
|
143
|
+
``` ruby
|
144
|
+
Wankel.parse('{"abc": 123}{"def": 456}')
|
145
|
+
# => Wankel::ParseError
|
146
|
+
|
147
|
+
Wankel.parse('{"abc": 123}{"def": 456}', :multiple_values => true)
|
148
|
+
# => [{"abc"=>123}, {"def"=>456}]
|
149
|
+
|
150
|
+
Wankel.parse('{"abc": 123}{"def": 456}', :multiple_values => true) do |obj|
|
151
|
+
puts obj
|
152
|
+
end
|
153
|
+
# => {"abc"=>123}
|
154
|
+
# => {"def"=>456}
|
155
|
+
```
|
156
|
+
|
157
|
+
* `:allow_partial_values` (Default: `false`)
|
158
|
+
|
159
|
+
TODO
|
160
|
+
|
161
|
+
* `:read_buffer_size` (Default: `8092`)
|
162
|
+
|
163
|
+
The read buffer size in bytes when reading from an `IO` Object.
|
164
|
+
|
165
|
+
|
166
|
+
Encoding Options
|
167
|
+
----------------
|
168
|
+
|
169
|
+
* `:beautify` (Default: `false`)
|
170
|
+
|
171
|
+
Generate indented (beautiful) output.
|
172
|
+
|
173
|
+
``` ruby
|
174
|
+
Wankel.encode({"key" => "value"}, :beautify => true)
|
175
|
+
# => "{\n \"key\": \"value\"\n}\n"
|
176
|
+
```
|
177
|
+
|
178
|
+
* `:indent_string` (Default: `" "`, four spaces)
|
179
|
+
|
180
|
+
The indent string which is used when `:beautify` is enabled
|
181
|
+
|
182
|
+
``` ruby
|
183
|
+
Wankel.encode({"key" => "value"}, :beautify => true, :indent_string => "\t")
|
184
|
+
# => "{\n\t\"key\": \"value\"\n}\n"
|
185
|
+
```
|
186
|
+
|
187
|
+
* `:validate_utf8` (Default: `false`)
|
188
|
+
|
189
|
+
Validate that the strings are valid UTF8.
|
190
|
+
|
191
|
+
``` ruby
|
192
|
+
Wankel.encode(["#{"\201\203"}"], :validate_utf8 => false)
|
193
|
+
# => "[\"#{"\201\203"}\"]"
|
194
|
+
|
195
|
+
Wankel.encode(["#{"\201\203"}"], :validate_utf8 => true)
|
196
|
+
# => Wankel::EncodeError
|
197
|
+
```
|
198
|
+
|
199
|
+
* `:escape_solidus` (Default: `false`)
|
200
|
+
|
201
|
+
The forward solidus (slash or '/' in human) is not required to be escaped in
|
202
|
+
json text. By default, YAJL will not escape it in the iterest of saving bytes.
|
203
|
+
Setting this flag will cause YAJL to always escape '/' in generated JSON
|
204
|
+
strings.
|
205
|
+
|
206
|
+
``` ruby
|
207
|
+
Wankel.encode("/", :escape_solidus => false)
|
208
|
+
# => '"/"'
|
209
|
+
|
210
|
+
Wankel.encode("/", :escape_solidus => true)
|
211
|
+
# => '"\/"'
|
212
|
+
```
|
213
|
+
|
214
|
+
* `:write_buffer_size`
|
215
|
+
|
216
|
+
The write buffer size in bytes before writing to the `IO` object or `String`.
|
217
|
+
|
218
|
+
Performance Comparisons
|
219
|
+
-----------------------
|
220
|
+
|
221
|
+
TODO:
|
222
|
+
|
223
|
+
#### General Encoder
|
224
|
+
|
225
|
+
The test description (ie. Small: 100,000 parses of a 255 byte JSON):
|
226
|
+
|
227
|
+
| Gem | Parse Time | Rate | Ratio |
|
228
|
+
|:------------- |:----------- |:--------------- |:----- |
|
229
|
+
| Wankel | N seconds | N.NK parses/sec | N.N |
|
230
|
+
| OJ | N seconds | N.NK parses/sec | N.N |
|
231
|
+
| Yajl | N seconds | N.NK parses/sec | N.N |
|
232
|
+
| JSON::Ext | N seconds | N.NK parses/sec | N.N |
|
233
|
+
|
234
|
+
#### General Decoder
|
235
|
+
|
236
|
+
#### Streaming Encoder
|
237
|
+
|
238
|
+
#### Streaming Decoder
|
data/ext/wankel/extconf.rb
CHANGED
data/ext/wankel/wankel_parser.c
CHANGED
@@ -45,26 +45,25 @@ static VALUE c_wankel, c_wankelParser, e_parseError, e_encodeError;
|
|
45
45
|
* call-seq: new([options])
|
46
46
|
*
|
47
47
|
* +:symbolize_keys+ will turn hash keys into Ruby symbols, defaults to false.
|
48
|
-
*
|
48
|
+
* Default `false`.
|
49
49
|
*
|
50
50
|
* +:allow_comments+ will ignore javascript style comments in JSON input.
|
51
|
-
*
|
51
|
+
* Default `false`.
|
52
52
|
*
|
53
|
-
* +:
|
54
|
-
*
|
55
|
-
*
|
56
|
-
*
|
53
|
+
* +:validate_utf8+ will verify that all strings in JSON input are valid UTF8
|
54
|
+
* and will emit a parse error if this is not so. This option
|
55
|
+
* makes parsing slightly more expensive (~7% depending on
|
56
|
+
* processor and compiler in use). Default `false`.
|
57
57
|
*
|
58
58
|
* +:allow_trailing_garbage+ will ensure the entire input text was consumed and
|
59
|
-
*
|
59
|
+
* will raise an error otherwise. Default `false`.
|
60
60
|
*
|
61
61
|
* +:multiple_values+ allow multiple values to be parsed by a single parser. The
|
62
|
-
*
|
63
|
-
*
|
64
|
-
*
|
65
|
-
* +:allow_partial_values+ check that the top level value was completely consumed/
|
66
|
-
* Default `false`.
|
62
|
+
* entire text must be valid JSON, and values can be seperated
|
63
|
+
* by any kind of whitespace. Default `false`.
|
67
64
|
*
|
65
|
+
* +:allow_partial_values+ check that the top level value was completely consumed
|
66
|
+
* Default `false`.
|
68
67
|
*
|
69
68
|
* +:read_buffer_size+ is the size of chunk that will be parsed off the input
|
70
69
|
* (if it's an IO) for each loop of the parsing process.
|
data/ext/wankel/yajl_helpers.c
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
#include "yajl_helpers.h"
|
3
3
|
|
4
4
|
static VALUE sym_allow_comments;
|
5
|
-
static VALUE
|
6
|
-
static VALUE
|
5
|
+
static VALUE sym_validate_utf8;
|
6
|
+
static VALUE sym_allow_trailing_garbage;
|
7
7
|
static VALUE sym_multiple_values;
|
8
|
-
static VALUE
|
8
|
+
static VALUE sym_allow_partial_values;
|
9
9
|
static VALUE sym_beautify;
|
10
10
|
static VALUE sym_indent_string;
|
11
11
|
static VALUE sym_validate_utf8;
|
@@ -13,10 +13,10 @@ static VALUE sym_escape_solidus;
|
|
13
13
|
|
14
14
|
void Init_yajl_helpers() {
|
15
15
|
sym_allow_comments = ID2SYM(rb_intern("allow_comments")); rb_gc_register_address(&sym_allow_comments);
|
16
|
-
|
17
|
-
|
16
|
+
sym_validate_utf8 = ID2SYM(rb_intern("validate_utf8")); rb_gc_register_address(&sym_validate_utf8);
|
17
|
+
sym_allow_trailing_garbage = ID2SYM(rb_intern("allow_trailing_garbage")); rb_gc_register_address(&sym_allow_trailing_garbage);
|
18
18
|
sym_multiple_values = ID2SYM(rb_intern("multiple_values")); rb_gc_register_address(&sym_multiple_values);
|
19
|
-
|
19
|
+
sym_allow_partial_values = ID2SYM(rb_intern("allow_partial_values")); rb_gc_register_address(&sym_allow_partial_values);
|
20
20
|
sym_beautify = ID2SYM(rb_intern("beautify")); rb_gc_register_address(&sym_beautify);
|
21
21
|
sym_indent_string = ID2SYM(rb_intern("indent_string")); rb_gc_register_address(&sym_indent_string);
|
22
22
|
sym_validate_utf8 = ID2SYM(rb_intern("validate_utf8")); rb_gc_register_address(&sym_validate_utf8);
|
@@ -76,13 +76,13 @@ void yajl_configure(yajl_handle handle, VALUE options) {
|
|
76
76
|
yajl_config(handle, yajl_allow_comments, 0);
|
77
77
|
}
|
78
78
|
|
79
|
-
if(rb_hash_aref(options,
|
79
|
+
if(rb_hash_aref(options, sym_validate_utf8) == Qtrue) {
|
80
80
|
yajl_config(handle, yajl_dont_validate_strings, 0);
|
81
81
|
} else {
|
82
82
|
yajl_config(handle, yajl_dont_validate_strings, 1);
|
83
83
|
}
|
84
84
|
|
85
|
-
if(rb_hash_aref(options,
|
85
|
+
if(rb_hash_aref(options, sym_allow_trailing_garbage) == Qtrue) {
|
86
86
|
yajl_config(handle, yajl_allow_trailing_garbage, 1);
|
87
87
|
} else {
|
88
88
|
yajl_config(handle, yajl_allow_trailing_garbage, 0);
|
@@ -94,7 +94,7 @@ void yajl_configure(yajl_handle handle, VALUE options) {
|
|
94
94
|
yajl_config(handle, yajl_allow_multiple_values, 0);
|
95
95
|
}
|
96
96
|
|
97
|
-
if(rb_hash_aref(options,
|
97
|
+
if(rb_hash_aref(options, sym_allow_partial_values) == Qtrue) {
|
98
98
|
yajl_config(handle, yajl_allow_partial_values, 1);
|
99
99
|
} else {
|
100
100
|
yajl_config(handle, yajl_allow_partial_values, 0);
|
data/lib/wankel.rb
CHANGED
data/logo.png
CHANGED
Binary file
|
@@ -20,7 +20,7 @@ class TheMindKillerDuce
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
class Wankel::EncoderTest < ::Test
|
23
|
+
class Wankel::EncoderTest < Minitest::Test
|
24
24
|
FILES = Dir[File.dirname(__FILE__)+'/../../benchmark/subjects/*.json']
|
25
25
|
|
26
26
|
FILES.each do |file|
|
@@ -128,6 +128,24 @@ class Wankel::EncoderTest < ::Test::Unit::TestCase
|
|
128
128
|
assert_equal(output, result)
|
129
129
|
end
|
130
130
|
|
131
|
+
test "should encoder not should validate UTF8 strings when :validate_utf8 set to false" do
|
132
|
+
assert_equal("[\"#{"\201\203"}\"]", Wankel.encode(["#{"\201\203"}"], :validate_utf8 => false))
|
133
|
+
end
|
134
|
+
|
135
|
+
test "should encoder should validate UTF8 strings when :validate_utf8 set to true" do
|
136
|
+
assert_raises Wankel::EncodeError do
|
137
|
+
Wankel.encode(["#{"\201\203"}"], :validate_utf8 => true)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
test "should encoder should not escape solidus when :escape_solidus set to false" do
|
142
|
+
assert_equal('"/"', Wankel.encode("/", :escape_solidus => false))
|
143
|
+
end
|
144
|
+
|
145
|
+
test "should encoder should escape solidus when :escape_solidus set to true" do
|
146
|
+
assert_equal('"\/"', Wankel.encode("/", :escape_solidus => true))
|
147
|
+
end
|
148
|
+
|
131
149
|
test "should encode multiple objects into a single stream, to an IO" do
|
132
150
|
io = StringIO.new
|
133
151
|
obj = {:foo => 1234}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'stringio'
|
2
2
|
|
3
|
-
class Wankel::SaxEncoderTest < ::Test
|
3
|
+
class Wankel::SaxEncoderTest < Minitest::Test
|
4
4
|
|
5
5
|
test 'default inherited from Wankel' do
|
6
6
|
encoder = Wankel::SaxEncoder.new(StringIO.new)
|
@@ -68,7 +68,7 @@ class Wankel::SaxEncoderTest < ::Test::Unit::TestCase
|
|
68
68
|
encoder.complete
|
69
69
|
assert_equal("{}", output.string)
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
test "array_open" do
|
73
73
|
output = StringIO.new
|
74
74
|
encoder = Wankel::SaxEncoder.new(output)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
require 'test_helper'
|
3
3
|
|
4
|
-
class Wankel::ActiveSupportTest < ::Test
|
4
|
+
class Wankel::ActiveSupportTest < Minitest::Test
|
5
5
|
|
6
6
|
TESTS = {
|
7
7
|
%q({"returnTo":{"\/categories":"\/"}}) => {"returnTo" => {"/categories" => "/"}},
|
@@ -37,28 +37,24 @@ class Wankel::ActiveSupportTest < ::Test::Unit::TestCase
|
|
37
37
|
|
38
38
|
TESTS.each do |json, expected|
|
39
39
|
test "should be able to parse #{json} as an IO" do
|
40
|
-
|
41
|
-
Wankel.parse(StringIO.new(json))
|
42
|
-
end
|
40
|
+
Wankel.parse(StringIO.new(json))
|
43
41
|
end
|
44
42
|
end
|
45
43
|
|
46
44
|
TESTS.each do |json, expected|
|
47
45
|
test "should be able to parse #{json} as a string" do
|
48
|
-
|
49
|
-
Wankel.parse(json)
|
50
|
-
end
|
46
|
+
Wankel.parse(json)
|
51
47
|
end
|
52
48
|
end
|
53
49
|
|
54
50
|
test "should fail parsing {: 1} as an IO" do
|
55
|
-
|
51
|
+
assert_raises Wankel::ParseError do
|
56
52
|
Wankel.parse(StringIO.new("{: 1}"))
|
57
53
|
end
|
58
54
|
end
|
59
55
|
|
60
56
|
test "should fail parsing {: 1} as a string" do
|
61
|
-
|
57
|
+
assert_raises Wankel::ParseError do
|
62
58
|
Wankel.parse("{: 1}")
|
63
59
|
end
|
64
60
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
require 'test_helper'
|
3
3
|
|
4
|
-
class Wankel::ParsingJSONFixturesTest < ::Test
|
4
|
+
class Wankel::ParsingJSONFixturesTest < Minitest::Test
|
5
5
|
|
6
6
|
fixtures = File.join(File.dirname(__FILE__), 'fixtures/*.json')
|
7
7
|
passed, failed = Dir[fixtures].partition { |f| f['pass'] }
|
@@ -10,7 +10,7 @@ class Wankel::ParsingJSONFixturesTest < ::Test::Unit::TestCase
|
|
10
10
|
|
11
11
|
FAILED.each do |name, source|
|
12
12
|
test "should not be able to parse #{File.basename(name)} as an IO" do
|
13
|
-
|
13
|
+
assert_raises Wankel::ParseError do
|
14
14
|
Wankel.parse(StringIO.new(source))
|
15
15
|
end
|
16
16
|
end
|
@@ -18,7 +18,7 @@ class Wankel::ParsingJSONFixturesTest < ::Test::Unit::TestCase
|
|
18
18
|
|
19
19
|
FAILED.each do |name, source|
|
20
20
|
test "should not be able to parse #{File.basename(name)} as a string" do
|
21
|
-
|
21
|
+
assert_raises Wankel::ParseError do
|
22
22
|
Wankel.parse(source)
|
23
23
|
end
|
24
24
|
end
|
@@ -26,17 +26,13 @@ class Wankel::ParsingJSONFixturesTest < ::Test::Unit::TestCase
|
|
26
26
|
|
27
27
|
PASSED.each do |name, source|
|
28
28
|
test "should be able to parse #{File.basename(name)} as an IO" do
|
29
|
-
|
30
|
-
Wankel.parse(StringIO.new(source), :allow_comments => true)
|
31
|
-
end
|
29
|
+
Wankel.parse(StringIO.new(source), :allow_comments => true)
|
32
30
|
end
|
33
31
|
end
|
34
32
|
|
35
33
|
PASSED.each do |name, source|
|
36
34
|
test "should be able to parse #{File.basename(name)} as a string" do
|
37
|
-
|
38
|
-
Wankel.parse(source, :allow_comments => true)
|
39
|
-
end
|
35
|
+
Wankel.parse(source, :allow_comments => true)
|
40
36
|
end
|
41
37
|
end
|
42
38
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
require 'test_helper'
|
3
3
|
|
4
|
-
class Wankel::MultipleValuesTest < ::Test
|
4
|
+
class Wankel::MultipleValuesTest < Minitest::Test
|
5
5
|
|
6
6
|
test "parsing with :multiple_values returns an array of values" do
|
7
7
|
assert_equal([true], Wankel.parse('true', :multiple_values => true))
|
@@ -14,7 +14,7 @@ class Wankel::MultipleValuesTest < ::Test::Unit::TestCase
|
|
14
14
|
end
|
15
15
|
|
16
16
|
test "parsing with should raise a Wankel::ParseError error if multiple JSON strings were found when :multiple_values => false" do
|
17
|
-
|
17
|
+
assert_raises Wankel::ParseError do
|
18
18
|
result = Wankel.parse('[{"abc": 123}][{"def": 456}]', :multiple_values => false)
|
19
19
|
end
|
20
20
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
require 'test_helper'
|
3
3
|
|
4
|
-
class Wankel::OneOffParseTest < ::Test
|
4
|
+
class Wankel::OneOffParseTest < Minitest::Test
|
5
5
|
|
6
6
|
test "should parse 23456789012E666 as Infinity" do
|
7
7
|
infinity = (1.0/0)
|
@@ -9,19 +9,32 @@ class Wankel::OneOffParseTest < ::Test::Unit::TestCase
|
|
9
9
|
end
|
10
10
|
|
11
11
|
test "should not parse JSON with a comment, with :allow_comments set to false" do
|
12
|
-
|
12
|
+
assert_raises Wankel::ParseError do
|
13
13
|
Wankel.parse('{"key": /* this is a comment */ "value"}', :allow_comments => false)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
test "should not parse invalid UTF8 with :
|
18
|
-
|
19
|
-
Wankel.parse("[\"#{"\201\203"}\"]", :
|
17
|
+
test "should not parse invalid UTF8 with :validate_utf8 set to true" do
|
18
|
+
assert_raises Wankel::ParseError do
|
19
|
+
Wankel.parse("[\"#{"\201\203"}\"]", :validate_utf8 => true)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
test "should parse invalid UTF8 with :
|
24
|
-
Wankel.parse("[\"#{"\201\203"}\"]", :
|
23
|
+
test "should parse invalid UTF8 with :validate_utf8 set to false" do
|
24
|
+
Wankel.parse("[\"#{"\201\203"}\"]", :validate_utf8 => false)
|
25
|
+
end
|
26
|
+
|
27
|
+
test "should not allow trailing garbage with :allow_trailing_garbage set to false" do
|
28
|
+
assert_raises Wankel::ParseError do
|
29
|
+
Wankel.parse('{"key": "value"}gar', :allow_trailing_garbage => false)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
test "should allow trailing garbage with :allow_trailing_garbage set to true" do
|
34
|
+
assert_equal(
|
35
|
+
{"key" => "value"},
|
36
|
+
Wankel.parse('{"key": "value"}gar', :allow_trailing_garbage => true)
|
37
|
+
)
|
25
38
|
end
|
26
39
|
|
27
40
|
test "should parse using it's class method, from an IO" do
|
data/test/performance.rb
CHANGED
@@ -130,6 +130,6 @@ perf = Perf.new()
|
|
130
130
|
perf.add('JSON::Ext', 'parse') { JSON::Ext::Parser.new(@json).parse }
|
131
131
|
perf.add('Yajl', 'parse') { Yajl::Parser.parse(@json) }
|
132
132
|
perf.add('Oj::Doc', 'parse') { Oj.load(@json) }
|
133
|
-
parser = Wankel::Parser.new
|
133
|
+
parser = Wankel::Parser.new
|
134
134
|
perf.add('Wankel', 'parse') { parser.parse(@json) }
|
135
135
|
perf.run(1000)
|
data/test/test_helper.rb
CHANGED
@@ -13,14 +13,16 @@ lib = File.expand_path(File.join(root, 'lib'))
|
|
13
13
|
|
14
14
|
$LOAD_PATH << lib
|
15
15
|
|
16
|
-
require
|
17
|
-
require '
|
16
|
+
require "minitest/autorun"
|
17
|
+
require 'minitest/unit'
|
18
|
+
require 'minitest/reporters'
|
18
19
|
require "mocha/setup"
|
19
20
|
require 'wankel'
|
20
21
|
|
22
|
+
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
|
21
23
|
|
22
24
|
# File 'lib/active_support/testing/declarative.rb', somewhere in rails....
|
23
|
-
class ::Test
|
25
|
+
class Minitest::Test
|
24
26
|
def self.test(name, &block)
|
25
27
|
test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
|
26
28
|
defined = instance_method(test_name) rescue false
|
data/test/wankel_test.rb
CHANGED
data/wankel.gemspec
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
|
-
s.name
|
3
|
-
s.version
|
4
|
-
s.
|
5
|
-
s.
|
6
|
-
s.
|
7
|
-
s.
|
8
|
-
s.
|
2
|
+
s.name = 'wankel'
|
3
|
+
s.version = '0.1.1'
|
4
|
+
s.licenses = ['MIT']
|
5
|
+
s.authors = ['Jon Bracy']
|
6
|
+
s.email = ['jonbracy@gmail.com']
|
7
|
+
s.homepage = 'http://wankelrb.com'
|
8
|
+
s.summary = 'SAX based JSON parser and encoder'
|
9
|
+
s.description = 'A JSON parser that enables streaming parsing and encoding of JSON'
|
9
10
|
|
10
|
-
s.rubyforge_project = "wankel"
|
11
|
-
|
12
11
|
s.files = `git ls-files`.split("\n")
|
13
12
|
s.extensions = ['ext/wankel/extconf.rb']
|
14
13
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -16,8 +15,8 @@ Gem::Specification.new do |s|
|
|
16
15
|
|
17
16
|
s.required_ruby_version = '>= 2.0.0'
|
18
17
|
|
19
|
-
s.add_development_dependency 'rake-compiler'
|
20
|
-
s.add_development_dependency 'minitest'
|
21
|
-
s.add_development_dependency '
|
22
|
-
s.add_development_dependency 'mocha'
|
23
|
-
end
|
18
|
+
s.add_development_dependency 'rake-compiler', '~> 0.9'
|
19
|
+
s.add_development_dependency 'minitest', '~> 5.3'
|
20
|
+
s.add_development_dependency 'minitest-reporters', '~> 1.0'
|
21
|
+
s.add_development_dependency 'mocha', '~> 1.1'
|
22
|
+
end
|
metadata
CHANGED
@@ -1,72 +1,72 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wankel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Bracy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '0.9'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '0.9'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '5.3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '5.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: minitest-reporters
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '1.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
54
|
+
version: '1.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: mocha
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '1.1'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
69
|
-
description:
|
68
|
+
version: '1.1'
|
69
|
+
description: A JSON parser that enables streaming parsing and encoding of JSON
|
70
70
|
email:
|
71
71
|
- jonbracy@gmail.com
|
72
72
|
executables: []
|
@@ -74,7 +74,7 @@ extensions:
|
|
74
74
|
- ext/wankel/extconf.rb
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
|
-
- .gitignore
|
77
|
+
- ".gitignore"
|
78
78
|
- LICENSE
|
79
79
|
- README.md
|
80
80
|
- Rakefile
|
@@ -167,7 +167,8 @@ files:
|
|
167
167
|
- test/wankel_test.rb
|
168
168
|
- wankel.gemspec
|
169
169
|
homepage: http://wankelrb.com
|
170
|
-
licenses:
|
170
|
+
licenses:
|
171
|
+
- MIT
|
171
172
|
metadata: {}
|
172
173
|
post_install_message:
|
173
174
|
rdoc_options: []
|
@@ -175,17 +176,17 @@ require_paths:
|
|
175
176
|
- lib
|
176
177
|
required_ruby_version: !ruby/object:Gem::Requirement
|
177
178
|
requirements:
|
178
|
-
- -
|
179
|
+
- - ">="
|
179
180
|
- !ruby/object:Gem::Version
|
180
181
|
version: 2.0.0
|
181
182
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
183
|
requirements:
|
183
|
-
- -
|
184
|
+
- - ">="
|
184
185
|
- !ruby/object:Gem::Version
|
185
186
|
version: '0'
|
186
187
|
requirements: []
|
187
|
-
rubyforge_project:
|
188
|
-
rubygems_version: 2.
|
188
|
+
rubyforge_project:
|
189
|
+
rubygems_version: 2.2.2
|
189
190
|
signing_key:
|
190
191
|
specification_version: 4
|
191
192
|
summary: SAX based JSON parser and encoder
|
@@ -257,3 +258,4 @@ test_files:
|
|
257
258
|
- test/performance.rb
|
258
259
|
- test/test_helper.rb
|
259
260
|
- test/wankel_test.rb
|
261
|
+
has_rdoc:
|