blob: 9cf2ccee79d8208eafd24f4fe097cac651ffe225 (
plain)
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
|
import Foundation
import Testing
@testable import NorgKit
struct InlineLinkTests {
@Test func storesKindAndTarget() {
let link = InlineLink(kind: .link, target: "https://example.com")
#expect(link.kind == .link)
#expect(link.target == "https://example.com")
}
@Test func anchorMayHaveNoTarget() {
let anchor = InlineLink(kind: .anchor, target: nil)
#expect(anchor.kind == .anchor)
#expect(anchor.target == nil)
}
@Test func equatableDistinguishesKindAndTarget() {
#expect(InlineLink(kind: .link, target: "a") == InlineLink(kind: .link, target: "a"))
#expect(InlineLink(kind: .link, target: "a") != InlineLink(kind: .anchor, target: "a"))
#expect(InlineLink(kind: .link, target: "a") != InlineLink(kind: .link, target: "b"))
}
@Test func roundTripsThroughJSON() throws {
for link in [InlineLink(kind: .link, target: "x"), InlineLink(kind: .anchor, target: nil)] {
let data = try JSONEncoder().encode(link)
#expect(try JSONDecoder().decode(InlineLink.self, from: data) == link)
}
}
}
|