Skip to content

Commit f547b80

Browse files
committed
Add jsonchecker suite
1 parent 5db7ea3 commit f547b80

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/test_jsonchecker.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
5+
# jsonchecker suite. originally from
6+
# http://json.org/JSON_checker/
7+
class TestJsonchecker < Minitest::Test
8+
Dir["#{DATA_DIR}/jsonchecker/*.json"].each do |filename|
9+
name = File.basename(filename, ".json").gsub(/_EXCLUDE\z/, "")
10+
exclude = filename.end_with?("_EXCLUDE.json")
11+
12+
define_method(:"test_#{name}") do
13+
original_json = File.read(filename)
14+
if name.start_with?("fail") && !exclude
15+
ex = assert_raises RapidJSON::ParseError do
16+
RapidJSON.parse(original_json)
17+
end
18+
re = /JSON parse error: .* \(\d+\)\z/
19+
assert_match re, ex.message
20+
else
21+
assert RapidJSON.parse(original_json)
22+
end
23+
end
24+
end
25+
end

0 commit comments

Comments
 (0)