krz/hutch

an ios client for sourcehut

clone: git clone https://gitbay.org/krz/hutch.git

main: HutchTests/ManPageCatalogTests.swift · raw

 1import Foundation
 2import Testing
 3@testable import Hutch
 4
 5@MainActor
 6struct ManPageCatalogTests {
 7    @Test
 8    func loadsBundledCatalog() {
 9        let entries = ManPageCatalog.load()
10        #expect(!entries.isEmpty)
11        #expect(entries.contains { $0.title == "git.sr.ht" })
12        #expect(entries.allSatisfy { $0.url.scheme == "https" })
13    }
14
15    @Test
16    func fallsBackWhenResourceMissing() {
17        // Foundation's own bundle has no man-pages.json, so this exercises the
18        // fallback path rather than the bundled resource.
19        let entries = ManPageCatalog.load(bundle: Bundle(for: JSONDecoder.self))
20        #expect(entries == ManPageCatalog.fallback)
21    }
22
23    @Test
24    func decodesCatalogJSON() throws {
25        let json = """
26        [
27          { "title": "git.sr.ht", "url": "https://man.sr.ht/git.sr.ht/" },
28          { "title": "srht.site", "url": "https://srht.site/" }
29        ]
30        """
31        let entries = try JSONDecoder().decode([ManPageCatalogEntry].self, from: Data(json.utf8))
32        #expect(entries.count == 2)
33        #expect(entries.first?.title == "git.sr.ht")
34        #expect(entries.first?.url == URL(string: "https://man.sr.ht/git.sr.ht/"))
35    }
36}