jsonerino 0.1.1 → 0.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/.github/workflows/tests.yml +20 -0
- data/.gitignore +0 -1
- data/Gemfile.lock +53 -0
- data/jsonerino.gemspec +17 -18
- data/lib/jsonerino/version.rb +1 -1
- data/spec/jsonerino/complex_values_spec.rb +143 -0
- data/spec/jsonerino/parse_error_spec.rb +32 -0
- data/spec/jsonerino/primitive_values_spec.rb +33 -0
- metadata +22 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db0148117c4f1e97e7a59f11c194b3ad895a993e972d9d13cd9a705764e2fd8d
|
4
|
+
data.tar.gz: 218b29012c65b31f756d0ad021e53004d304c7b8cef140fbb9efaeefb542d868
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 954f20f2dad9611b23aa7f40f284a9b1b6121dc434ae7e2d3c252f5292c95130d479906a814048cc46ee4080e2edd6f1e5b5a977a9d1f3c2bdc8638583960ea3
|
7
|
+
data.tar.gz: 12f33ea0ff37354f8ae892e809777c8b34e87e552fc8b6a1d58ff7586bb72d0bb4086fc6192840efdbb7f7ef727d20833d9b7111c00f5732e40d6a04d7074aaf
|
@@ -0,0 +1,20 @@
|
|
1
|
+
name: Tests
|
2
|
+
|
3
|
+
on: pull_request
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
rspec:
|
7
|
+
name: RSpec
|
8
|
+
runs-on: ubuntu-18.04
|
9
|
+
steps:
|
10
|
+
- uses: actions/checkout@v2
|
11
|
+
- uses: actions/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: 2.6.x
|
14
|
+
- name: Setup RSpec
|
15
|
+
run: |
|
16
|
+
gem install bundler
|
17
|
+
[ -f Gemfile ] && bundle --deployment
|
18
|
+
gem install --no-document rspec:'~>3.0'
|
19
|
+
- name: RSpec Report
|
20
|
+
run: rspec --force-color --format documentation
|
data/.gitignore
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
jsonerino (0.1.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.1)
|
10
|
+
diff-lcs (1.4.2)
|
11
|
+
jaro_winkler (1.5.4)
|
12
|
+
parallel (1.19.2)
|
13
|
+
parser (2.7.1.4)
|
14
|
+
ast (~> 2.4.1)
|
15
|
+
rainbow (3.0.0)
|
16
|
+
rake (13.0.1)
|
17
|
+
rexml (3.2.4)
|
18
|
+
rspec (3.9.0)
|
19
|
+
rspec-core (~> 3.9.0)
|
20
|
+
rspec-expectations (~> 3.9.0)
|
21
|
+
rspec-mocks (~> 3.9.0)
|
22
|
+
rspec-core (3.9.2)
|
23
|
+
rspec-support (~> 3.9.3)
|
24
|
+
rspec-expectations (3.9.2)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.9.0)
|
27
|
+
rspec-mocks (3.9.1)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.9.0)
|
30
|
+
rspec-support (3.9.3)
|
31
|
+
rubocop (0.81.0)
|
32
|
+
jaro_winkler (~> 1.5.1)
|
33
|
+
parallel (~> 1.10)
|
34
|
+
parser (>= 2.7.0.1)
|
35
|
+
rainbow (>= 2.2.2, < 4.0)
|
36
|
+
rexml
|
37
|
+
ruby-progressbar (~> 1.7)
|
38
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
39
|
+
ruby-progressbar (1.10.1)
|
40
|
+
unicode-display_width (1.7.0)
|
41
|
+
|
42
|
+
PLATFORMS
|
43
|
+
ruby
|
44
|
+
|
45
|
+
DEPENDENCIES
|
46
|
+
bundler (~> 1.6)
|
47
|
+
jsonerino!
|
48
|
+
rake
|
49
|
+
rspec
|
50
|
+
rubocop (~> 0.81.0)
|
51
|
+
|
52
|
+
BUNDLED WITH
|
53
|
+
1.17.2
|
data/jsonerino.gemspec
CHANGED
@@ -1,25 +1,24 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'jsonerino/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name
|
8
|
-
spec.version
|
9
|
-
spec.authors
|
10
|
-
spec.email
|
11
|
-
spec.summary
|
12
|
-
spec.description
|
13
|
-
spec.homepage
|
14
|
-
spec.license
|
6
|
+
spec.name = 'jsonerino'
|
7
|
+
spec.version = Jsonerino::VERSION
|
8
|
+
spec.authors = ['WinterCore']
|
9
|
+
spec.email = ['hogobbl@gmail.com']
|
10
|
+
spec.summary = 'JSON parser'
|
11
|
+
spec.description = 'JSON parser'
|
12
|
+
spec.homepage = 'https://github.com/WinterCore/microverse-ruby-capstone-json-parser'
|
13
|
+
spec.license = 'MIT'
|
15
14
|
|
16
|
-
spec.files
|
17
|
-
spec.executables
|
18
|
-
spec.test_files
|
19
|
-
spec.require_paths = [
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
20
19
|
|
21
|
-
spec.add_development_dependency
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
21
|
+
spec.add_development_dependency 'rake'
|
22
|
+
spec.add_development_dependency 'rspec'
|
23
|
+
spec.add_development_dependency 'rubocop', '~> 0.81.0'
|
25
24
|
end
|
data/lib/jsonerino/version.rb
CHANGED
@@ -0,0 +1,143 @@
|
|
1
|
+
require_relative '../../lib/jsonerino'
|
2
|
+
|
3
|
+
describe Jsonerino do
|
4
|
+
let(:complex_json_str) do
|
5
|
+
'
|
6
|
+
{
|
7
|
+
"problems": [{
|
8
|
+
"Diabetes":[{
|
9
|
+
"medications":[{
|
10
|
+
"medicationsClasses":[{
|
11
|
+
"className":[{
|
12
|
+
"associatedDrug":[{"name":"asprin", "dose":"", "strength":"500 mg"}],
|
13
|
+
"associatedDrug#2":[{"name":"somethingElse", "dose":"", "strength":"500 mg"}]
|
14
|
+
}],
|
15
|
+
"className2":[{
|
16
|
+
"associatedDrug":[{ "name":"asprin", "dose":"", "strength":"500 mg" }],
|
17
|
+
"associatedDrug#2":[{ "name":"somethingElse", "dose":"", "strength":"500 mg"}]
|
18
|
+
}]
|
19
|
+
}]
|
20
|
+
}],
|
21
|
+
"labs":[{"missing_field": "missing_value"}]
|
22
|
+
}],
|
23
|
+
"Asthma":[{}]
|
24
|
+
}]
|
25
|
+
}
|
26
|
+
'
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:complex_json) do
|
30
|
+
{
|
31
|
+
'problems' => [{
|
32
|
+
'Diabetes' => [{
|
33
|
+
'medications' => [{
|
34
|
+
'medicationsClasses' => [{
|
35
|
+
'className' => [{
|
36
|
+
'associatedDrug' => [{ 'name' => 'asprin', 'dose' => '', 'strength' => '500 mg' }],
|
37
|
+
'associatedDrug#2' => [{ 'name' => 'somethingElse', 'dose' => '', 'strength' => '500 mg' }]
|
38
|
+
}],
|
39
|
+
'className2' => [{
|
40
|
+
'associatedDrug' => [{ 'name' => 'asprin', 'dose' => '', 'strength' => '500 mg' }],
|
41
|
+
'associatedDrug#2' => [{ 'name' => 'somethingElse', 'dose' => '', 'strength' => '500 mg' }]
|
42
|
+
}]
|
43
|
+
}]
|
44
|
+
}],
|
45
|
+
'labs' => [{
|
46
|
+
'missing_field' => 'missing_value'
|
47
|
+
}]
|
48
|
+
}],
|
49
|
+
'Asthma' => [{}]
|
50
|
+
}]
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#parse (complex)' do
|
55
|
+
it 'Should parse empty objects' do
|
56
|
+
expect(Jsonerino.parse('{}')).to eql({})
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'Should parse empty arrays' do
|
60
|
+
expect(Jsonerino.parse('[]')).to eql([])
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'Should parse objects that have values' do
|
64
|
+
str = '
|
65
|
+
{
|
66
|
+
"str" : "bar",
|
67
|
+
"bool" : true,
|
68
|
+
"null" : null,
|
69
|
+
"number" : 11
|
70
|
+
}
|
71
|
+
'
|
72
|
+
expect(Jsonerino.parse(str)).to eql(
|
73
|
+
{
|
74
|
+
'str' => 'bar',
|
75
|
+
'bool' => true,
|
76
|
+
'null' => nil,
|
77
|
+
'number' => 11
|
78
|
+
}
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'Should parse arrays that contain random values' do
|
83
|
+
str = '
|
84
|
+
[
|
85
|
+
true,
|
86
|
+
false,
|
87
|
+
11.5,
|
88
|
+
"string",
|
89
|
+
null
|
90
|
+
]
|
91
|
+
'
|
92
|
+
expect(Jsonerino.parse(str)).to eql(
|
93
|
+
[
|
94
|
+
true,
|
95
|
+
false,
|
96
|
+
11.5,
|
97
|
+
'string',
|
98
|
+
nil
|
99
|
+
]
|
100
|
+
)
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'Should parse complex nested JSON data (pass 1)' do
|
104
|
+
str = '
|
105
|
+
[
|
106
|
+
{"arr" : [1, 2, 3, { "four" : 4 }]},
|
107
|
+
true,
|
108
|
+
[{"a" : "b", "c" : null}, null]
|
109
|
+
]
|
110
|
+
'
|
111
|
+
|
112
|
+
expect(Jsonerino.parse(str)).to eql(
|
113
|
+
[
|
114
|
+
{ 'arr' => [1, 2, 3, { 'four' => 4 }] },
|
115
|
+
true,
|
116
|
+
[{ 'a' => 'b', 'c' => nil }, nil]
|
117
|
+
]
|
118
|
+
)
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'Should parse complex nested JSON data (pass 1)' do
|
122
|
+
str = '
|
123
|
+
[
|
124
|
+
{"arr" : [1, 2, 3, { "four" : 4 }]},
|
125
|
+
true,
|
126
|
+
[{"a" : "b", "c" : null}, null]
|
127
|
+
]
|
128
|
+
'
|
129
|
+
|
130
|
+
expect(Jsonerino.parse(str)).to eql(
|
131
|
+
[
|
132
|
+
{ 'arr' => [1, 2, 3, { 'four' => 4 }] },
|
133
|
+
true,
|
134
|
+
[{ 'a' => 'b', 'c' => nil }, nil]
|
135
|
+
]
|
136
|
+
)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'Should parse complex nested JSON data (pass 2)' do
|
140
|
+
expect(Jsonerino.parse(complex_json_str)).to eql(complex_json)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative '../../lib/jsonerino'
|
2
|
+
require_relative '../../lib/jsonerino/parse_error'
|
3
|
+
|
4
|
+
describe Jsonerino do
|
5
|
+
describe '#parse (exceptions)' do
|
6
|
+
it 'Should throw parse error when invoked on empty strings' do
|
7
|
+
expect { Jsonerino.parse(' ') }.to raise_error(Jsonerino::JsonParseError)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'Should print out the line (row) and character index (column) to indicate where the parse error occurred' do
|
11
|
+
expect { Jsonerino.parse('{"foo" }') }.to raise_error(Jsonerino::JsonParseError, /line 1 column 8/)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'Should print out the unexpected token that caused the error' do
|
15
|
+
expect { Jsonerino.parse('{"foo" }') }.to raise_error(Jsonerino::JsonParseError, /Unexpected token '}'/)
|
16
|
+
expect { Jsonerino.parse('{"foo": : }') }.to raise_error(Jsonerino::JsonParseError, /Unexpected token ':'/)
|
17
|
+
expect { Jsonerino.parse('{"foo": ] }') }.to raise_error(Jsonerino::JsonParseError, /Unexpected token ']'/)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'Should throw end of input error when end of input is reached'\
|
21
|
+
'(happens with unclosed curly brackets/double qutoes/etc.)' do
|
22
|
+
expect { Jsonerino.parse('{"foo }') }
|
23
|
+
.to raise_error(Jsonerino::JsonParseError, /End of data while reading object contents of the JSON data/)
|
24
|
+
expect { Jsonerino.parse('{"foo" ') }
|
25
|
+
.to raise_error(Jsonerino::JsonParseError, /End of data while reading object contents of the JSON data/)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'Should throw runtime error for unsupported characters' do
|
29
|
+
expect { Jsonerino.parse('{"foo": % }') }.to raise_error(RuntimeError, /Unexpected character '%'/)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative '../../lib/jsonerino'
|
2
|
+
|
3
|
+
describe Jsonerino do
|
4
|
+
describe '#parse (primitive)' do
|
5
|
+
it 'Should parse strings properly' do
|
6
|
+
output = Jsonerino.parse '"foo"'
|
7
|
+
expect(output).to eql('foo')
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'Should parse strings that contain escape sequences' do
|
11
|
+
output = Jsonerino.parse "\"foo\n\t\""
|
12
|
+
expect(output).to eql("foo\n\t")
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'Should parse strings that contain unicode escape sequences' do
|
16
|
+
output = Jsonerino.parse "\"foo\u0269\""
|
17
|
+
expect(output).to eql("foo\u0269")
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'Should parse booleans properly' do
|
21
|
+
expect(Jsonerino.parse('true')).to eql(true)
|
22
|
+
expect(Jsonerino.parse('false')).to eql(false)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'Should parse numbers properly' do
|
26
|
+
expect(Jsonerino.parse('1.5e-5')).to eql(1.5e-5)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'Should parse null values properly' do
|
30
|
+
expect(Jsonerino.parse('null')).to eql(nil)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonerino
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- WinterCore
|
@@ -25,21 +25,21 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0
|
33
|
+
version: '0'
|
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: 0
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,20 +53,20 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rubocop
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.81.0
|
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: JSON parser
|
68
|
+
version: 0.81.0
|
69
|
+
description: JSON parser
|
70
70
|
email:
|
71
71
|
- hogobbl@gmail.com
|
72
72
|
executables: []
|
@@ -74,10 +74,12 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- ".github/workflows/linters.yml"
|
77
|
+
- ".github/workflows/tests.yml"
|
77
78
|
- ".gitignore"
|
78
79
|
- ".rspec"
|
79
80
|
- ".rubocop.yml"
|
80
81
|
- Gemfile
|
82
|
+
- Gemfile.lock
|
81
83
|
- README.md
|
82
84
|
- Rakefile
|
83
85
|
- jsonerino.gemspec
|
@@ -89,6 +91,9 @@ files:
|
|
89
91
|
- lib/jsonerino/parser.rb
|
90
92
|
- lib/jsonerino/token.rb
|
91
93
|
- lib/jsonerino/version.rb
|
94
|
+
- spec/jsonerino/complex_values_spec.rb
|
95
|
+
- spec/jsonerino/parse_error_spec.rb
|
96
|
+
- spec/jsonerino/primitive_values_spec.rb
|
92
97
|
- spec/spec_helper.rb
|
93
98
|
homepage: https://github.com/WinterCore/microverse-ruby-capstone-json-parser
|
94
99
|
licenses:
|
@@ -112,6 +117,9 @@ requirements: []
|
|
112
117
|
rubygems_version: 3.0.3
|
113
118
|
signing_key:
|
114
119
|
specification_version: 4
|
115
|
-
summary: JSON parser
|
120
|
+
summary: JSON parser
|
116
121
|
test_files:
|
122
|
+
- spec/jsonerino/complex_values_spec.rb
|
123
|
+
- spec/jsonerino/parse_error_spec.rb
|
124
|
+
- spec/jsonerino/primitive_values_spec.rb
|
117
125
|
- spec/spec_helper.rb
|