Skip to content

Commit cda2382

Browse files
committed
Add jsonpath-compliance-test-suite tests
1 parent 725f187 commit cda2382

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "test/jsonpath-compliance-test-suite"]
2+
path = test/jsonpath-compliance-test-suite
3+
url = https://github.com/jsonpath-standard/jsonpath-compliance-test-suite.git

test/test_jsonpath_compliance.rb

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# frozen_string_literal: true
2+
3+
require 'minitest/autorun'
4+
require 'jsonpath'
5+
require 'json'
6+
7+
class TestJsonpathCompliance < MiniTest::Unit::TestCase
8+
skipped = [
9+
'whitespace, filter, space between parenthesized expression and bracket',
10+
'whitespace, filter, return between parenthesized expression and bracket',
11+
'filter, group terms, left',
12+
'whitespace, filter, tab between parenthesized expression and bracket'
13+
]
14+
JSON.parse(File.read('test/jsonpath-compliance-test-suite/cts.json')).fetch('tests').each_with_index do |test, index|
15+
name = test['name']
16+
method_name = name.gsub(/[^a-z0-9]+/, '_').sub(/_$/, '')
17+
define_method("test_jsonpath_compliance_#{method_name}") do
18+
skip "#{name} – skipping" if skipped.include?(name)
19+
if test.key?('result')
20+
result = Timeout.timeout(1) do
21+
JsonPath.new(test.fetch('selector')).on(test['document'])
22+
end
23+
assert_equal(test['result'], result, "Test: #{name.inspect}")
24+
elsif test['invalid_selector']
25+
skip "skipping #{name} – invalid_selector #{test.fetch('selector').inspect}"
26+
else
27+
raise "don't know how to test #{name}#{test.inspect}"
28+
end
29+
end
30+
end
31+
end

0 commit comments

Comments
 (0)