hana 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hana.rb +9 -7
- data/test/helper.rb +5 -1
- data/test/json-patch-tests/README.md +30 -5
- data/test/json-patch-tests/spec_tests.json +4 -3
- data/test/json-patch-tests/tests.json +87 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ccb71fa0fbe43f9887bd8a7f3a1b5ad9273acbcb
|
4
|
+
data.tar.gz: 807c25b1c8b8dcc67ce9f109799224f91bff37ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44ebd19bc18f9aac58a3e22d97ef0af22249bd2d559d5b25e876d0054fd12c5d4ed4bc8def868da96c71d1655809006578d6ca3bfe0931c3abf42b00549154b0
|
7
|
+
data.tar.gz: f8882b84a664e16bb252138a101af07640c3dbcd33c037ed777d33838815a1b7c458c710b3877ca1abd39c484cea61981b4e63ace77c6d495a1ca02a808c4f61
|
data/lib/hana.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Hana
|
2
|
-
VERSION = '1.3.
|
2
|
+
VERSION = '1.3.1'
|
3
3
|
|
4
4
|
class Pointer
|
5
5
|
include Enumerable
|
@@ -88,7 +88,7 @@ module Hana
|
|
88
88
|
list = Pointer.parse ins[PATH]
|
89
89
|
key = list.pop
|
90
90
|
dest = Pointer.eval list, doc
|
91
|
-
obj = ins
|
91
|
+
obj = ins.fetch VALUE
|
92
92
|
|
93
93
|
raise(MissingTargetException, ins[PATH]) unless dest
|
94
94
|
|
@@ -101,7 +101,7 @@ module Hana
|
|
101
101
|
end
|
102
102
|
|
103
103
|
def move ins, doc
|
104
|
-
from = Pointer.parse ins
|
104
|
+
from = Pointer.parse ins.fetch FROM
|
105
105
|
to = Pointer.parse ins[PATH]
|
106
106
|
from_key = from.pop
|
107
107
|
key = to.pop
|
@@ -114,7 +114,7 @@ module Hana
|
|
114
114
|
end
|
115
115
|
|
116
116
|
def copy ins, doc
|
117
|
-
from = Pointer.parse ins
|
117
|
+
from = Pointer.parse ins.fetch FROM
|
118
118
|
to = Pointer.parse ins[PATH]
|
119
119
|
from_key = from.pop
|
120
120
|
key = to.pop
|
@@ -135,7 +135,7 @@ module Hana
|
|
135
135
|
def test ins, doc
|
136
136
|
expected = Pointer.new(ins[PATH]).eval doc
|
137
137
|
|
138
|
-
unless expected == ins
|
138
|
+
unless expected == ins.fetch(VALUE)
|
139
139
|
raise FailedTestException.new(ins[VALUE], ins[PATH])
|
140
140
|
end
|
141
141
|
doc
|
@@ -146,11 +146,13 @@ module Hana
|
|
146
146
|
key = list.pop
|
147
147
|
obj = Pointer.eval list, doc
|
148
148
|
|
149
|
+
return ins.fetch VALUE unless key
|
150
|
+
|
149
151
|
if Array === obj
|
150
152
|
raise Patch::IndexError unless key =~ /\A\d+\Z/
|
151
|
-
obj[key.to_i] = ins
|
153
|
+
obj[key.to_i] = ins.fetch VALUE
|
152
154
|
else
|
153
|
-
obj[key] = ins
|
155
|
+
obj[key] = ins.fetch VALUE
|
154
156
|
end
|
155
157
|
doc
|
156
158
|
end
|
data/test/helper.rb
CHANGED
@@ -49,7 +49,11 @@ module Hana
|
|
49
49
|
[Hana::Patch::IndexError, Hana::Patch::ObjectOperationOnArrayException]
|
50
50
|
when /bad number$/ then
|
51
51
|
[Hana::Patch::IndexError, Hana::Patch::ObjectOperationOnArrayException]
|
52
|
-
when /missing|
|
52
|
+
when /missing '(from|value)' parameter/ then
|
53
|
+
[KeyError]
|
54
|
+
when /Unrecognized op 'spam'/ then
|
55
|
+
[Hana::Patch::Exception]
|
56
|
+
when /missing|non-existent/ then
|
53
57
|
[Hana::Patch::MissingTargetException]
|
54
58
|
else
|
55
59
|
[Hana::Patch::FailedTestException]
|
@@ -1,8 +1,9 @@
|
|
1
1
|
JSON Patch Tests
|
2
2
|
================
|
3
3
|
|
4
|
-
These are test cases for implementations of
|
5
|
-
|
4
|
+
These are test cases for implementations of [IETF JSON Patch (RFC6902)](http://tools.ietf.org/html/rfc6902).
|
5
|
+
|
6
|
+
Some implementations can be found at [jsonpatch.com](http://jsonpatch.com).
|
6
7
|
|
7
8
|
|
8
9
|
Test Format
|
@@ -21,7 +22,30 @@ test record is an object with the following members:
|
|
21
22
|
All fields except 'doc' and 'patch' are optional. Test records consisting only
|
22
23
|
of a comment are also OK.
|
23
24
|
|
24
|
-
|
25
|
+
|
26
|
+
Files
|
27
|
+
-----
|
28
|
+
|
29
|
+
- tests.json: the main test file
|
30
|
+
- spec_tests.json: tests from the RFC6902 spec
|
31
|
+
|
32
|
+
|
33
|
+
Writing Tests
|
34
|
+
-------------
|
35
|
+
|
36
|
+
All tests should have a descriptive comment. Tests should be as
|
37
|
+
simple as possible - just what's required to test a specific piece of
|
38
|
+
behavior. If you want to test interacting behaviors, create tests for
|
39
|
+
each behavior as well as the interaction.
|
40
|
+
|
41
|
+
If an 'error' member is specified, the error text should describe the
|
42
|
+
error the implementation should raise - *not* what's being tested.
|
43
|
+
Implementation error strings will vary, but the suggested error should
|
44
|
+
be easily matched to the implementation error string. Try to avoid
|
45
|
+
creating error tests that might pass because an incorrect error was
|
46
|
+
reported.
|
47
|
+
|
48
|
+
Please feel free to contribute!
|
25
49
|
|
26
50
|
|
27
51
|
Credits
|
@@ -35,7 +59,7 @@ extended by [Mike McCabe](https://github.com/mikemccabe).
|
|
35
59
|
License
|
36
60
|
-------
|
37
61
|
|
38
|
-
Copyright
|
62
|
+
Copyright 2014 The Authors
|
39
63
|
|
40
64
|
Licensed under the Apache License, Version 2.0 (the "License");
|
41
65
|
you may not use this file except in compliance with the License.
|
@@ -47,4 +71,5 @@ License
|
|
47
71
|
distributed under the License is distributed on an "AS IS" BASIS,
|
48
72
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
49
73
|
See the License for the specific language governing permissions and
|
50
|
-
limitations under the License.
|
74
|
+
limitations under the License.
|
75
|
+
|
@@ -174,14 +174,14 @@
|
|
174
174
|
},
|
175
175
|
|
176
176
|
{
|
177
|
-
"comment": "A.12. Adding to a Non-
|
177
|
+
"comment": "A.12. Adding to a Non-existent Target",
|
178
178
|
"doc": {
|
179
179
|
"foo": "bar"
|
180
180
|
},
|
181
181
|
"patch": [
|
182
182
|
{ "op": "add", "path": "/baz/bat", "value": "qux" }
|
183
183
|
],
|
184
|
-
"error": "add to a non-
|
184
|
+
"error": "add to a non-existent target"
|
185
185
|
},
|
186
186
|
|
187
187
|
{
|
@@ -192,7 +192,8 @@
|
|
192
192
|
"patch": [
|
193
193
|
{ "op": "add", "path": "/baz", "value": "qux", "op": "remove" }
|
194
194
|
],
|
195
|
-
"error": "operation has two 'op' members"
|
195
|
+
"error": "operation has two 'op' members",
|
196
|
+
"disabled": true
|
196
197
|
},
|
197
198
|
|
198
199
|
{
|
@@ -171,6 +171,11 @@
|
|
171
171
|
"expected": ["foo", ["bar", "baz"]],
|
172
172
|
"comment": "value in array replace not flattened" },
|
173
173
|
|
174
|
+
{ "comment": "replace whole document",
|
175
|
+
"doc": {"foo": "bar"},
|
176
|
+
"patch": [{"op": "replace", "path": "", "value": {"baz": "qux"}}],
|
177
|
+
"expected": {"baz": "qux"} },
|
178
|
+
|
174
179
|
{ "comment": "spurious patch properties",
|
175
180
|
"doc": {"foo": 1},
|
176
181
|
"patch": [{"op": "test", "path": "/foo", "value": 1, "spurious": 1}],
|
@@ -196,8 +201,6 @@
|
|
196
201
|
"patch": [{"op": "test", "path": "/foo", "value": [1, 2]}],
|
197
202
|
"error": "test op should fail" },
|
198
203
|
|
199
|
-
{ "comment": "json-pointer tests" },
|
200
|
-
|
201
204
|
{ "comment": "Whole document",
|
202
205
|
"doc": { "foo": 1 },
|
203
206
|
"patch": [{"op": "test", "path": "", "value": {"foo": 1}}],
|
@@ -263,5 +266,86 @@
|
|
263
266
|
"patch": [ { "op": "add", "path": "/2/1/-", "value": { "foo": [ "bar", "baz" ] } } ],
|
264
267
|
"expected": [ 1, 2, [ 3, [ 4, 5, { "foo": [ "bar", "baz" ] } ] ] ]},
|
265
268
|
|
266
|
-
{ "comment": "
|
269
|
+
{ "comment": "test remove with bad number should fail",
|
270
|
+
"doc": {"foo": 1, "baz": [{"qux": "hello"}]},
|
271
|
+
"patch": [{"op": "remove", "path": "/baz/1e0/qux"}],
|
272
|
+
"error": "remove op shouldn't remove from array with bad number" },
|
273
|
+
|
274
|
+
{ "comment": "test remove on array",
|
275
|
+
"doc": [1, 2, 3, 4],
|
276
|
+
"patch": [{"op": "remove", "path": "/0"}],
|
277
|
+
"expected": [2, 3, 4] },
|
278
|
+
|
279
|
+
{ "comment": "test repeated removes",
|
280
|
+
"doc": [1, 2, 3, 4],
|
281
|
+
"patch": [{ "op": "remove", "path": "/1" },
|
282
|
+
{ "op": "remove", "path": "/2" }],
|
283
|
+
"expected": [1, 3] },
|
284
|
+
|
285
|
+
{ "comment": "test remove with bad index should fail",
|
286
|
+
"doc": [1, 2, 3, 4],
|
287
|
+
"patch": [{"op": "remove", "path": "/1e0"}],
|
288
|
+
"error": "remove op shouldn't remove from array with bad number" },
|
289
|
+
|
290
|
+
{ "comment": "test replace with bad number should fail",
|
291
|
+
"doc": [""],
|
292
|
+
"patch": [{"op": "replace", "path": "/1e0", "value": false}],
|
293
|
+
"error": "replace op shouldn't replace in array with bad number" },
|
294
|
+
|
295
|
+
{ "comment": "test copy with bad number should fail",
|
296
|
+
"doc": {"baz": [1,2,3], "bar": 1},
|
297
|
+
"patch": [{"op": "copy", "from": "/baz/1e0", "path": "/boo"}],
|
298
|
+
"error": "copy op shouldn't work with bad number" },
|
299
|
+
|
300
|
+
{ "comment": "test move with bad number should fail",
|
301
|
+
"doc": {"foo": 1, "baz": [1,2,3,4]},
|
302
|
+
"patch": [{"op": "move", "from": "/baz/1e0", "path": "/foo"}],
|
303
|
+
"error": "move op shouldn't work with bad number" },
|
304
|
+
|
305
|
+
{ "comment": "test add with bad number should fail",
|
306
|
+
"doc": ["foo", "sil"],
|
307
|
+
"patch": [{"op": "add", "path": "/1e0", "value": "bar"}],
|
308
|
+
"error": "add op shouldn't add to array with bad number" },
|
309
|
+
|
310
|
+
{ "comment": "missing 'value' parameter to add",
|
311
|
+
"doc": [ 1 ],
|
312
|
+
"patch": [ { "op": "add", "path": "/-" } ],
|
313
|
+
"error": "missing 'value' parameter" },
|
314
|
+
|
315
|
+
{ "comment": "missing 'value' parameter to replace",
|
316
|
+
"doc": [ 1 ],
|
317
|
+
"patch": [ { "op": "replace", "path": "/0" } ],
|
318
|
+
"error": "missing 'value' parameter" },
|
319
|
+
|
320
|
+
{ "comment": "missing 'value' parameter to test",
|
321
|
+
"doc": [ null ],
|
322
|
+
"patch": [ { "op": "test", "path": "/0" } ],
|
323
|
+
"error": "missing 'value' parameter" },
|
324
|
+
|
325
|
+
{ "comment": "missing value parameter to test - where undef is falsy",
|
326
|
+
"doc": [ false ],
|
327
|
+
"patch": [ { "op": "test", "path": "/0" } ],
|
328
|
+
"error": "missing 'value' parameter" },
|
329
|
+
|
330
|
+
{ "comment": "missing from parameter to copy",
|
331
|
+
"doc": [ 1 ],
|
332
|
+
"patch": [ { "op": "copy", "path": "/-" } ],
|
333
|
+
"error": "missing 'from' parameter" },
|
334
|
+
|
335
|
+
{ "comment": "missing from parameter to move",
|
336
|
+
"doc": { "foo": 1 },
|
337
|
+
"patch": [ { "op": "move", "path": "" } ],
|
338
|
+
"error": "missing 'from' parameter" },
|
339
|
+
|
340
|
+
{ "comment": "duplicate ops",
|
341
|
+
"doc": { "foo": "bar" },
|
342
|
+
"patch": [ { "op": "add", "path": "/baz", "value": "qux",
|
343
|
+
"op": "move", "from":"/foo" } ],
|
344
|
+
"error": "patch has two 'op' members",
|
345
|
+
"disabled": true },
|
346
|
+
|
347
|
+
{ "comment": "unrecognized op should fail",
|
348
|
+
"doc": {"foo": 1},
|
349
|
+
"patch": [{"op": "spam", "path": "/foo", "value": 1}],
|
350
|
+
"error": "Unrecognized op 'spam'" }
|
267
351
|
]
|