|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the SwiftConfiguration open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2025 Apple Inc. and the SwiftConfiguration project authors |
| 6 | +// Licensed under Apache License v2.0 |
| 7 | +// |
| 8 | +// See LICENSE.txt for license information |
| 9 | +// See CONTRIBUTORS.txt for the list of SwiftConfiguration project authors |
| 10 | +// |
| 11 | +// SPDX-License-Identifier: Apache-2.0 |
| 12 | +// |
| 13 | +//===----------------------------------------------------------------------===// |
| 14 | + |
| 15 | + |
| 16 | + // ############################################################################# |
| 17 | + // # # |
| 18 | + // # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. # |
| 19 | + // # # |
| 20 | + // ############################################################################# |
| 21 | + |
| 22 | + |
| 23 | +import Testing |
| 24 | +@testable import Configuration |
| 25 | +import ConfigurationTestingInternal |
| 26 | + |
| 27 | +struct ConfigSnapshotReaderMethodTestsGet2 { |
| 28 | + |
| 29 | + typealias Defaults = ConfigReaderTests.Defaults |
| 30 | + typealias TestEnum = ConfigReaderTests.TestEnum |
| 31 | + typealias TestStringConvertible = ConfigReaderTests.TestStringConvertible |
| 32 | + |
| 33 | + @available(Configuration 1.0, *) |
| 34 | + @Test func get() async throws { |
| 35 | + let config = ConfigReaderTests.config |
| 36 | + |
| 37 | + do { |
| 38 | + let snapshot = config.snapshot() |
| 39 | + |
| 40 | + // Optional - success |
| 41 | + #expect(snapshot.string(forKey: "stringConvertible", as: TestStringConvertible.self) == Defaults.stringConvertible) |
| 42 | + |
| 43 | + // Optional - missing |
| 44 | + #expect(snapshot.string(forKey: "absentStringConvertible", as: TestStringConvertible.self) == nil) |
| 45 | + |
| 46 | + // Optional - failing |
| 47 | + #expect(snapshot.string(forKey: "failure", as: TestStringConvertible.self) == nil) |
| 48 | + |
| 49 | + // Defaulted - success |
| 50 | + #expect(snapshot.string(forKey: "stringConvertible", as: TestStringConvertible.self, default: Defaults.otherStringConvertible) == Defaults.stringConvertible) |
| 51 | + |
| 52 | + // Defaulted - missing |
| 53 | + #expect(snapshot.string(forKey: "absentStringConvertible", as: TestStringConvertible.self, default: Defaults.otherStringConvertible) == Defaults.otherStringConvertible) |
| 54 | + |
| 55 | + // Defaulted - failing |
| 56 | + #expect(snapshot.string(forKey: "failure", as: TestStringConvertible.self, default: Defaults.otherStringConvertible) == Defaults.otherStringConvertible) |
| 57 | + |
| 58 | + // Required - success |
| 59 | + try #expect(snapshot.requiredString(forKey: "stringConvertible", as: TestStringConvertible.self) == Defaults.stringConvertible) |
| 60 | + |
| 61 | + // Required - missing |
| 62 | + let error1 = #expect(throws: ConfigError.self) { try snapshot.requiredString(forKey: "absentStringConvertible", as: TestStringConvertible.self) } |
| 63 | + #expect(error1 == .missingRequiredConfigValue(AbsoluteConfigKey(["absentStringConvertible"]))) |
| 64 | + |
| 65 | + // Required - failing |
| 66 | + #expect(throws: TestProvider.TestError.self) { try snapshot.requiredString(forKey: "failure", as: TestStringConvertible.self) } |
| 67 | + } |
| 68 | + do { |
| 69 | + let snapshot = config.snapshot() |
| 70 | + |
| 71 | + // Optional - success |
| 72 | + #expect(snapshot.string(forKey: "stringEnum", as: TestEnum.self) == Defaults.stringEnum) |
| 73 | + |
| 74 | + // Optional - missing |
| 75 | + #expect(snapshot.string(forKey: "absentStringEnum", as: TestEnum.self) == nil) |
| 76 | + |
| 77 | + // Optional - failing |
| 78 | + #expect(snapshot.string(forKey: "failure", as: TestEnum.self) == nil) |
| 79 | + |
| 80 | + // Defaulted - success |
| 81 | + #expect(snapshot.string(forKey: "stringEnum", as: TestEnum.self, default: Defaults.otherStringEnum) == Defaults.stringEnum) |
| 82 | + |
| 83 | + // Defaulted - missing |
| 84 | + #expect(snapshot.string(forKey: "absentStringEnum", as: TestEnum.self, default: Defaults.otherStringEnum) == Defaults.otherStringEnum) |
| 85 | + |
| 86 | + // Defaulted - failing |
| 87 | + #expect(snapshot.string(forKey: "failure", as: TestEnum.self, default: Defaults.otherStringEnum) == Defaults.otherStringEnum) |
| 88 | + |
| 89 | + // Required - success |
| 90 | + try #expect(snapshot.requiredString(forKey: "stringEnum", as: TestEnum.self) == Defaults.stringEnum) |
| 91 | + |
| 92 | + // Required - missing |
| 93 | + let error1 = #expect(throws: ConfigError.self) { try snapshot.requiredString(forKey: "absentStringEnum", as: TestEnum.self) } |
| 94 | + #expect(error1 == .missingRequiredConfigValue(AbsoluteConfigKey(["absentStringEnum"]))) |
| 95 | + |
| 96 | + // Required - failing |
| 97 | + #expect(throws: TestProvider.TestError.self) { try snapshot.requiredString(forKey: "failure", as: TestEnum.self) } |
| 98 | + } |
| 99 | + } |
| 100 | +} |
0 commit comments