1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import XCTest
import Basics
import PackageModel
class PackageIdentityNameTests: XCTestCase {
func testValidNames() throws {
XCTAssertNoThrow(try PackageIdentity.Name(validating: "LinkedList"))
XCTAssertNoThrow(try PackageIdentity.Name(validating: "Linked-List"))
XCTAssertNoThrow(try PackageIdentity.Name(validating: "Linked_List"))
XCTAssertNoThrow(try PackageIdentity.Name(validating: "A"))
XCTAssertNoThrow(try PackageIdentity.Name(validating: "1"))
XCTAssertNoThrow(try PackageIdentity.Name(validating: String(repeating: "A", count: 100)))
}
func testInvalidNames() throws {
XCTAssertThrowsError(try PackageIdentity.Name(validating: "")) { error in
XCTAssertEqual(error.localizedDescription, "The minimum length of a package name is 1 character.")
}
XCTAssertThrowsError(try PackageIdentity.Name(validating: String(repeating: "a", count: 101))) { error in
XCTAssertEqual(error.localizedDescription, "The maximum length of a package name is 100 characters.")
}
XCTAssertThrowsError(try PackageIdentity.Name(validating: "!")) { error in
XCTAssertEqual(error.localizedDescription, "A package name consists of alphanumeric characters, underscores, and hyphens.")
}
XCTAssertThrowsError(try PackageIdentity.Name(validating: "あ")) { error in
XCTAssertEqual(error.localizedDescription, "A package name consists of alphanumeric characters, underscores, and hyphens.")
}
XCTAssertThrowsError(try PackageIdentity.Name(validating: "🧍")) { error in
XCTAssertEqual(error.localizedDescription, "A package name consists of alphanumeric characters, underscores, and hyphens.")
}
XCTAssertThrowsError(try PackageIdentity.Name(validating: "-a")) { error in
XCTAssertEqual(error.localizedDescription, "Hyphens and underscores may not occur at the beginning of a name.")
}
XCTAssertThrowsError(try PackageIdentity.Name(validating: "_a")) { error in
XCTAssertEqual(error.localizedDescription, "Hyphens and underscores may not occur at the beginning of a name.")
}
XCTAssertThrowsError(try PackageIdentity.Name(validating: "a-")) { error in
XCTAssertEqual(error.localizedDescription, "Hyphens and underscores may not occur at the end of a name.")
}
XCTAssertThrowsError(try PackageIdentity.Name(validating: "a_")) { error in
XCTAssertEqual(error.localizedDescription, "Hyphens and underscores may not occur at the end of a name.")
}
XCTAssertThrowsError(try PackageIdentity.Name(validating: "a_-a")) { error in
XCTAssertEqual(error.localizedDescription, "Hyphens and underscores may not occur consecutively within a name.")
}
XCTAssertThrowsError(try PackageIdentity.Name(validating: "a-_a")) { error in
XCTAssertEqual(error.localizedDescription, "Hyphens and underscores may not occur consecutively within a name.")
}
XCTAssertThrowsError(try PackageIdentity.Name(validating: "a--a")) { error in
XCTAssertEqual(error.localizedDescription, "Hyphens and underscores may not occur consecutively within a name.")
}
XCTAssertThrowsError(try PackageIdentity.Name(validating: "a__a")) { error in
XCTAssertEqual(error.localizedDescription, "Hyphens and underscores may not occur consecutively within a name.")
}
}
func testNamesAreCaseInsensitive() throws {
let lowercase: PackageIdentity.Name = "linkedlist"
let uppercase: PackageIdentity.Name = "LINKEDLIST"
XCTAssertEqual(lowercase, uppercase)
}
}
|