-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GIT_REMOTE_PATTERNS regexes are being overly greedy (#4132)
* GIT_REMOTE_PATTERNS regexes are being overly greedy With given remote url: “https://github.com/foo/bar.cr.git” - Before: {repo: “bar”} - Now: {repo: “bar.cr”} * Add specs for Crystal::Doc::Generator::GIT_REMOTE_PATTERNS
- Loading branch information
Showing
2 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require "../../../spec_helper" | ||
|
||
private def assert_matches_pattern(url, **options) | ||
match = Crystal::Doc::Generator::GIT_REMOTE_PATTERNS.each_key.compact_map(&.match(url)).first? | ||
if match | ||
options.each { |k, v| match[k.to_s].should eq(v) } | ||
end | ||
end | ||
|
||
describe Crystal::Doc::Generator do | ||
describe "GIT_REMOTE_PATTERNS" do | ||
it "matches github repos" do | ||
assert_matches_pattern "https://www.github.com/foo/bar", user: "foo", repo: "bar" | ||
assert_matches_pattern "http://www.github.com/foo/bar", user: "foo", repo: "bar" | ||
assert_matches_pattern "http://github.com/foo/bar", user: "foo", repo: "bar" | ||
|
||
assert_matches_pattern "https://github.com/foo/bar", user: "foo", repo: "bar" | ||
assert_matches_pattern "https://github.com/foo/bar.git", user: "foo", repo: "bar" | ||
assert_matches_pattern "https://github.com/foo/bar.cr", user: "foo", repo: "bar.cr" | ||
assert_matches_pattern "https://github.com/foo/bar.cr.git", user: "foo", repo: "bar.cr" | ||
|
||
assert_matches_pattern "https://github.com/fOO-Bar/w00den-baRK.ab.cd", user: "fOO-Bar", repo: "w00den-baRK.ab.cd" | ||
assert_matches_pattern "https://github.com/fOO-Bar/w00den-baRK.ab.cd.git", user: "fOO-Bar", repo: "w00den-baRK.ab.cd" | ||
assert_matches_pattern "https://github.com/foo_bar/_baz-buzz.cx", user: "foo_bar", repo: "_baz-buzz.cx" | ||
end | ||
|
||
it "matches gitlab repos" do | ||
assert_matches_pattern "https://www.gitlab.com/foo/bar", user: "foo", repo: "bar" | ||
assert_matches_pattern "http://www.gitlab.com/foo/bar", user: "foo", repo: "bar" | ||
assert_matches_pattern "http://gitlab.com/foo/bar", user: "foo", repo: "bar" | ||
|
||
assert_matches_pattern "https://gitlab.com/foo/bar", user: "foo", repo: "bar" | ||
assert_matches_pattern "https://gitlab.com/foo/bar.git", user: "foo", repo: "bar" | ||
assert_matches_pattern "https://gitlab.com/foo/bar.cr", user: "foo", repo: "bar.cr" | ||
assert_matches_pattern "https://gitlab.com/foo/bar.cr.git", user: "foo", repo: "bar.cr" | ||
|
||
assert_matches_pattern "https://gitlab.com/fOO-Bar/w00den-baRK.ab.cd", user: "fOO-Bar", repo: "w00den-baRK.ab.cd" | ||
assert_matches_pattern "https://gitlab.com/fOO-Bar/w00den-baRK.ab.cd.git", user: "fOO-Bar", repo: "w00den-baRK.ab.cd" | ||
assert_matches_pattern "https://gitlab.com/foo_bar/_baz-buzz.cx", user: "foo_bar", repo: "_baz-buzz.cx" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters