Files
swift-nio-imap/Tests/NIOIMAPCoreTests/Parser/CommandParser+Tests.swift
T
David Evans 2599f0d94d Re-add BodyStructureTests (#250)
* Re-add tests

* Uncomment tests

* Fix sanity

* Refactor Body Field Language

* Add humungous example

* Fix sanity

* Remove unused extension (PR review nit)
2020-07-06 22:44:28 +01:00

67 lines
2.1 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 CommandParser_Tests: XCTestCase {}
// MARK: - init
extension CommandParser_Tests {
func testInit_defaultBufferSize() {
let parser = CommandParser()
XCTAssertEqual(parser.bufferLimit, 1_000)
}
func testInit_customBufferSize() {
let parser = CommandParser(bufferLimit: 80_000)
XCTAssertEqual(parser.bufferLimit, 80_000)
}
}
// MARK: - Test normal usage
extension CommandParser_Tests {
func testNormalUsage() {
var input = ByteBuffer("")
var parser = CommandParser()
XCTAssertNoThrow(XCTAssertNil(try parser.parseCommandStream(buffer: &input)))
input = "1 NOOP\r\n"
XCTAssertNoThrow(
XCTAssertEqual(
try parser.parseCommandStream(buffer: &input),
.init(numberOfSynchronisingLiterals: 0, command: .command(.init(tag: "1", command: .noop)))
)
)
XCTAssertEqual(input, "")
input = "2 LOGIN {0}\r\n {0}\r\n\r\n"
XCTAssertNoThrow(
XCTAssertEqual(
try parser.parseCommandStream(buffer: &input),
.init(numberOfSynchronisingLiterals: 2, command: .command(.init(tag: "2", command: .login(username: "", password: ""))))
)
)
XCTAssertEqual(input, "")
input = "3 APPEND INBOX {3+}\r\n123 {3+}\r\n456 {3+}\r\n789\r\n"
XCTAssertEqual(try! parser.parseCommandStream(buffer: &input), .init(numberOfSynchronisingLiterals: 0, command: .append(.start(tag: "3", appendingTo: .inbox))))
XCTAssertEqual(input, " {3+}\r\n123 {3+}\r\n456 {3+}\r\n789\r\n")
}
}