Skip to content

Commit 0709758

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

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-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

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

0 commit comments

Comments
 (0)