1# frozen_string_literal: true
2require 'spec_helper'
3
4describe 'Compliance' do
5 PARSER = JMESPath::Parser.new(disable_visit_errors: true)
6 Dir.glob('spec/compliance/*.json').each do |path|
7 describe(File.basename(path).split('.').first) do
8 JMESPath.load_json(path).each do |scenario|
9 describe("Given #{scenario['given'].inspect}") do
10 scenario['cases'].each do |test_case|
11 next unless test_case['error']
12
13 if %w(invalid-type invalid-arity).include?(test_case['error'])
14 it "the expression #{test_case['expression'].inspect} returns nil if disable_visit_errors is true" do
15 result = PARSER.parse(test_case['expression']).visit(scenario['given'])
16 expect(result).to be_nil
17 end
18 else
19 it "the expression #{test_case['expression'].inspect} raises a #{test_case['error']} error when parsing even if disable_visit_errors is true" do
20 error_class = case test_case['error']
21 when 'syntax' then JMESPath::Errors::SyntaxError
22 when 'invalid-value' then JMESPath::Errors::InvalidValueError
23 when 'unknown-function' then JMESPath::Errors::UnknownFunctionError
24 else raise "unhandled error type #{test_case['error']}"
25 end
26
27 raised = nil
28 begin
29 PARSER.parse(test_case['expression'])
30 rescue JMESPath::Errors::Error => error
31 raised = error
32 end
33
34 expect(raised).to be_kind_of(error_class)
35 end
36 end
37 end
38 end
39 end
40 end
41 end
42end
43