Files
swift-nio-imap/Tests/NIOIMAPCoreTests/ModifiedUTF7+Tests.swift
David EvansandGeorge Barnett 78b55555bf Add some documentation (#341)
* 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>
2020-10-26 09:54:46 +00:00

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),
("雑件", "&ltFO9g-", #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),
("&ltFO9g-", "雑件", #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("&ltFO9g-"))
XCTAssertThrowsError(try ModifiedUTF7.validate("&Jjo!"))
XCTAssertThrowsError(try ModifiedUTF7.validate("&U,BTFw-&ZeVnLIqe-"))
}
}