40 lines
1.4 KiB
Swift
40 lines
1.4 KiB
Swift
import Foundation
|
|
import PlakCore
|
|
import Testing
|
|
|
|
@Suite struct URLCommandTests {
|
|
private func command(_ string: String) throws -> URLCommand? {
|
|
URLCommand(try #require(URL(string: string)))
|
|
}
|
|
|
|
@Test("append takes the percent-decoded text; a + stays a +")
|
|
func append() throws {
|
|
#expect(try command("plak://append?text=hello%20world") == .append("hello world"))
|
|
#expect(try command("plak://append?text=1+1") == .append("1+1"))
|
|
#expect(try command("PLAK://append?text=a") == .append("a"))
|
|
}
|
|
|
|
@Test("append keeps newlines and unicode")
|
|
func appendMultiline() throws {
|
|
#expect(try command("plak://append?text=one%0Atwo%0A%0Ad%C3%A9j%C3%A0%20%F0%9F%93%8B") == .append("one\ntwo\n\ndéjà 📋"))
|
|
}
|
|
|
|
@Test("append without text, or with an empty one, appends the empty text")
|
|
func appendWithoutText() throws {
|
|
#expect(try command("plak://append") == .append(""))
|
|
#expect(try command("plak://append?text=") == .append(""))
|
|
}
|
|
|
|
@Test("paste appends the pasteboard")
|
|
func paste() throws {
|
|
#expect(try command("plak://paste") == .paste)
|
|
}
|
|
|
|
@Test("an unknown host or another scheme is no command")
|
|
func unknown() throws {
|
|
#expect(try command("plak://delete") == nil)
|
|
#expect(try command("plak:") == nil)
|
|
#expect(try command("https://append?text=a") == nil)
|
|
}
|
|
}
|