Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add jsonpath-compliance-test-suite tests #174

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "test/jsonpath-compliance-test-suite"]
path = test/jsonpath-compliance-test-suite
url = https://github.com/jsonpath-standard/jsonpath-compliance-test-suite.git
1 change: 1 addition & 0 deletions test/jsonpath-compliance-test-suite
31 changes: 31 additions & 0 deletions test/test_jsonpath_compliance.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require 'minitest/autorun'
require 'jsonpath'
require 'json'

class TestJsonpathCompliance < MiniTest::Unit::TestCase
skipped = [
'whitespace, filter, space between parenthesized expression and bracket',
'whitespace, filter, return between parenthesized expression and bracket',
'filter, group terms, left',
'whitespace, filter, tab between parenthesized expression and bracket'
]
JSON.parse(File.read('test/jsonpath-compliance-test-suite/cts.json')).fetch('tests').each_with_index do |test, index|
name = test['name']
method_name = name.gsub(/[^a-z0-9]+/, '_').sub(/_$/, '')
define_method("test_jsonpath_compliance_#{method_name}") do
skip "#{name} – skipping" if skipped.include?(name)
if test.key?('result')
result = Timeout.timeout(1) do
JsonPath.new(test.fetch('selector')).on(test['document'])
end
assert_equal(test['result'], result, "Test: #{name.inspect}")
elsif test['invalid_selector']
skip "skipping #{name} – invalid_selector #{test.fetch('selector').inspect}"
else
raise "don't know how to test #{name} – #{test.inspect}"
end
end
end
end