|
2 | 2 | //
|
3 | 3 | // This source file is part of the Swift open source project
|
4 | 4 | //
|
5 |
| -// Copyright (c) 2021 Apple Inc. and the Swift project authors |
| 5 | +// Copyright (c) 2021-2025 Apple Inc. and the Swift project authors |
6 | 6 | // Licensed under Apache License v2.0 with Runtime Library Exception
|
7 | 7 | //
|
8 | 8 | // See http://swift.org/LICENSE.txt for license information
|
9 | 9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
10 | 10 | //
|
11 | 11 | //===----------------------------------------------------------------------===//
|
| 12 | +import Foundation |
12 | 13 |
|
13 | 14 | @testable import Basics
|
14 |
| -import XCTest |
| 15 | +import Testing |
15 | 16 |
|
16 |
| -final class EnvironmentKeyTests: XCTestCase { |
17 |
| - func test_comparable() { |
| 17 | +struct EnvironmentKeyTests { |
| 18 | + @Test |
| 19 | + func comparable() { |
18 | 20 | let key0 = EnvironmentKey("Test")
|
19 | 21 | let key1 = EnvironmentKey("Test1")
|
20 |
| - XCTAssertLessThan(key0, key1) |
| 22 | + #expect(key0 < key1) |
21 | 23 |
|
22 | 24 | let key2 = EnvironmentKey("test")
|
23 |
| - XCTAssertLessThan(key0, key2) |
| 25 | + #expect(key0 < key2) |
24 | 26 | }
|
25 | 27 |
|
26 |
| - func test_customStringConvertible() { |
| 28 | + @Test |
| 29 | + func customStringConvertible() { |
27 | 30 | let key = EnvironmentKey("Test")
|
28 |
| - XCTAssertEqual(key.description, "Test") |
| 31 | + #expect(key.description == "Test") |
29 | 32 | }
|
30 | 33 |
|
31 |
| - func test_encodable() throws { |
| 34 | + @Test |
| 35 | + func encodable() throws { |
32 | 36 | let key = EnvironmentKey("Test")
|
33 | 37 | let data = try JSONEncoder().encode(key)
|
34 | 38 | let string = String(data: data, encoding: .utf8)
|
35 |
| - XCTAssertEqual(string, #""Test""#) |
| 39 | + #expect(string == #""Test""#) |
36 | 40 | }
|
37 | 41 |
|
38 |
| - func test_equatable() { |
| 42 | + @Test |
| 43 | + func equatable() { |
39 | 44 | let key0 = EnvironmentKey("Test")
|
40 | 45 | let key1 = EnvironmentKey("Test")
|
41 |
| - XCTAssertEqual(key0, key1) |
| 46 | + #expect(key0 == key1) |
42 | 47 |
|
43 | 48 | let key2 = EnvironmentKey("Test2")
|
44 |
| - XCTAssertNotEqual(key0, key2) |
| 49 | + #expect(key0 != key2) |
45 | 50 |
|
46 | 51 | #if os(Windows)
|
47 | 52 | // Test case insensitivity on windows
|
48 | 53 | let key3 = EnvironmentKey("teSt")
|
49 |
| - XCTAssertEqual(key0, key3) |
| 54 | + #expect(key0 == key3) |
50 | 55 | #endif
|
51 | 56 | }
|
52 | 57 |
|
53 |
| - func test_expressibleByStringLiteral() { |
| 58 | + @Test |
| 59 | + func expressibleByStringLiteral() { |
54 | 60 | let key0 = EnvironmentKey("Test")
|
55 |
| - XCTAssertEqual(key0, "Test") |
| 61 | + #expect(key0 == "Test") |
56 | 62 | }
|
57 | 63 |
|
58 |
| - func test_decodable() throws { |
| 64 | + @Test |
| 65 | + func decodable() throws { |
59 | 66 | let jsonString = #""Test""#
|
60 | 67 | let data = jsonString.data(using: .utf8)!
|
61 | 68 | let key = try JSONDecoder().decode(EnvironmentKey.self, from: data)
|
62 |
| - XCTAssertEqual(key.rawValue, "Test") |
| 69 | + #expect(key.rawValue == "Test") |
63 | 70 | }
|
64 | 71 |
|
65 |
| - func test_hashable() { |
| 72 | + @Test |
| 73 | + func hashable() { |
66 | 74 | var set = Set<EnvironmentKey>()
|
67 | 75 | let key0 = EnvironmentKey("Test")
|
68 |
| - XCTAssertTrue(set.insert(key0).inserted) |
| 76 | + #expect(set.insert(key0).inserted) |
69 | 77 |
|
70 | 78 | let key1 = EnvironmentKey("Test")
|
71 |
| - XCTAssertTrue(set.contains(key1)) |
72 |
| - XCTAssertFalse(set.insert(key1).inserted) |
| 79 | + #expect(set.contains(key1)) |
| 80 | + #expect(!set.insert(key1).inserted) |
73 | 81 |
|
74 | 82 | let key2 = EnvironmentKey("Test2")
|
75 |
| - XCTAssertFalse(set.contains(key2)) |
76 |
| - XCTAssertTrue(set.insert(key2).inserted) |
| 83 | + #expect(!set.contains(key2)) |
| 84 | + #expect(set.insert(key2).inserted) |
77 | 85 |
|
78 | 86 | #if os(Windows)
|
79 | 87 | // Test case insensitivity on windows
|
80 | 88 | let key3 = EnvironmentKey("teSt")
|
81 |
| - XCTAssertTrue(set.contains(key3)) |
82 |
| - XCTAssertFalse(set.insert(key3).inserted) |
| 89 | + #expect(set.contains(key3)) |
| 90 | + #expect(!set.insert(key3).inserted) |
83 | 91 | #endif
|
84 | 92 |
|
85 |
| - XCTAssertEqual(set, ["Test", "Test2"]) |
| 93 | + #expect(set == ["Test", "Test2"]) |
86 | 94 | }
|
87 | 95 |
|
88 |
| - func test_rawRepresentable() { |
| 96 | + @Test |
| 97 | + func rawRepresentable() { |
89 | 98 | let key = EnvironmentKey(rawValue: "Test")
|
90 |
| - XCTAssertEqual(key?.rawValue, "Test") |
| 99 | + #expect(key?.rawValue == "Test") |
91 | 100 | }
|
92 | 101 | }
|
0 commit comments