import Testing @testable import gitbay @MainActor struct ReadmeBadgeSourceTests { private func rewrite(_ content: String, host: String = "gitbay.org") -> String { ReadmeView.preferringPNGBadges(content, host: host) } @Test func aBadgeOnThisInstancePointsAtThePNG() { #expect(rewrite("[[https://gitbay.org/krz/gitbay/builds][file:https://gitbay.org/krz/gitbay/badge/build.svg]]") == "[[https://gitbay.org/krz/gitbay/builds][file:https://gitbay.org/krz/gitbay/badge/build.png]]") } @Test func aBadgeForAnotherRepoOnTheSameInstanceIsRewritten() { #expect(rewrite("file:https://gitbay.org/krz/orgo/badge/build.svg") == "file:https://gitbay.org/krz/orgo/badge/build.png") } /// Somewhere else's badge has no PNG to offer, so it is left as authored. @Test func aBadgeOnAnotherHostIsLeftAlone() { let shields = "file:https://img.shields.io/badge/build-passing.svg" #expect(rewrite(shields) == shields) } /// Only the badge path is rewritten; an SVG committed to the repo is not a badge. @Test func anSVGThatIsNotABadgeIsLeftAlone() { let diagram = "file:https://gitbay.org/krz/gitbay/raw/HEAD/docs/diagram.svg" #expect(rewrite(diagram) == diagram) } @Test func anEmptyHostRewritesNothing() { let badge = "file:https://gitbay.org/krz/gitbay/badge/build.svg" #expect(rewrite(badge, host: "") == badge) } /// The host is matched literally: its dots are not wildcards. @Test func theHostIsNotTreatedAsAPattern() { let impostor = "file:https://gitbayxorg/krz/gitbay/badge/build.svg" #expect(rewrite(impostor) == impostor) } }