aboutsummaryrefslogtreecommitdiff
path: root/Tests/NorgUITests/NorgLinkURLTests.swift
blob: dcd54466c10a1686708020c6cf7c703994141c45 (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
import Foundation
import NorgKit
import Testing

@testable import NorgUI

@Suite struct NorgLinkURLTests {
  @Test func roundTripsLink() throws {
    let link = InlineLink(kind: .link, target: "* My Heading")
    let url = try #require(NorgLinkURL.encode(link))
    #expect(NorgLinkURL.decode(url) == link)
  }

  @Test func roundTripsAnchor() throws {
    let link = InlineLink(kind: .anchor, target: "some anchor")
    let url = try #require(NorgLinkURL.encode(link))
    #expect(NorgLinkURL.decode(url) == link)
  }

  @Test func roundTripsMissingTarget() throws {
    let link = InlineLink(kind: .link, target: nil)
    let url = try #require(NorgLinkURL.encode(link))
    #expect(NorgLinkURL.decode(url) == link)
  }

  @Test func ignoresForeignURLs() throws {
    let url = try #require(URL(string: "https://example.com"))
    #expect(NorgLinkURL.decode(url) == nil)
  }
}