hana 1.2.0 → 1.2.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/Manifest.txt +1 -0
- data/Rakefile +1 -0
- data/lib/hana.rb +12 -8
- data/test/helper.rb +53 -1
- data/test/mine.json +36 -0
- data/test/test_ietf.rb +11 -33
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1cbfce7020c1e6b550e0c4b08659f36ec2dcee8e
|
4
|
+
data.tar.gz: c3283388b7d72f50c74d66c693a154bfd3a223a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 944e3a00cbd11622b76d000cd28ba368338b4483e5827da783ea2a6d8cda46d7e378fb9c2eb654b328774b2f97d4d3504232cb879a97f297f633a58c688ce526
|
7
|
+
data.tar.gz: c890fff53ef18b8ff1b4df345749e2097106e3a636e6cc307a9bed7bd757e591447115561dbeb861030f254159a1d088777d58ab35f9668d990314f2e623b10a
|
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
data/lib/hana.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Hana
|
2
|
-
VERSION = '1.2.
|
2
|
+
VERSION = '1.2.1'
|
3
3
|
|
4
4
|
class Pointer
|
5
5
|
include Enumerable
|
@@ -20,7 +20,7 @@ module Hana
|
|
20
20
|
def self.eval list, object
|
21
21
|
list.inject(object) { |o, part|
|
22
22
|
if Array === o
|
23
|
-
raise Patch::
|
23
|
+
raise Patch::IndexError unless part =~ /\A\d+\Z/
|
24
24
|
part = part.to_i
|
25
25
|
end
|
26
26
|
o[part]
|
@@ -56,7 +56,10 @@ module Hana
|
|
56
56
|
class ObjectOperationOnArrayException < Exception
|
57
57
|
end
|
58
58
|
|
59
|
-
class
|
59
|
+
class IndexError < Exception
|
60
|
+
end
|
61
|
+
|
62
|
+
class MissingTargetException < Exception
|
60
63
|
end
|
61
64
|
|
62
65
|
def initialize is
|
@@ -81,6 +84,8 @@ module Hana
|
|
81
84
|
dest = Pointer.eval list, doc
|
82
85
|
obj = ins['value']
|
83
86
|
|
87
|
+
raise(MissingTargetException, ins['path']) unless dest
|
88
|
+
|
84
89
|
if key
|
85
90
|
add_op dest, key, obj
|
86
91
|
else
|
@@ -109,6 +114,7 @@ module Hana
|
|
109
114
|
dest = Pointer.eval to, doc
|
110
115
|
|
111
116
|
if Array === src
|
117
|
+
raise Patch::IndexError unless from_key =~ /\A\d+\Z/
|
112
118
|
obj = src.fetch from_key.to_i
|
113
119
|
else
|
114
120
|
obj = src.fetch from_key
|
@@ -118,11 +124,7 @@ module Hana
|
|
118
124
|
end
|
119
125
|
|
120
126
|
def test ins, doc
|
121
|
-
|
122
|
-
expected = Pointer.new(ins['path']).eval doc
|
123
|
-
rescue Patch::IndexException
|
124
|
-
raise FailedTestException.new(ins['value'], ins['path'])
|
125
|
-
end
|
127
|
+
expected = Pointer.new(ins['path']).eval doc
|
126
128
|
|
127
129
|
unless expected == ins['value']
|
128
130
|
raise FailedTestException.new(ins['value'], ins['path'])
|
@@ -135,6 +137,7 @@ module Hana
|
|
135
137
|
obj = Pointer.eval list, doc
|
136
138
|
|
137
139
|
if Array === obj
|
140
|
+
raise Patch::IndexError unless key =~ /\A\d+\Z/
|
138
141
|
obj[key.to_i] = ins['value']
|
139
142
|
else
|
140
143
|
obj[key] = ins['value']
|
@@ -167,6 +170,7 @@ module Hana
|
|
167
170
|
|
168
171
|
def rm_op obj, key
|
169
172
|
if Array === obj
|
173
|
+
raise Patch::IndexError unless key =~ /\A\d+\Z/
|
170
174
|
obj.delete_at key.to_i
|
171
175
|
else
|
172
176
|
obj.delete key
|
data/test/helper.rb
CHANGED
@@ -1,7 +1,59 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
2
|
require 'hana'
|
3
|
+
require 'json'
|
3
4
|
|
4
5
|
module Hana
|
5
|
-
class TestCase <
|
6
|
+
class TestCase < Minitest::Test
|
7
|
+
TESTDIR = File.dirname File.expand_path __FILE__
|
8
|
+
|
9
|
+
def self.read_test_json_file file
|
10
|
+
Module.new {
|
11
|
+
tests = JSON.load File.read file
|
12
|
+
tests.each_with_index do |test, i|
|
13
|
+
next unless test['doc']
|
14
|
+
|
15
|
+
define_method("test_#{test['comment'] || i }") do
|
16
|
+
skip "disabled" if test['disabled']
|
17
|
+
|
18
|
+
doc = test['doc']
|
19
|
+
patch = test['patch']
|
20
|
+
|
21
|
+
patch = Hana::Patch.new patch
|
22
|
+
|
23
|
+
if test['error']
|
24
|
+
assert_raises(*ex(test['error'])) do
|
25
|
+
patch.apply doc
|
26
|
+
end
|
27
|
+
else
|
28
|
+
assert_equal(test['expected'] || doc, patch.apply(doc))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.skip regexp, message
|
36
|
+
instance_methods.grep(regexp).each do |method|
|
37
|
+
define_method(method) { skip message }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def ex msg
|
44
|
+
case msg
|
45
|
+
when /Out of bounds/i then [Hana::Patch::OutOfBoundsException]
|
46
|
+
when /Object operation on array/ then
|
47
|
+
[Hana::Patch::ObjectOperationOnArrayException]
|
48
|
+
when /test op shouldn't get array element/ then
|
49
|
+
[Hana::Patch::IndexError, Hana::Patch::ObjectOperationOnArrayException]
|
50
|
+
when /bad number$/ then
|
51
|
+
[Hana::Patch::IndexError, Hana::Patch::ObjectOperationOnArrayException]
|
52
|
+
when /missing|non-existant/ then
|
53
|
+
[Hana::Patch::MissingTargetException]
|
54
|
+
else
|
55
|
+
[Hana::Patch::FailedTestException]
|
56
|
+
end
|
57
|
+
end
|
6
58
|
end
|
7
59
|
end
|
data/test/mine.json
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
[
|
2
|
+
{ "comment": "test remove with bad number should fail",
|
3
|
+
"doc": {"foo": 1, "baz": [{"qux": "hello"}]},
|
4
|
+
"patch": [{"op": "remove", "path": "/baz/1e0/qux"}],
|
5
|
+
"error": "remove op shouldn't remove from array with bad number" },
|
6
|
+
|
7
|
+
{ "comment": "test remove on array",
|
8
|
+
"doc": [1, 2, 3, 4],
|
9
|
+
"patch": [{"op": "remove", "path": "/0"}],
|
10
|
+
"expected": [2, 3, 4] },
|
11
|
+
|
12
|
+
{ "comment": "test remove with bad index should fail",
|
13
|
+
"doc": [1, 2, 3, 4],
|
14
|
+
"patch": [{"op": "remove", "path": "/1e0"}],
|
15
|
+
"error": "remove op shouldn't remove from array with bad number" },
|
16
|
+
|
17
|
+
{ "comment": "test replace with bad number should fail",
|
18
|
+
"doc": [""],
|
19
|
+
"patch": [{"op": "replace", "path": "/1e0", "value": false}],
|
20
|
+
"error": "replace op shouldn't replace in array with bad number" },
|
21
|
+
|
22
|
+
{ "comment": "test copy with bad number should fail",
|
23
|
+
"doc": {"baz": [1,2,3], "bar": 1},
|
24
|
+
"patch": [{"op": "copy", "from": "/baz/1e0", "path": "/boo"}],
|
25
|
+
"error": "copy op shouldn't work with bad number" },
|
26
|
+
|
27
|
+
{ "comment": "test move with bad number should fail",
|
28
|
+
"doc": {"foo": 1, "baz": [1,2,3,4]},
|
29
|
+
"patch": [{"op": "move", "from": "/baz/1e0", "path": "/foo"}],
|
30
|
+
"error": "move op shouldn't work with bad number" },
|
31
|
+
|
32
|
+
{ "comment": "test add with bad number should fail",
|
33
|
+
"doc": ["foo", "sil"],
|
34
|
+
"patch": [{"op": "add", "path": "/1e0", "value": "bar"}],
|
35
|
+
"error": "add op shouldn't add to array with bad number" }
|
36
|
+
]
|
data/test/test_ietf.rb
CHANGED
@@ -1,42 +1,20 @@
|
|
1
1
|
require 'helper'
|
2
|
-
require 'json'
|
3
2
|
|
4
3
|
module Hana
|
5
4
|
class TestIETF < TestCase
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
tests.each_with_index do |test, i|
|
10
|
-
next unless test['doc']
|
11
|
-
|
12
|
-
define_method("test_#{test['comment'] || i }") do
|
13
|
-
skip "disabled" if test['disabled']
|
14
|
-
|
15
|
-
doc = test['doc']
|
16
|
-
patch = test['patch']
|
17
|
-
|
18
|
-
patch = Hana::Patch.new patch
|
5
|
+
filename = File.join TESTDIR, 'json-patch-tests', 'tests.json'
|
6
|
+
include read_test_json_file filename
|
7
|
+
end
|
19
8
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
else
|
25
|
-
assert_equal(test['expected'] || doc, patch.apply(doc))
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
9
|
+
class TestSpec < TestCase
|
10
|
+
filename = File.join TESTDIR, 'json-patch-tests', 'spec_tests.json'
|
11
|
+
include read_test_json_file filename
|
29
12
|
|
30
|
-
|
13
|
+
skip(/A\.13/, 'This test depends on the JSON parser')
|
14
|
+
end
|
31
15
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
when /Object operation on array/ then
|
36
|
-
Hana::Patch::ObjectOperationOnArrayException
|
37
|
-
else
|
38
|
-
Hana::Patch::FailedTestException
|
39
|
-
end
|
40
|
-
end
|
16
|
+
class MyTests < TestCase
|
17
|
+
filename = File.join TESTDIR, 'mine.json'
|
18
|
+
include read_test_json_file filename
|
41
19
|
end
|
42
20
|
end
|
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.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Patterson
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- test/json-patch-tests/README.md
|
73
73
|
- test/json-patch-tests/spec_tests.json
|
74
74
|
- test/json-patch-tests/tests.json
|
75
|
+
- test/mine.json
|
75
76
|
- test/test_hana.rb
|
76
77
|
- test/test_ietf.rb
|
77
78
|
- .gemtest
|