Skip to content

Commit

Permalink
add spec
Browse files Browse the repository at this point in the history
  • Loading branch information
uvlad7 committed Dec 26, 2024
1 parent 76adeaf commit f9c9f78
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions spec/json_scanner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@
)
end

it "works with max path len correctly" do
expect(
described_class.scan('{"a": [1]}', [[], ["a"]]),
).to eq(
[[[0, 10, :object]], [[6, 9, :array]]],
)
expect(
described_class.scan('{"a": {"b": 1}}', [[], ["a"]]),
).to eq(
[[[0, 15, :object]], [[6, 14, :object]]],
)
expect(described_class.scan('{"a": 1}', [[]])).to eq([[[0, 8, :object]]])
expect(described_class.scan("[[1]]", [[]])).to eq([[[0, 5, :array]]])
expect(described_class.scan("[[1]]", [[0]])).to eq([[[1, 4, :array]]])
end

it "raises on invalid json" do
expect do
begin
Expand Down Expand Up @@ -145,5 +161,10 @@
).to eq(
[[[26, 27, :number]]],
)
expect(
described_class.scan('[{"a": /* comment */ 1}]_________', [[]], { allow_comments: true, allow_trailing_garbage: true }),
).to eq(
[[[0, 24, :array]]],
)
end
end

0 comments on commit f9c9f78

Please sign in to comment.