The deleted end is mateched to the if

Before

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

After

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

Before

program
call
identifier "require"
argument_list
string
" "'"
string_content "spec_helper"
" "'"
call
identifier "describe"
argument_list
string
" "'"
string_content "Compliance"
" "'"
do_block
do "do"
body_statement
assignment
constant "PARSER"
= "="
call
scope_resolution
constant "JMESPath"
:: "::"
constant "Parser"
. "."
identifier "new"
argument_list
( "("
pair
simple_symbol ":disable_visit_errors"
=> "=>"
true "true"
) ")"
call
call
constant "Dir"
. "."
identifier "glob"
argument_list
( "("
string
" "'"
string_content "spec/compliance/*.json"
" "'"
) ")"
. "."
identifier "each"
do_block
do "do"
block_parameters
| "|"
identifier "path"
| "|"
body_statement
call
identifier "describe"
argument_list (+24 nodes collapsed)
do_block
do "do"
body_statement
call
call
constant "JMESPath"
. "."
identifier "load_json"
argument_list
( "("
identifier "path"
) ")"
. "."
identifier "each"
do_block
do "do"
block_parameters
| "|"
identifier "scenario"
| "|"
body_statement
call
identifier "describe"
argument_list (+21 nodes collapsed)
do_block
do "do"
body_statement
call
element_reference
identifier "scenario"
[ "["
string
" "'"
string_content "cases"
" "'"
] "]"
. "."
identifier "each"
do_block
do "do"
block_parameters
| "|"
identifier "test_case"
| "|"
body_statement
if
if "if"
element_reference
identifier "test_case"
[ "["
string
" "'"
string_content "error"
" "'"
] "]"
then
if
if "if"
call
string_array
%w( "%w["
bare_string
string_content "invalid-type"
bare_string
string_content "invalid-arity"
) "]"
. "."
identifier "include?"
argument_list
( "("
element_reference
identifier "test_case"
[ "["
string
" "'"
string_content "error"
" "'"
] "]"
) ")"
then (+70 nodes collapsed)
else (+179 nodes collapsed)
end "end"
end "end"
end "end"
end "end"
end "end"
end "end"
end "end"
end "end"

After

program
comment "# frozen_string_literal: true"
call
identifier "require"
argument_list
string
" "'"
string_content "spec_helper"
" "'"
call
identifier "describe"
argument_list
string
" "'"
string_content "Compliance"
" "'"
do_block
do "do"
body_statement
assignment
constant "PARSER"
= "="
call
scope_resolution
constant "JMESPath"
:: "::"
constant "Parser"
. "."
identifier "new"
argument_list
( "("
pair
hash_key_symbol "disable_visit_errors"
: ":"
true "true"
) ")"
call
call
constant "Dir"
. "."
identifier "glob"
argument_list
( "("
string
" "'"
string_content "spec/compliance/*.json"
" "'"
) ")"
. "."
identifier "each"
do_block
do "do"
block_parameters
| "|"
identifier "path"
| "|"
body_statement
call
identifier "describe"
argument_list (+24 nodes collapsed)
do_block
do "do"
body_statement
call
call
constant "JMESPath"
. "."
identifier "load_json"
argument_list
( "("
identifier "path"
) ")"
. "."
identifier "each"
do_block
do "do"
block_parameters
| "|"
identifier "scenario"
| "|"
body_statement
call
identifier "describe"
argument_list (+21 nodes collapsed)
do_block
do "do"
body_statement
call
element_reference
identifier "scenario"
[ "["
string
" "'"
string_content "cases"
" "'"
] "]"
. "."
identifier "each"
do_block
do "do"
block_parameters
| "|"
identifier "test_case"
| "|"
body_statement
unless_modifier
next
next "next"
unless "unless"
element_reference
identifier "test_case"
[ "["
string
" "'"
string_content "error"
" "'"
] "]"
if
if "if"
call
string_array
%w( "%w("
bare_string
string_content "invalid-type"
bare_string
string_content "invalid-arity"
) ")"
. "."
identifier "include?"
argument_list
( "("
element_reference
identifier "test_case"
[ "["
string
" "'"
string_content "error"
" "'"
] "]"
) ")"
then (+70 nodes collapsed)
else (+179 nodes collapsed)
end "end"
end "end"
end "end"
end "end"
end "end"
end "end"
end "end"