import Foundation import PlakCore import Testing @Suite struct PageLinkTests { private let text = "see https://plak.app/a?b=1 and\nmail jo@example.com\nplain words" as NSString @Test("an index inside a web address gives the address and its range") func web() throws { let link = try #require(PageLink.link(in: text, at: 10)) #expect(link.url.absoluteString == "https://plak.app/a?b=1") #expect(link.range == NSRange(location: 4, length: 22)) } @Test("a mail address on a later line is a mailto link") func mail() throws { let link = try #require(PageLink.link(in: text, at: 40)) #expect(link.url.absoluteString == "mailto:jo@example.com") } @Test("an index outside an address, or out of the text, gives no link") func none() { #expect(PageLink.link(in: text, at: 1) == nil) #expect(PageLink.link(in: text, at: text.length - 2) == nil) #expect(PageLink.link(in: text, at: text.length) == nil) #expect(PageLink.link(in: text, at: -1) == nil) } }