Before

…lines 1–35 unchanged (35 lines)
36 # For the sake of brevity, this is a limited subset of the information found
37 # in release objects in a response from the GitHub API. Some of these objects
38 # are somewhat representative of real world scenarios but others are
39 # contrived examples for the sake of exercising code paths.
40 let(:content) do
41 <<~EOS
42 [
43 {
44 "tag_name": "v1.2.3",
45 "name": "v1.2.3",
46 "draft": false,
47 "prerelease": false
48 },
49 {
50 "tag_name": "no-version-tag-also",
51 "name": "1.2.2",
52 "draft": false,
53 "prerelease": false
54 },
55 {
56 "tag_name": "1.2.1",
57 "name": "No version title",
58 "draft": false,
59 "prerelease": false
60 },
61 {
62 "tag_name": "no-version-tag",
…lines 63–86 unchanged (24 lines)
87 }
88 ]
89 EOS
90 end
91 let(:json) { JSON.parse(content) }
92
93 let(:matches) { ["1.2.3", "1.2.2", "1.2.1"] }
94
95 describe "::match?" do
96 it "returns true for a GitHub release artifact URL" do
97 expect(github_releases.match?(github_urls[:release_asset])).to be true
98 end
99
…lines 100–144 unchanged (45 lines)
145 expect(github_releases.versions_from_content(content, regex) { "1.2.3" }).to eq(["1.2.3"])
146
147 # Returning an array of strings from block
148 expect(github_releases.versions_from_content(content, regex) do |json, regex|
149 json.map do |release|
150 next if release["draft"] || release["prerelease"]
151
152 match = release["tag_name"]&.match(regex)
153 next if match.blank?
154
155 match[1]
156 end
157 end).to eq(["1.2.3", "1.2.1"])
158 end
159
160 it "allows a nil return from a block" do
161 expect(github_releases.versions_from_content(content, regex) { next }).to eq([])
162 end
163
…lines 164–209 unchanged (46 lines)
210 next if match.blank?
211
212 match[1]
213 end
214 end,
215 ).to eq(match_data[:cached].merge({
216 matches: ["1.2.3", "1.2.1"].to_h { |v| [v, Version.new(v)] },
217 regex: brew_regex,
218 }))
219 end
220
221 it "returns default match_data when url is blank" do
222 expect(github_releases.find_versions(url: ""))
…lines 223–232 unchanged (10 lines)

After

…lines 1–35 unchanged (35 lines)
36 # For the sake of brevity, this is a limited subset of the information found
37 # in release objects in a response from the GitHub API. Some of these objects
38 # are somewhat representative of real world scenarios but others are
39 # contrived examples for the sake of exercising code paths.
40 let(:content) do
41 <<~EOS
42 [
43 {
44 "tag_name": "v1.2.3",
45 "name": "v1.2.3",
46 "draft": false,
47 "prerelease": false
48 },
49 {
50 "tag_name": "1.2.2",
51 "name": "No version title",
52 "draft": false,
53 "prerelease": false
54 },
55 {
56 "tag_name": "no-version-tag",
…lines 57–80 unchanged (24 lines)
81 }
82 ]
83 EOS
84 end
85 let(:json) { JSON.parse(content) }
86
87 let(:matches) { ["1.2.3", "1.2.2"] }
88
89 describe "::match?" do
90 it "returns true for a GitHub release artifact URL" do
91 expect(github_releases.match?(github_urls[:release_asset])).to be true
92 end
93
…lines 94–138 unchanged (45 lines)
139 expect(github_releases.versions_from_content(content, regex) { "1.2.3" }).to eq(["1.2.3"])
140
141 # Returning an array of strings from block
142 expect(github_releases.versions_from_content(content, regex) do |json, regex|
143 json.map do |release|
144 next if release["draft"] || release["prerelease"]
145
146 release["tag_name"]&.[](regex, 1)
147 end
148 end).to eq(matches)
149 end
150
151 it "allows a nil return from a block" do
152 expect(github_releases.versions_from_content(content, regex) { next }).to eq([])
153 end
154
…lines 155–200 unchanged (46 lines)
201 next if match.blank?
202
203 match[1]
204 end
205 end,
206 ).to eq(match_data[:cached].merge({
207 matches: ["1.2.3", "1.2.2"].to_h { |v| [v, Version.new(v)] },
208 regex: brew_regex,
209 }))
210 end
211
212 it "returns default match_data when url is blank" do
213 expect(github_releases.find_versions(url: ""))
…lines 214–223 unchanged (10 lines)

Before

program
comment "# frozen_string_literal: true"
call
identifier "require"
argument_list
string
" "\""
string_content "livecheck/strategy"
" "\""
call
constant "RSpec"
. "."
identifier "describe"
argument_list
scope_resolution
scope_resolution
scope_resolution
constant "Homebrew"
:: "::"
constant "Livecheck"
:: "::"
constant "Strategy"
:: "::"
constant "GithubReleases"
do_block
do "do"
body_statement
call
identifier "subject"
argument_list
( "("
simple_symbol ":github_releases"
) ")"
block
{ "{"
block_body
identifier "described_class"
} "}"
call (+53 nodes collapsed)
call
identifier "let"
argument_list
( "("
simple_symbol ":non_github_url"
) ")"
block
{ "{"
block_body
string
" "\""
string_content "https://brew.sh/test"
" "\""
} "}"
call
identifier "let"
argument_list
( "("
simple_symbol ":regex"
) ")"
block
{ "{"
block_body
scope_resolution
identifier "github_releases"
:: "::"
constant "DEFAULT_REGEX"
} "}"
call (+75 nodes collapsed)
comment "# For the sake of brevity, this is a limited subset of the i"...
comment "# in release objects in a response from the GitHub API. Some"...
comment "# are somewhat representative of real world scenarios but ot"...
comment "# contrived examples for the sake of exercising code paths."
call
identifier "let"
argument_list
( "("
simple_symbol ":content"
) ")"
do_block
do "do"
body_statement
heredoc_beginning "<<~EOS"
heredoc_body
heredoc_content "\n [\n {\n \"tag_name\": \"v1.2.3\",\n "...
heredoc_end "EOS"
end "end"
call
identifier "let"
argument_list
( "("
simple_symbol ":json"
) ")"
block
{ "{"
block_body
call
constant "JSON"
. "."
identifier "parse"
argument_list
( "("
identifier "content"
) ")"
} "}"
call
identifier "let"
argument_list
( "("
simple_symbol ":matches"
) ")"
block
{ "{"
block_body
array
[ "["
string
" "\""
string_content "1.2.3"
" "\""
, ","
string
" "\""
string_content "1.2.2"
" "\""
, ","
string
" "\""
string_content "1.2.1"
" "\""
] "]"
} "}"
call (+176 nodes collapsed)
call (+204 nodes collapsed)
call
identifier "describe"
argument_list
string
" "\""
string_content "::versions_from_content"
" "\""
do_block
do "do"
body_statement
call (+70 nodes collapsed)
call (+36 nodes collapsed)
call
identifier "it"
argument_list
string
" "\""
string_content "returns an array of version strings when given content and a"...
" "\""
do_block
do "do"
comment "# Returning a string from block"
body_statement
call (+39 nodes collapsed)
comment "# Returning an array of strings from block"
call
call
identifier "expect"
argument_list
( "("
call
identifier "github_releases"
. "."
identifier "versions_from_content"
argument_list
( "("
identifier "content"
, ","
identifier "regex"
) ")"
do_block
do "do"
block_parameters
| "|"
identifier "json"
, ","
identifier "regex"
| "|"
body_statement
call
identifier "json"
. "."
identifier "map"
do_block
do "do"
block_parameters
| "|"
identifier "release"
| "|"
body_statement
if_modifier (+22 nodes collapsed)
assignment
identifier "match"
= "="
call
element_reference
identifier "release"
[ "["
string
" "\""
string_content "tag_name"
" "\""
] "]"
&. "&."
identifier "match"
argument_list
( "("
identifier "regex"
) ")"
if_modifier
next
next "next"
if "if"
call
identifier "match"
. "."
identifier "blank?"
element_reference
identifier "match"
[ "["
integer "1"
] "]"
end "end"
end "end"
) ")"
. "."
identifier "to"
argument_list
call
identifier "eq"
argument_list
( "("
array
[ "["
string
" "\""
string_content "1.2.3"
" "\""
, ","
string
" "\""
string_content "1.2.1"
" "\""
] "]"
) ")"
end "end"
call (+44 nodes collapsed)
call (+53 nodes collapsed)
end "end"
call
identifier "describe"
argument_list
string
" "\""
string_content "::find_versions"
" "\""
do_block
do "do"
body_statement
call (+125 nodes collapsed)
call
identifier "let"
argument_list
( "("
simple_symbol ":brew_regex"
) ")"
block
{ "{"
block_body
regex
/ "/"
string_content "^v?("
escape_sequence "\\d"
string_content "+(?:"
escape_sequence "\\."
escape_sequence "\\d"
string_content "+)+)$"
/ "/i"
} "}"
call (+71 nodes collapsed)
call
identifier "it"
argument_list
string
" "\""
string_content "finds versions in provided content"
" "\""
do_block
do "do"
body_statement
call (+38 nodes collapsed)
comment "# This `strategy` block is unnecessary but it's intended to "...
comment "# regex in a `strategy` block."
call
call (+106 nodes collapsed)
. "."
identifier "to"
argument_list
call
identifier "eq"
argument_list
( "("
call
element_reference
identifier "match_data"
[ "["
simple_symbol ":cached"
] "]"
. "."
identifier "merge"
argument_list
( "("
hash
{ "{"
pair
hash_key_symbol "matches"
: ":"
call
array
[ "["
string
" "\""
string_content "1.2.3"
" "\""
, ","
string
" "\""
string_content "1.2.1"
" "\""
] "]"
. "."
identifier "to_h"
block (+21 nodes collapsed)
, ","
pair
hash_key_symbol "regex"
: ":"
identifier "brew_regex"
, ","
} "}"
) ")"
) ")"
end "end"
call (+62 nodes collapsed)
call (+52 nodes collapsed)
end "end"
end "end"

After

program
comment "# frozen_string_literal: true"
call
identifier "require"
argument_list
string
" "\""
string_content "livecheck/strategy"
" "\""
call
constant "RSpec"
. "."
identifier "describe"
argument_list
scope_resolution
scope_resolution
scope_resolution
constant "Homebrew"
:: "::"
constant "Livecheck"
:: "::"
constant "Strategy"
:: "::"
constant "GithubReleases"
do_block
do "do"
body_statement
call
identifier "subject"
argument_list
( "("
simple_symbol ":github_releases"
) ")"
block
{ "{"
block_body
identifier "described_class"
} "}"
call (+53 nodes collapsed)
call
identifier "let"
argument_list
( "("
simple_symbol ":non_github_url"
) ")"
block
{ "{"
block_body
string
" "\""
string_content "https://brew.sh/test"
" "\""
} "}"
call
identifier "let"
argument_list
( "("
simple_symbol ":regex"
) ")"
block
{ "{"
block_body
scope_resolution
identifier "github_releases"
:: "::"
constant "DEFAULT_REGEX"
} "}"
call (+75 nodes collapsed)
comment "# For the sake of brevity, this is a limited subset of the i"...
comment "# in release objects in a response from the GitHub API. Some"...
comment "# are somewhat representative of real world scenarios but ot"...
comment "# contrived examples for the sake of exercising code paths."
call
identifier "let"
argument_list
( "("
simple_symbol ":content"
) ")"
do_block
do "do"
body_statement
heredoc_beginning "<<~EOS"
heredoc_body
heredoc_content "\n [\n {\n \"tag_name\": \"v1.2.3\",\n "...
heredoc_end "EOS"
end "end"
call
identifier "let"
argument_list
( "("
simple_symbol ":json"
) ")"
block
{ "{"
block_body
call
constant "JSON"
. "."
identifier "parse"
argument_list
( "("
identifier "content"
) ")"
} "}"
call
identifier "let"
argument_list
( "("
simple_symbol ":matches"
) ")"
block
{ "{"
block_body
array
[ "["
string
" "\""
string_content "1.2.3"
" "\""
, ","
string
" "\""
string_content "1.2.2"
" "\""
] "]"
} "}"
call (+176 nodes collapsed)
call (+204 nodes collapsed)
call
identifier "describe"
argument_list
string
" "\""
string_content "::versions_from_content"
" "\""
do_block
do "do"
body_statement
call (+70 nodes collapsed)
call (+36 nodes collapsed)
call
identifier "it"
argument_list
string
" "\""
string_content "returns an array of version strings when given content and a"...
" "\""
do_block
do "do"
comment "# Returning a string from block"
body_statement
call (+39 nodes collapsed)
comment "# Returning an array of strings from block"
call
call
identifier "expect"
argument_list
( "("
call
identifier "github_releases"
. "."
identifier "versions_from_content"
argument_list
( "("
identifier "content"
, ","
identifier "regex"
) ")"
do_block
do "do"
block_parameters
| "|"
identifier "json"
, ","
identifier "regex"
| "|"
body_statement
call
identifier "json"
. "."
identifier "map"
do_block
do "do"
block_parameters
| "|"
identifier "release"
| "|"
body_statement
if_modifier (+22 nodes collapsed)
call
element_reference
identifier "release"
[ "["
string
" "\""
string_content "tag_name"
" "\""
] "]"
&. "&."
operator
[] "[]"
argument_list
( "("
identifier "regex"
, ","
integer "1"
) ")"
end "end"
end "end"
) ")"
. "."
identifier "to"
argument_list
call
identifier "eq"
argument_list
( "("
identifier "matches"
) ")"
end "end"
call (+44 nodes collapsed)
call (+53 nodes collapsed)
end "end"
call
identifier "describe"
argument_list
string
" "\""
string_content "::find_versions"
" "\""
do_block
do "do"
body_statement
call (+125 nodes collapsed)
call
identifier "let"
argument_list
( "("
simple_symbol ":brew_regex"
) ")"
block
{ "{"
block_body
regex
/ "/"
string_content "^v?("
escape_sequence "\\d"
string_content "+(?:"
escape_sequence "\\."
escape_sequence "\\d"
string_content "+)+)$"
/ "/i"
} "}"
call (+71 nodes collapsed)
call
identifier "it"
argument_list
string
" "\""
string_content "finds versions in provided content"
" "\""
do_block
do "do"
body_statement
call (+38 nodes collapsed)
comment "# This `strategy` block is unnecessary but it's intended to "...
comment "# regex in a `strategy` block."
call
call (+106 nodes collapsed)
. "."
identifier "to"
argument_list
call
identifier "eq"
argument_list
( "("
call
element_reference
identifier "match_data"
[ "["
simple_symbol ":cached"
] "]"
. "."
identifier "merge"
argument_list
( "("
hash
{ "{"
pair
hash_key_symbol "matches"
: ":"
call
array
[ "["
string
" "\""
string_content "1.2.3"
" "\""
, ","
string
" "\""
string_content "1.2.2"
" "\""
] "]"
. "."
identifier "to_h"
block (+21 nodes collapsed)
, ","
pair
hash_key_symbol "regex"
: ":"
identifier "brew_regex"
, ","
} "}"
) ")"
) ")"
end "end"
call (+62 nodes collapsed)
call (+52 nodes collapsed)
end "end"
end "end"