mirror of
https://github.com/apple/swift-algorithms
synced 2026-11-22 04:10:39 +00:00
* Incorporate swift-format formatting fixes * Resolve linting issues * Doc edits, mostly to fix linter-identified issues * Early exit improvements * Indentation fixes * Line lengths to 80 maximum * Implement case binding rule, plus argument line break improvements * Implement NoForceUnwrap rule * Format the tests, as well * Stop masquerading as XCTest
24 lines
837 B
Swift
24 lines
837 B
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift Algorithms open source project
|
|
//
|
|
// Copyright (c) 2020 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import Algorithms
|
|
import XCTest
|
|
|
|
final class FirstNonNilTests: XCTestCase {
|
|
func testFirstNonNil() {
|
|
XCTAssertNil([].firstNonNil { $0 })
|
|
XCTAssertNil(["A", "B", "C"].firstNonNil { Int($0) })
|
|
XCTAssertNil(["A", "B", "C"].firstNonNil { _ in nil })
|
|
XCTAssertEqual(["A", "B", "10"].firstNonNil { Int($0) }, 10)
|
|
XCTAssertEqual(["20", "B", "10"].firstNonNil { Int($0) }, 20)
|
|
}
|
|
}
|