|
| 1 | +import Foundation |
| 2 | +@testable import Swiftly |
| 3 | +@testable import SwiftlyCore |
| 4 | +import Testing |
| 5 | + |
| 6 | +@Suite struct OutputSchemaTests { |
| 7 | + // MARK: - Test Data Setup |
| 8 | + |
| 9 | + static let testStableToolchain = ToolchainVersion.stable(.init(major: 5, minor: 8, patch: 1)) |
| 10 | + static let testMainSnapshot = ToolchainVersion.snapshot(.init(branch: .main, date: "2023-07-15")) |
| 11 | + static let testReleaseSnapshot = ToolchainVersion.snapshot(.init(branch: .release(major: 5, minor: 9), date: "2023-07-10")) |
| 12 | + |
| 13 | + static let testStableVersionInfo = ToolchainVersion.stable(.init(major: 5, minor: 8, patch: 1)) |
| 14 | + |
| 15 | + static let testMainSnapshotVersionInfo = ToolchainVersion.snapshot(.init(branch: .main, date: "2023-07-15")) |
| 16 | + |
| 17 | + static let testReleaseSnapshotVersionInfo = ToolchainVersion.snapshot(.init(branch: .release(major: 5, minor: 9), date: "2023-07-10")) |
| 18 | + |
| 19 | + // MARK: - ToolchainVersion Tests |
| 20 | + |
| 21 | + @Test func toolchainVersionName() async throws { |
| 22 | + #expect(Self.testStableVersionInfo.name == "5.8.1") |
| 23 | + #expect(Self.testMainSnapshotVersionInfo.name == "main-snapshot-2023-07-15") |
| 24 | + #expect(Self.testReleaseSnapshotVersionInfo.name == "5.9-snapshot-2023-07-10") |
| 25 | + } |
| 26 | + |
| 27 | + // MARK: - AvailableToolchainInfo Tests |
| 28 | + |
| 29 | + @Test func availableToolchainInfoDescription() async throws { |
| 30 | + let basicToolchain = AvailableToolchainInfo( |
| 31 | + version: Self.testStableVersionInfo, |
| 32 | + inUse: false, |
| 33 | + default: false, |
| 34 | + installed: false |
| 35 | + ) |
| 36 | + #expect(basicToolchain.description == "5.8.1") |
| 37 | + |
| 38 | + let installedToolchain = AvailableToolchainInfo( |
| 39 | + version: Self.testStableVersionInfo, |
| 40 | + inUse: false, |
| 41 | + default: false, |
| 42 | + installed: true |
| 43 | + ) |
| 44 | + #expect(installedToolchain.description == "5.8.1 (installed)") |
| 45 | + |
| 46 | + let inUseToolchain = AvailableToolchainInfo( |
| 47 | + version: Self.testStableVersionInfo, |
| 48 | + inUse: true, |
| 49 | + default: false, |
| 50 | + installed: true |
| 51 | + ) |
| 52 | + #expect(inUseToolchain.description == "5.8.1 (installed) (in use)") |
| 53 | + |
| 54 | + let defaultToolchain = AvailableToolchainInfo( |
| 55 | + version: Self.testStableVersionInfo, |
| 56 | + inUse: true, |
| 57 | + default: true, |
| 58 | + installed: true |
| 59 | + ) |
| 60 | + #expect(defaultToolchain.description == "5.8.1 (installed) (in use) (default)") |
| 61 | + |
| 62 | + let defaultOnlyToolchain = AvailableToolchainInfo( |
| 63 | + version: Self.testStableVersionInfo, |
| 64 | + inUse: false, |
| 65 | + default: true, |
| 66 | + installed: false |
| 67 | + ) |
| 68 | + #expect(defaultOnlyToolchain.description == "5.8.1 (default)") |
| 69 | + } |
| 70 | + |
| 71 | + @Test func availableToolchainsListInfoDescriptionNoSelector() async throws { |
| 72 | + let toolchains = [ |
| 73 | + AvailableToolchainInfo( |
| 74 | + version: Self.testStableVersionInfo, |
| 75 | + inUse: true, |
| 76 | + default: true, |
| 77 | + installed: true |
| 78 | + ), |
| 79 | + AvailableToolchainInfo( |
| 80 | + version: Self.testMainSnapshotVersionInfo, |
| 81 | + inUse: false, |
| 82 | + default: false, |
| 83 | + installed: false |
| 84 | + ), |
| 85 | + ] |
| 86 | + |
| 87 | + let listInfo = AvailableToolchainsListInfo(toolchains: toolchains) |
| 88 | + let description = listInfo.description |
| 89 | + |
| 90 | + #expect(description.contains("Available release toolchains")) |
| 91 | + #expect(description.contains("----------------------------")) |
| 92 | + #expect(description.contains("5.8.1 (installed) (in use) (default)")) |
| 93 | + #expect(description.contains("main-snapshot-2023-07-15")) |
| 94 | + } |
| 95 | + |
| 96 | + @Test func availableToolchainsListInfoDescriptionWithStableSelector() async throws { |
| 97 | + let toolchains = [ |
| 98 | + AvailableToolchainInfo( |
| 99 | + version: Self.testStableVersionInfo, |
| 100 | + inUse: true, |
| 101 | + default: true, |
| 102 | + installed: true |
| 103 | + ), |
| 104 | + ] |
| 105 | + |
| 106 | + let selector = ToolchainSelector.stable(major: 5, minor: 8, patch: nil) |
| 107 | + let listInfo = AvailableToolchainsListInfo(toolchains: toolchains, selector: selector) |
| 108 | + let description = listInfo.description |
| 109 | + |
| 110 | + #expect(description.contains("Available Swift 5.8 release toolchains")) |
| 111 | + #expect(description.contains("5.8.1 (installed) (in use) (default)")) |
| 112 | + } |
| 113 | + |
| 114 | + @Test func availableToolchainsListInfoDescriptionWithMajorOnlySelector() async throws { |
| 115 | + let majorOnlySelector = ToolchainSelector.stable(major: 5, minor: nil, patch: nil) |
| 116 | + let majorOnlyListInfo = AvailableToolchainsListInfo( |
| 117 | + toolchains: [AvailableToolchainInfo( |
| 118 | + version: Self.testStableVersionInfo, |
| 119 | + inUse: false, |
| 120 | + default: false, |
| 121 | + installed: true |
| 122 | + )], |
| 123 | + selector: majorOnlySelector |
| 124 | + ) |
| 125 | + #expect(majorOnlyListInfo.description.contains("Available Swift 5 release toolchains")) |
| 126 | + #expect(majorOnlyListInfo.description.contains("5.8.1 (installed)")) |
| 127 | + } |
| 128 | + |
| 129 | + @Test func availableToolchainsListInfoDescriptionWithMainSnapshotSelector() async throws { |
| 130 | + let mainSnapshotSelector = ToolchainSelector.snapshot(branch: .main, date: nil) |
| 131 | + let mainSnapshotListInfo = AvailableToolchainsListInfo( |
| 132 | + toolchains: [AvailableToolchainInfo( |
| 133 | + version: Self.testMainSnapshotVersionInfo, |
| 134 | + inUse: false, |
| 135 | + default: false, |
| 136 | + installed: false |
| 137 | + )], |
| 138 | + selector: mainSnapshotSelector |
| 139 | + ) |
| 140 | + #expect(mainSnapshotListInfo.description.contains("Available main development snapshot toolchains")) |
| 141 | + #expect(mainSnapshotListInfo.description.contains("main-snapshot-2023-07-15")) |
| 142 | + } |
| 143 | + |
| 144 | + @Test func availableToolchainsListInfoDescriptionWithReleaseSnapshotSelector() async throws { |
| 145 | + let releaseSnapshotSelector = ToolchainSelector.snapshot(branch: .release(major: 5, minor: 9), date: nil) |
| 146 | + let releaseSnapshotListInfo = AvailableToolchainsListInfo( |
| 147 | + toolchains: [AvailableToolchainInfo( |
| 148 | + version: Self.testReleaseSnapshotVersionInfo, |
| 149 | + inUse: false, |
| 150 | + default: false, |
| 151 | + installed: true |
| 152 | + )], |
| 153 | + selector: releaseSnapshotSelector |
| 154 | + ) |
| 155 | + #expect(releaseSnapshotListInfo.description.contains("Available 5.9 development snapshot toolchains")) |
| 156 | + #expect(releaseSnapshotListInfo.description.contains("5.9-snapshot-2023-07-10 (installed)")) |
| 157 | + } |
| 158 | + |
| 159 | + @Test func availableToolchainsListInfoDescriptionWithSpecificVersionSelector() async throws { |
| 160 | + let specificSelector = ToolchainSelector.stable(major: 5, minor: 8, patch: 1) |
| 161 | + let specificListInfo = AvailableToolchainsListInfo( |
| 162 | + toolchains: [AvailableToolchainInfo( |
| 163 | + version: Self.testStableVersionInfo, |
| 164 | + inUse: false, |
| 165 | + default: false, |
| 166 | + installed: false |
| 167 | + )], |
| 168 | + selector: specificSelector |
| 169 | + ) |
| 170 | + #expect(specificListInfo.description.contains("Available matching toolchains")) |
| 171 | + #expect(specificListInfo.description.contains("5.8.1")) |
| 172 | + } |
| 173 | + |
| 174 | + @Test func availableToolchainsListInfoEmptyToolchains() async throws { |
| 175 | + let listInfo = AvailableToolchainsListInfo(toolchains: []) |
| 176 | + let description = listInfo.description |
| 177 | + |
| 178 | + #expect(description.contains("Available release toolchains")) |
| 179 | + #expect(description.contains("----------------------------")) |
| 180 | + // Should not contain any toolchain entries |
| 181 | + #expect(!description.contains("5.8.1")) |
| 182 | + #expect(!description.contains("snapshot")) |
| 183 | + } |
| 184 | +} |
0 commit comments