blob: 43c9a4795e320a9443f7e9e061eae20e3201452a [file] [log] [blame]
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
import Foundation
import XCTest
#else
import SwiftFoundation
import SwiftXCTest
#endif
class TestNSError : XCTestCase {
static var allTests: [(String, (TestNSError) -> () throws -> Void)] {
return [
("test_LocalizedError_errorDescription", test_LocalizedError_errorDescription),
("test_NSErrorAsError_localizedDescription", test_NSErrorAsError_localizedDescription),
]
}
func test_LocalizedError_errorDescription() {
struct Error : LocalizedError {
var errorDescription: String? { return "error description" }
}
let error = Error()
XCTAssertEqual(error.localizedDescription, "error description")
}
func test_NSErrorAsError_localizedDescription() {
let nsError = NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: "Localized!"])
let error = nsError as Error
XCTAssertEqual(error.localizedDescription, "Localized!")
}
}