import Foundation import Testing @testable import EquipoShareCore @Test func providerTextSupportsUTF8AndBOMUTF16WithinMessageBound() throws { let value = "The sign-in button is cut off. 📷" for encoding in [String.Encoding.utf8, .utf16] { #expect(try ShareText.decode(Data(value.data(using: encoding)!)) == value) } let archive = try NSKeyedArchiver.archivedData(withRootObject: value as NSString, requiringSecureCoding: true) #expect(try ShareText.decode(archive) == value) let longArchive = try NSKeyedArchiver.archivedData(withRootObject: String(repeating: "x", count: 16385) as NSString, requiringSecureCoding: true) #expect(throws: AttachmentFailure.tooLarge) { try ShareText.decode(longArchive) } #expect(throws: AttachmentFailure.tooLarge) { try ShareText.decode(Data(repeating: 65, count: 32771)) } let nonString = try NSKeyedArchiver.archivedData(withRootObject: Data([1, 2, 3]) as NSData, requiringSecureCoding: true) #expect(throws: AttachmentFailure.type) { try ShareText.decode(nonString) } #expect(throws: AttachmentFailure.tooLarge) { try ShareText.decode(Data(String(repeating: "x", count: 16 * 1024 + 1).utf8)) } #expect(throws: AttachmentFailure.type) { try ShareText.decode(Data([0xff, 0xff, 0xff])) } }