diff options
Diffstat (limited to 'Tests/NorgKitTests/Models/InlineSpanTests.swift')
| -rw-r--r-- | Tests/NorgKitTests/Models/InlineSpanTests.swift | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Tests/NorgKitTests/Models/InlineSpanTests.swift b/Tests/NorgKitTests/Models/InlineSpanTests.swift new file mode 100644 index 0000000..24531e4 --- /dev/null +++ b/Tests/NorgKitTests/Models/InlineSpanTests.swift @@ -0,0 +1,35 @@ +import Foundation +import Testing + +@testable import NorgKit + +struct InlineSpanTests { + + @Test func defaultsToNoStyleAndNoLink() { + let span = InlineSpan(text: "hi") + #expect(span.styles.isEmpty) + #expect(span.link == nil) + } + + @Test func storesStyleAndLink() { + let link = InlineLink(kind: .link, target: "https://example.com") + let span = InlineSpan(text: "hi", styles: .bold, link: link) + #expect(span.styles.contains(.bold)) + #expect(span.link == link) + } + + @Test func equatableDistinguishesFields() { + #expect(InlineSpan(text: "a") == InlineSpan(text: "a")) + #expect(InlineSpan(text: "a") != InlineSpan(text: "b")) + #expect(InlineSpan(text: "a", styles: .bold) != InlineSpan(text: "a")) + } + + @Test func roundTripsThroughJSON() throws { + let span = InlineSpan( + text: "hi", styles: [.bold, .italic], + link: InlineLink(kind: .anchor, target: nil) + ) + let data = try JSONEncoder().encode(span) + #expect(try JSONDecoder().decode(InlineSpan.self, from: data) == span) + } +} |