36 lines
1.2 KiB
Swift
36 lines
1.2 KiB
Swift
import Foundation
|
|
import HelderCore
|
|
import Testing
|
|
|
|
@Suite struct PlakTests {
|
|
private func query(_ text: String) -> String? {
|
|
Plak.appendURL(text)?.absoluteString.replacingOccurrences(of: "plak://append?text=", with: "")
|
|
}
|
|
|
|
@Test func spacesAndNewlinesArePercentEncoded() {
|
|
#expect(query("a b\nc") == "a%20b%0Ac")
|
|
}
|
|
|
|
@Test func ampersandPlusAndHashAreEncoded() {
|
|
#expect(query("a&b+c#d") == "a%26b%2Bc%23d")
|
|
}
|
|
|
|
@Test func theURLTargetsAppend() {
|
|
#expect(Plak.appendURL("x")?.absoluteString == "plak://append?text=x")
|
|
#expect(Plak.pasteURL.absoluteString == "plak://paste")
|
|
}
|
|
|
|
@Test func shortTextIsAppended() {
|
|
#expect(Plak.delivery(for: "hi") == .append(URL(string: "plak://append?text=hi")!))
|
|
#expect(Plak.delivery(for: String(repeating: "a", count: Plak.appendLimit)) != .paste)
|
|
}
|
|
|
|
@Test func textOverTheLimitGoesThroughThePasteboard() {
|
|
#expect(Plak.delivery(for: String(repeating: "a", count: Plak.appendLimit + 1)) == .paste)
|
|
}
|
|
|
|
@Test func theLimitCountsUTF8Bytes() {
|
|
#expect(Plak.delivery(for: String(repeating: "é", count: Plak.appendLimit / 2 + 1)) == .paste)
|
|
}
|
|
}
|