aboutsummaryrefslogtreecommitdiff
path: root/Tests/NorgKitTests/Models/InlineSpanTests.swift
blob: 24531e494a8a048819d5a30d6bb8a7d14843378c (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
33
34
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)
  }
}