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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 47901af6a51be41cedcdbea157ab51919387f620
4
- data.tar.gz: 533536f30bece16ab323ef9af184dbf7aca22e6f
3
+ metadata.gz: ccb71fa0fbe43f9887bd8a7f3a1b5ad9273acbcb
4
+ data.tar.gz: 807c25b1c8b8dcc67ce9f109799224f91bff37ad
5
5
  SHA512:
6
- metadata.gz: 0720be506f273f9404ba4ac0f62b46599eec0935906e07542b6fbb95da6e5054193b87f96de888c7680cced1c543b551a193a02499f2b39cf3bfb597dc611e41
7
- data.tar.gz: 840399954c106f206257c46f4d217a2ed06d23f84b92c0d30e59b65b77839c21d335ca806188da86621de5403195b4a941eefd421846576d3763af8a5dac8c4e
6
+ metadata.gz: 44ebd19bc18f9aac58a3e22d97ef0af22249bd2d559d5b25e876d0054fd12c5d4ed4bc8def868da96c71d1655809006578d6ca3bfe0931c3abf42b00549154b0
7
+ data.tar.gz: f8882b84a664e16bb252138a101af07640c3dbcd33c037ed777d33838815a1b7c458c710b3877ca1abd39c484cea61981b4e63ace77c6d495a1ca02a808c4f61
@@ -1,5 +1,5 @@
1
1
  module Hana
2
- VERSION = '1.3.0'
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[VALUE]
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[FROM]
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[FROM]
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[VALUE]
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[VALUE]
153
+ obj[key.to_i] = ins.fetch VALUE
152
154
  else
153
- obj[key] = ins[VALUE]
155
+ obj[key] = ins.fetch VALUE
154
156
  end
155
157
  doc
156
158
  end
@@ -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|non-existant/ then
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 the [IETF JSON Patch
5
- draft](http://tools.ietf.org/html/draft-ietf-appsawg-json-patch).
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
- These tests are not complete, or even correct - help welcome!
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 2012 The Authors
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-existant Target",
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-existant target"
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": "tests complete" }
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
  ]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hana
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Patterson