gitbayTests/ReadmeBadgeTests.swift
43 lines · 1702 bytes
8 symbols in this file
1import Testing
2@testable import gitbay
3
4@MainActor
5struct ReadmeBadgeSourceTests {
6
7 private func rewrite(_ content: String, host: String = "gitbay.org") -> String {
8 ReadmeView.preferringPNGBadges(content, host: host)
9 }
10
11 @Test func aBadgeOnThisInstancePointsAtThePNG() {
12 #expect(rewrite("[[https://gitbay.org/krz/gitbay/builds][file:https://gitbay.org/krz/gitbay/badge/build.svg]]")
13 == "[[https://gitbay.org/krz/gitbay/builds][file:https://gitbay.org/krz/gitbay/badge/build.png]]")
14 }
15
16 @Test func aBadgeForAnotherRepoOnTheSameInstanceIsRewritten() {
17 #expect(rewrite("file:https://gitbay.org/krz/orgo/badge/build.svg")
18 == "file:https://gitbay.org/krz/orgo/badge/build.png")
19 }
20
21 /// Somewhere else's badge has no PNG to offer, so it is left as authored.
22 @Test func aBadgeOnAnotherHostIsLeftAlone() {
23 let shields = "file:https://img.shields.io/badge/build-passing.svg"
24 #expect(rewrite(shields) == shields)
25 }
26
27 /// Only the badge path is rewritten; an SVG committed to the repo is not a badge.
28 @Test func anSVGThatIsNotABadgeIsLeftAlone() {
29 let diagram = "file:https://gitbay.org/krz/gitbay/raw/HEAD/docs/diagram.svg"
30 #expect(rewrite(diagram) == diagram)
31 }
32
33 @Test func anEmptyHostRewritesNothing() {
34 let badge = "file:https://gitbay.org/krz/gitbay/badge/build.svg"
35 #expect(rewrite(badge, host: "") == badge)
36 }
37
38 /// The host is matched literally: its dots are not wildcards.
39 @Test func theHostIsNotTreatedAsAPattern() {
40 let impostor = "file:https://gitbayxorg/krz/gitbay/badge/build.svg"
41 #expect(rewrite(impostor) == impostor)
42 }
43}