aboutsummaryrefslogtreecommitdiff
path: root/Tests/NorgKitTests/Models/InlineLinkTests.swift
diff options
context:
space:
mode:
Diffstat (limited to 'Tests/NorgKitTests/Models/InlineLinkTests.swift')
-rw-r--r--Tests/NorgKitTests/Models/InlineLinkTests.swift32
1 files changed, 32 insertions, 0 deletions
diff --git a/Tests/NorgKitTests/Models/InlineLinkTests.swift b/Tests/NorgKitTests/Models/InlineLinkTests.swift
new file mode 100644
index 0000000..9cf2cce
--- /dev/null
+++ b/Tests/NorgKitTests/Models/InlineLinkTests.swift
@@ -0,0 +1,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)
+ }
+ }
+}