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