|
| 1 | +// |
| 2 | +// This source file is part of the Swift.org open source project |
| 3 | +// |
| 4 | +// Copyright (c) 2024 Apple Inc. and the Swift project authors |
| 5 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 6 | +// |
| 7 | +// See https://swift.org/LICENSE.txt for license information |
| 8 | +// See https://swift.org/CONTRIBUTORS.txt for Swift project authors |
| 9 | +// |
| 10 | + |
| 11 | +@testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing |
| 12 | + |
| 13 | +private import _TestingInternals |
| 14 | + |
| 15 | +@Suite("CustomTestStringConvertible Tests") |
| 16 | +struct CustomTestStringConvertibleTests { |
| 17 | + @Test func optionals() { |
| 18 | + #expect(String(describingForTest: 0 as Int?) == "0") |
| 19 | + #expect(String(describingForTest: "abc" as String?) == #""abc""#) |
| 20 | + #expect(String(describingForTest: nil as Int?) == "nil") |
| 21 | + #expect(String(describingForTest: nil as String?) == "nil") |
| 22 | + #expect(String(describingForTest: nil as _OptionalNilComparisonType) == "nil") |
| 23 | + } |
| 24 | + |
| 25 | + @Test func strings() { |
| 26 | + #expect(String(describingForTest: "abc") == #""abc""#) |
| 27 | + #expect(String(describingForTest: "abc"[...] as Substring) == #""abc""#) |
| 28 | + } |
| 29 | + |
| 30 | + @Test func ranges() { |
| 31 | + #expect(String(describingForTest: 0 ... 1) == "0 ... 1") |
| 32 | + #expect(String(describingForTest: 0...) == "0...") |
| 33 | + #expect(String(describingForTest: ...1) == "...1") |
| 34 | + #expect(String(describingForTest: ..<1) == "..<1") |
| 35 | + #expect(String(describingForTest: 0 ..< 1) == "0 ..< 1") |
| 36 | + } |
| 37 | + |
| 38 | + @Test func types() { |
| 39 | + #expect(String(describingForTest: Self.self) == "CustomTestStringConvertibleTests") |
| 40 | + #expect(String(describingForTest: NonCopyableType.self) == "NonCopyableType") |
| 41 | + } |
| 42 | + |
| 43 | + @Test func enumerations() { |
| 44 | + #expect(String(describingForTest: SWTTestEnumeration.A) == "SWTTestEnumeration(rawValue: \(SWTTestEnumeration.A.rawValue))") |
| 45 | + #expect(String(describingForTest: SomeEnum.elitSedDoEiusmod) == ".elitSedDoEiusmod") |
| 46 | + } |
| 47 | + |
| 48 | + @Test func otherProtocols() { |
| 49 | + #expect(String(describingForTest: CustomStringConvertibleType()) == "Lorem ipsum") |
| 50 | + #expect(String(describingForTest: TextOutputStreamableType()) == "Dolor sit amet") |
| 51 | + #expect(String(describingForTest: CustomDebugStringConvertibleType()) == "Consectetur adipiscing") |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +// MARK: - Fixtures |
| 56 | + |
| 57 | +private struct NonCopyableType: ~Copyable {} |
| 58 | + |
| 59 | +private struct CustomStringConvertibleType: CustomStringConvertible { |
| 60 | + var description: String { |
| 61 | + "Lorem ipsum" |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +private struct TextOutputStreamableType: TextOutputStreamable { |
| 66 | + func write(to target: inout some TextOutputStream) { |
| 67 | + target.write("Dolor sit amet") |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +private struct CustomDebugStringConvertibleType: CustomDebugStringConvertible { |
| 72 | + var debugDescription: String { |
| 73 | + "Consectetur adipiscing" |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +private enum SomeEnum { |
| 78 | + case elitSedDoEiusmod |
| 79 | +} |
0 commit comments