mirror of
https://github.com/apple/swift-nio-imap
synced 2026-11-27 05:04:23 +00:00
* Fix documentation * Remove link to NIO http 2 * Document TooDeep error * Remove ParsingError * Make GrammarParser non-public * Better UTF7 errors * Document Access * Document CommandStream types * Partially document `Command` * Document date * Document Access * Update Sources/NIOIMAPCore/Grammar/Date/Date.swift Co-authored-by: George Barnett <gbarnett@apple.com> * Update Sources/NIOIMAPCore/Grammar/Access.swift Co-authored-by: George Barnett <gbarnett@apple.com> * Update Sources/NIOIMAPCore/Grammar/Command/CommandStream.swift Co-authored-by: George Barnett <gbarnett@apple.com> * Fix typo Co-authored-by: George Barnett <gbarnett@apple.com>
82 lines
2.9 KiB
Swift
82 lines
2.9 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the SwiftNIO open source project
|
|
//
|
|
// Copyright (c) 2020 Apple Inc. and the SwiftNIO project authors
|
|
// Licensed under Apache License v2.0
|
|
//
|
|
// See LICENSE.txt for license information
|
|
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import NIO
|
|
@testable import NIOIMAPCore
|
|
import XCTest
|
|
|
|
class ModifiedUTF7_Tests: XCTestCase {}
|
|
|
|
extension ModifiedUTF7_Tests {
|
|
func testEncode() {
|
|
let inputs: [(String, String, UInt)] = [
|
|
("", "", #line),
|
|
("abc", "abc", #line),
|
|
("&", "&-", #line),
|
|
("ab&12", "ab&-12", #line),
|
|
("mail/€/£", "mail/&IKw-/&AKM-", #line),
|
|
("Répertoire", "R&AOk-pertoire", #line),
|
|
("パリ", "&MNEw6g-", #line),
|
|
("雑件", "<FO9g-", #line),
|
|
("🏣🏣", "&2Dzf49g83+M-", #line),
|
|
("🧑🏽🦳", "&2D7d0dg83,0gDdg+3bM-", #line),
|
|
("a/b/c", "a/b/c", #line),
|
|
(#"a\b\c"#, #"a\b\c"#, #line),
|
|
("a+b", "a+b", #line),
|
|
("~ab", "~ab", #line),
|
|
]
|
|
for (input, expected, line) in inputs {
|
|
let actual = ModifiedUTF7.encode(input)
|
|
XCTAssertEqual(expected, String(buffer: actual), line: line)
|
|
}
|
|
}
|
|
|
|
func testDecode() {
|
|
let inputs: [(String, String, UInt)] = [
|
|
("", "", #line),
|
|
("abc", "abc", #line),
|
|
("&-", "&", #line),
|
|
("ab&-12", "ab&12", #line),
|
|
("mail/&IKw-/&AKM-", "mail/€/£", #line),
|
|
("R&AOk-pertoire", "Répertoire", #line),
|
|
("&MNEw6g-", "パリ", #line),
|
|
("<FO9g-", "雑件", #line),
|
|
("&2Dzf49g83+M-", "🏣🏣", #line),
|
|
("&2D7d0dg83,0gDdg+3bM-", "🧑🏽🦳", #line),
|
|
("a/b/c", "a/b/c", #line),
|
|
(#"a\b\c"#, #"a\b\c"#, #line),
|
|
("a+b", "a+b", #line),
|
|
("~ab", "~ab", #line),
|
|
]
|
|
for (input, expected, line) in inputs {
|
|
XCTAssertNoThrow(XCTAssertEqual(expected, try ModifiedUTF7.decode(ByteBuffer(string: input)), line: line), line: line)
|
|
}
|
|
}
|
|
|
|
func testDecode_error() {
|
|
XCTAssertThrowsError(try ModifiedUTF7.decode(ByteBuffer(string: "&aa==-"))) { e in
|
|
XCTAssertTrue(e is ModifiedUTF7.OddByteCountError)
|
|
}
|
|
}
|
|
|
|
func testValidate() {
|
|
XCTAssertNoThrow(try ModifiedUTF7.validate("a"))
|
|
XCTAssertNoThrow(try ModifiedUTF7.validate("a/b/c"))
|
|
XCTAssertNoThrow(try ModifiedUTF7.validate("&2Dzf49g83+M-"))
|
|
XCTAssertNoThrow(try ModifiedUTF7.validate("<FO9g-"))
|
|
XCTAssertThrowsError(try ModifiedUTF7.validate("&Jjo!"))
|
|
XCTAssertThrowsError(try ModifiedUTF7.validate("&U,BTFw-&ZeVnLIqe-"))
|
|
}
|
|
}
|