|
| 1 | +require "../../../spec_helper" |
| 2 | + |
| 3 | +private def assert_matches_pattern(url, **options) |
| 4 | + match = Crystal::Doc::Generator::GIT_REMOTE_PATTERNS.each_key.compact_map(&.match(url)).first? |
| 5 | + if match |
| 6 | + options.each { |k, v| match[k.to_s].should eq(v) } |
| 7 | + end |
| 8 | +end |
| 9 | + |
| 10 | +describe Crystal::Doc::Generator do |
| 11 | + describe "GIT_REMOTE_PATTERNS" do |
| 12 | + it "matches github repos" do |
| 13 | + assert_matches_pattern "https://www.github.com/foo/bar", user: "foo", repo: "bar" |
| 14 | + assert_matches_pattern "http://www.github.com/foo/bar", user: "foo", repo: "bar" |
| 15 | + assert_matches_pattern "http://github.com/foo/bar", user: "foo", repo: "bar" |
| 16 | + |
| 17 | + assert_matches_pattern "https://github.com/foo/bar", user: "foo", repo: "bar" |
| 18 | + assert_matches_pattern "https://github.com/foo/bar.git", user: "foo", repo: "bar" |
| 19 | + assert_matches_pattern "https://github.com/foo/bar.cr", user: "foo", repo: "bar.cr" |
| 20 | + assert_matches_pattern "https://github.com/foo/bar.cr.git", user: "foo", repo: "bar.cr" |
| 21 | + |
| 22 | + assert_matches_pattern "https://github.com/fOO-Bar/w00den-baRK.ab.cd", user: "fOO-Bar", repo: "w00den-baRK.ab.cd" |
| 23 | + assert_matches_pattern "https://github.com/fOO-Bar/w00den-baRK.ab.cd.git", user: "fOO-Bar", repo: "w00den-baRK.ab.cd" |
| 24 | + assert_matches_pattern "https://github.com/foo_bar/_baz-buzz.cx", user: "foo_bar", repo: "_baz-buzz.cx" |
| 25 | + end |
| 26 | + |
| 27 | + it "matches gitlab repos" do |
| 28 | + assert_matches_pattern "https://www.gitlab.com/foo/bar", user: "foo", repo: "bar" |
| 29 | + assert_matches_pattern "http://www.gitlab.com/foo/bar", user: "foo", repo: "bar" |
| 30 | + assert_matches_pattern "http://gitlab.com/foo/bar", user: "foo", repo: "bar" |
| 31 | + |
| 32 | + assert_matches_pattern "https://gitlab.com/foo/bar", user: "foo", repo: "bar" |
| 33 | + assert_matches_pattern "https://gitlab.com/foo/bar.git", user: "foo", repo: "bar" |
| 34 | + assert_matches_pattern "https://gitlab.com/foo/bar.cr", user: "foo", repo: "bar.cr" |
| 35 | + assert_matches_pattern "https://gitlab.com/foo/bar.cr.git", user: "foo", repo: "bar.cr" |
| 36 | + |
| 37 | + assert_matches_pattern "https://gitlab.com/fOO-Bar/w00den-baRK.ab.cd", user: "fOO-Bar", repo: "w00den-baRK.ab.cd" |
| 38 | + assert_matches_pattern "https://gitlab.com/fOO-Bar/w00den-baRK.ab.cd.git", user: "fOO-Bar", repo: "w00den-baRK.ab.cd" |
| 39 | + assert_matches_pattern "https://gitlab.com/foo_bar/_baz-buzz.cx", user: "foo_bar", repo: "_baz-buzz.cx" |
| 40 | + end |
| 41 | + end |
| 42 | +end |
0 commit comments