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