diff --git a/.gitignore b/.gitignore index d9d8f012..ea02318b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ .DS_Store -/.build +.build /build /.swiftpm /Packages diff --git a/Sources/Vexil/Flag.swift b/Sources/Vexil/Flag.swift index ec58a4d6..00a61731 100644 --- a/Sources/Vexil/Flag.swift +++ b/Sources/Vexil/Flag.swift @@ -11,54 +11,6 @@ // //===----------------------------------------------------------------------===// -/// Creates a flag with the specified configuration. -/// -/// All Flags must be initialised with a default value and a description. -/// The default value is used when none of the sources on the `FlagPole` -/// have a value specified for this flag. The description is used for future -/// developer reference and in Vexlliographer to describe the flag. -/// -/// The type that you wrap with `@Flag` must conform to `FlagValue`. -/// -/// You can access flag details and observe flag value changes using a peer -/// property prefixed with `$`. -/// -/// ```swift -/// @Flag(default: false, description: "My magical flag") -/// var magicFlag: Bool -/// -/// // Subscribe to flag updates -/// for try await magic in $magicFlag { -/// // Do magic thing -/// } -/// -/// // Also works with Combine -/// $magicFlag -/// .sink { magic in -/// // Do magic thing -/// } -/// ``` -/// -/// - Parameters: -/// - name: An optional display name to give the flag. Only visible in flag editors like Vexillographer. -/// Default is to calculate one based on the property name. -/// - keyStrategy: An optional strategy to use when calculating the key name. The default is to use the `FlagPole`s strategy. -/// - default: The default value for this `Flag` should no sources have it set. -/// - description: A description of this flag. Used in flag editors like Vexillographer, -/// and also for future developer context. -/// - display: How the flag should be displayed in Vexillographer. Defaults to `.default`, -/// you can set it to `.hidden` to hide the flag. -/// -@attached(accessor) -@attached(peer, names: prefixed(`$`)) -public macro Flag( - name: StaticString? = nil, - keyStrategy: VexilConfiguration.FlagKeyStrategy = .default, - default initialValue: Value, - description: StaticString, - display: FlagDisplayOption = .default -) = #externalMacro(module: "VexilMacros", type: "FlagMacro") - /// Creates a flag with the specified configuration. /// /// All Flags must be initialised via the property and include a description. diff --git a/Sources/Vexil/Group.swift b/Sources/Vexil/Group.swift index 1c8f8c22..375b2bb5 100644 --- a/Sources/Vexil/Group.swift +++ b/Sources/Vexil/Group.swift @@ -11,6 +11,90 @@ // //===----------------------------------------------------------------------===// +/// Creates a FlagGroup with the given parameters. +/// +/// All FlagGroup's must have at least a `description` which is used for future developer +/// reference and within Vexillographer, our generated flag management UI. +/// +/// Attach this to a property within a `@FlagContainer`. The property's type must also +/// be a `FlagContainer`. +/// +/// ```swift +/// @FlagContainer +/// struct MyFlags { +/// @FlagGroup("These flags are displayed inside a `NavigationLink` (this is the default)", display: .navigation) +/// var navigation: NavigationFlags +/// +/// @FlagGroup("These flags are displayed as a `Section`", display: .section) +/// var section: SectionedFlags +/// } +/// +/// @FlagContainer +/// struct NavigationFlags { +/// @Flag("First Flag") +/// var first = false +/// } +/// +/// @FlagContainer +/// struct SectionedFlags { +/// @Flag("Second Flag") +/// var second = false +/// } +/// ``` +/// +/// - Parameters: +/// - description: A description of this flag group. Used in flag editors like Vexillographer, and also for future developer context. +/// - display: How the flag should be displayed in Vexillographer. Defaults to `.navigation` which wraps it in a +/// `NavigationLink`. Other options include `.section` to wrap it in a `Section` and `.hidden` +/// to hide it from Vexillographer entirely. +/// +@attached(accessor) +@attached(peer, names: prefixed(`$`)) +public macro FlagGroup( + _ description: StaticString, + display: FlagGroupDisplayOption = .navigation +) = #externalMacro(module: "VexilMacros", type: "FlagGroupMacro") + +/// Creates a FlagGroup with the given parameters. +/// +/// All FlagGroup's must have at least a `description` which is used for future developer +/// reference and within Vexillographer, our generated flag management UI. +/// +/// Attach this to a property within a `@FlagContainer`. The property's type must also +/// be a `FlagContainer`. +/// +/// ```swift +/// @FlagContainer +/// struct MyFlags { +/// @FlagGroup(name: "Navigation Flags", description: "These flags are displayed inside a `NavigationLink` (this is the default)", display: .navigation) +/// var navigation: NavigationFlags +/// +/// @FlagGroup(name: "Section Flags", description: "These flags are displayed as a `Section`", display: .section) +/// var section: SectionedFlags +/// } +/// +/// @FlagContainer +/// struct NavigationFlags { +/// @Flag("First Flag") +/// var first = false +/// } +/// +/// @FlagContainer +/// struct SectionedFlags { +/// @Flag("Second Flag") +/// var second = false +/// } +/// ``` +/// +/// - Parameters: +/// - name: An optional display name to give the flag group. Only visible in flag editors like Vexillographer. +/// Default is to calculate one based on the property name. +/// - keyStrategy: An optional strategy to use when calculating the key name. The default is to use the `FlagPole`s strategy. +/// - description: A description of this flag group. Used in flag editors like Vexillographer, and also for future developer context. +/// - display: How the flag should be displayed in Vexillographer. Defaults to `.navigation` which wraps it in a +/// `NavigationLink`. Other options include `.section` to wrap it in a `Section` and `.hidden` +/// to hide it from Vexillographer entirely. +/// @attached(accessor) @attached(peer, names: prefixed(`$`)) public macro FlagGroup( diff --git a/Sources/Vexil/Vexil.docc/DefiningFlags.md b/Sources/Vexil/Vexil.docc/DefiningFlags.md index 079856bd..5de379a1 100644 --- a/Sources/Vexil/Vexil.docc/DefiningFlags.md +++ b/Sources/Vexil/Vexil.docc/DefiningFlags.md @@ -69,14 +69,14 @@ import Vexil struct NormalFlags: FlagContainer { - @Flag(default: 10, "This is a demonstration Int flag") - var myIntFlag: Int + @Flag("This is a demonstration Int flag") + var myIntFlag = 10 - @Flag(default: 0.5, "This is a demonstration Double flag") - var myDoubleFlag: Double + @Flag("This is a demonstration Double flag") + var myDoubleFlag = 0.5 - @Flag(default: "Placeholder", "This is a demonstration String flag") - var myStringFlag: String + @Flag("This is a demonstration String flag") + var myStringFlag = "Placeholder"" } ``` @@ -98,8 +98,8 @@ enum MyTheme: String, FlagValue, CaseIterable { struct ThemeFlags { - @Flag(default: .blue, "The theme to use for the app") - var currentTheme: MyTheme + @Flag("The theme to use for the app") + var currentTheme = MyTheme.blue } ``` @@ -117,8 +117,8 @@ struct MyStruct: FlagValue, Codable { struct TestFlags: FlagContainer { - @Flag(defaultValue: MyStruct(property1: "abc123", property2: 123, property3: "🤯"), description: "...") - var testFlag: MyStruct + @Flag(description: "...") + var testFlag = MyStruct(property1: "abc123", property2: 123, property3: "🤯") } ``` diff --git a/Sources/Vexil/Vexil.docc/FlagKeys.md b/Sources/Vexil/Vexil.docc/FlagKeys.md index 9bec0a90..a8267415 100644 --- a/Sources/Vexil/Vexil.docc/FlagKeys.md +++ b/Sources/Vexil/Vexil.docc/FlagKeys.md @@ -73,8 +73,8 @@ print(flagPole.subgroup.secondSubgroup.$myAwesomeFlag.key) Sometimes though you want to override how a specific flag calculates its key. Vexil allows you to pass in a ``Flag/CodingKeyStrategy`` when you declare your ``Flag`` to alter how its key is calculated: ```swift -@Flag(codingKeyStrategy: .snakecase, default: false, description: "My Awesome Flag") -var myAwesomeFlag: Bool +@Flag(codingKeyStrategy: .snakecase, description: "My Awesome Flag") +var myAwesomeFlag = false // Key is "subgroup.second-subgroup.my_awesome_flag" ``` @@ -86,8 +86,8 @@ That would leave `myAwesomeFlag` calculating its key as `"subgroup.second-subgro You can also go for a manually specified key instead of a calculated one using a ``Flag/CodingKeyStrategy`` of `.customKey("my-key")`: ```swift -@Flag(codingKeyStrategy: .customKey("my-key"), default: false, description: "My Awesome Flag") -var myAwesomeFlag: Bool +@Flag(codingKeyStrategy: .customKey("my-key"), description: "My Awesome Flag") +var myAwesomeFlag = false // Key is "subgroup.second-subgroup.my-key" ``` @@ -97,8 +97,8 @@ var myAwesomeFlag: Bool But sometimes your ``FlagValueSource`` doesn't play nice, or the people naming flags in the backend don't provide the same structure that you want your local flags to be in. You can instead set a manual key path. In this case the ``FlagPole`` will ignore the location of the ``Flag`` in the flag structure and will just use the key you specify. ```swift -@Flag(codingKeyStrategy: .customKeyPath("my-key"), default: false, description: "My Awesome Flag") -var myAwesomeFlag: Bool +@Flag(codingKeyStrategy: .customKeyPath("my-key"), description: "My Awesome Flag") +var myAwesomeFlag = false // Key is "my-key" ``` @@ -110,7 +110,7 @@ While a ``FlagGroup`` doesn't have an explicit key of its own, it does form part ```swift struct MyFlags: FlagContainer { - @FlagGroup(description: "A subgroup of flags") + @FlagGroup("A subgroup of flags") var subgroup: Subgroup } diff --git a/Sources/Vexil/Vexil.docc/Migration2-3.md b/Sources/Vexil/Vexil.docc/Migration2-3.md index 72104c30..22dd6964 100644 --- a/Sources/Vexil/Vexil.docc/Migration2-3.md +++ b/Sources/Vexil/Vexil.docc/Migration2-3.md @@ -57,10 +57,10 @@ struct MyFlags: FlagContainer { @FlagContainer struct MyFlags { - @Flag(default: false, description: "Test flag that does something magical") - var testFlag: Bool + @Flag("Test flag that does something magical") + var testFlag = false - @FlagGroup(description: "Some nested flags") + @FlagGroup("Some nested flags") var nested: NestedFlags } @@ -117,12 +117,19 @@ FlagContainer.init( Under Vexil 3, this is now a macro: ```swift +// Full macro public macro FlagGroup( name: StaticString? = nil, keyStrategy: VexilConfiguration.GroupKeyStrategy = .default, description: StaticString, display: VexilDisplayOption = .navigation ) + +// Or shorter +public macro FlagGroup( + _ description: StaticString, + display: VexilDisplayOption = .navigation +) ``` As you can see the changes here purely for simplification: `codingKeyStrategy` @@ -136,14 +143,14 @@ could set your description to `.hidden`; now you pass `.hidden` to display: var nested: NestedFlags // Vexil 3 -@FlagGroup(description: "Nested flags", display: .hidden) +@FlagGroup("Nested flags", display: .hidden) var nested: NestedFlags ``` ### Flags Much like Flag Groups, the `@Flag` property wrapper was replaced with the -``Flag(name:keyStrategy:default:description:)`` macro, with simplified parameters: +``Flag(name:keyStrategy:description:display:)`` macro, with simplified parameters: ```swift // Vexil 2 @@ -156,9 +163,6 @@ var magic = false // Vexil 3 -@Flag(default: false, description: "Flag that enables magic") -var magic: Bool - @Flag("Flag that enables magic") var magic = false ``` @@ -184,18 +188,9 @@ init( ) ``` -Both approaches are available via the `@Flag` macro: +With the `@Flag` macro we now require the property initialiser. ```swift -/// Explicit default parameter -macro Flag( - name: StaticString? = nil, - keyStrategy: VexilConfiguration.FlagKeyStrategy = .default, - default initialValue: Value, - description: StaticString, - display: FlagDisplayOption = .default -) - /// Sets default via property initialiser macro Flag( name: StaticString? = nil, @@ -211,6 +206,19 @@ macro Flag(_ description: StaticString) Same as with the `FlagGroup`, the `codingKeyStrategy` parameter has been shortened to `keyStrategy`, and the ability to hide flags has been moved to the `display` property. +>Note: +> +>The `default:` parameter option was removed as it included a large foot-gun with cryptic +>error message. It was decided to remove this potential issue by aligning with +>[swift-argument-parser](https://github.com/apple/swift-argument-parser)'s approach. +> +>As the macro is type-checked without reference to the attached property's type you get errors like: +> +>```swift +>@Flag(default: .enumCase, description: "") // compiler error: Type of `.enumCase` cannot be inferred. +>var myFlag: MyEnum +>``` + ## Flag Pole Observation Under Vexil 2, every time a `FlagValueSource` reported a flag value change, we would diff --git a/Sources/Vexil/Vexil.docc/Vexil.md b/Sources/Vexil/Vexil.docc/Vexil.md index 56650730..4c733905 100644 --- a/Sources/Vexil/Vexil.docc/Vexil.md +++ b/Sources/Vexil/Vexil.docc/Vexil.md @@ -148,7 +148,6 @@ let snapshot = flagPole.snapshot() ### Flags - -- ``Flag(name:keyStrategy:default:description:display:)`` - ``Flag(name:keyStrategy:description:display:)`` - ``Flag(_:)`` - ``FlagValue`` @@ -156,6 +155,7 @@ let snapshot = flagPole.snapshot() ### Flag Groups - ``FlagGroup(name:keyStrategy:description:display:)`` +- ``FlagGroup(_:display:)`` - ``FlagContainer(generateEquatable:)`` ### Snapshots diff --git a/Sources/VexilMacros/FlagContainerMacro.swift b/Sources/VexilMacros/FlagContainerMacro.swift index 209e4f7d..512b4ed9 100644 --- a/Sources/VexilMacros/FlagContainerMacro.swift +++ b/Sources/VexilMacros/FlagContainerMacro.swift @@ -170,7 +170,7 @@ extension FlagContainerMacro: ExtensionMacro { ]) } } - ExprSyntax("lhs.\(lastBinding) == rhs.\(lastBinding)") + ExprSyntax("lhs.\(lastBinding.trimmed) == rhs.\(lastBinding.trimmed)") } } .with(\.modifiers, Array(scopes) + [ DeclModifierSyntax(name: .keyword(.static)) ]) diff --git a/Sources/VexilMacros/FlagGroupMacro.swift b/Sources/VexilMacros/FlagGroupMacro.swift index 605a29ff..eaf83bf4 100644 --- a/Sources/VexilMacros/FlagGroupMacro.swift +++ b/Sources/VexilMacros/FlagGroupMacro.swift @@ -56,7 +56,7 @@ public struct FlagGroupMacro { self.scopes = property.modifiers.scopeSyntax self.name = arguments[label: "name"]?.expression - self.description = arguments[label: "description"]?.expression + self.description = arguments[label: "description"]?.expression ?? arguments[label: nil]?.expression self.displayOption = arguments[label: "display"]?.expression } diff --git a/Sources/VexilMacros/FlagMacro.swift b/Sources/VexilMacros/FlagMacro.swift index 0c04d0a9..7cda6401 100644 --- a/Sources/VexilMacros/FlagMacro.swift +++ b/Sources/VexilMacros/FlagMacro.swift @@ -50,15 +50,19 @@ public struct FlagMacro { let property = declaration.as(VariableDeclSyntax.self), let binding = property.bindings.first, let identifier = binding.pattern.as(IdentifierPatternSyntax.self)?.identifier, - let type = binding.typeAnnotation?.type ?? binding.inferredType, binding.accessorBlock == nil else { throw DiagnosticsError(diagnostics: [ .init(node: node, message: Diagnostic.onlySimpleVariableSupported) ]) } + + guard let type = binding.typeAnnotation?.type ?? binding.inferredType else { + throw DiagnosticsError(diagnostics: [ .init(node: node, message: Diagnostic.onlySimpleVariableSupported) ]) + } + self.scopes = property.modifiers.scopeSyntax var defaultExprSyntax: ExprSyntax - if let defaultExpr = arguments[label: "default"]?.expression ?? binding.initializer?.value { + if let defaultExpr = binding.initializer?.value { defaultExprSyntax = defaultExpr } else if binding.typeAnnotation?.type.is(OptionalTypeSyntax.self) == true { defaultExprSyntax = ExprSyntax(NilLiteralExprSyntax()) @@ -192,6 +196,7 @@ extension FlagMacro { case missingDefaultValue case missingDescription case onlySimpleVariableSupported + case typeCouldNotBeInferred var message: String { switch self { @@ -200,6 +205,7 @@ extension FlagMacro { case .missingDefaultValue: "Could not infer the default value. Initialise the property or set the default: parameter." case .missingDescription: "Description parameter missing." case .onlySimpleVariableSupported: "Only simple single-binding properties supported." + case .typeCouldNotBeInferred: "Type could not be inferred from the initializer. Specify a type explicitly." } } @@ -210,6 +216,7 @@ extension FlagMacro { case .missingDefaultValue: MessageID(domain: "com.unsignedapps.vexil.flagMacro", id: "missingDefaultValue") case .missingDescription: MessageID(domain: "com.unsignedapps.vexil.flagMacro", id: "missingDescription") case .onlySimpleVariableSupported: MessageID(domain: "com.unsignedapps.vexil.flagMacro", id: "onlySimpleVariableSupported") + case .typeCouldNotBeInferred: MessageID(domain: "com.unsignedapps.vexil.flagMacro", id: "typeCouldNotBeInferred") } } diff --git a/Sources/VexilMacros/Utilities/AttributeArgument.swift b/Sources/VexilMacros/Utilities/AttributeArgument.swift index 6302b369..f811af62 100644 --- a/Sources/VexilMacros/Utilities/AttributeArgument.swift +++ b/Sources/VexilMacros/Utilities/AttributeArgument.swift @@ -15,7 +15,7 @@ import SwiftSyntax extension AttributeSyntax.Arguments { - subscript(label label: String) -> LabeledExprSyntax? { + subscript(label label: String?) -> LabeledExprSyntax? { guard case let .argumentList(list) = self else { return nil } diff --git a/Sources/VexilMacros/Utilities/PatternBindingSyntax.swift b/Sources/VexilMacros/Utilities/PatternBindingSyntax.swift index a1fb8351..c48a46bc 100644 --- a/Sources/VexilMacros/Utilities/PatternBindingSyntax.swift +++ b/Sources/VexilMacros/Utilities/PatternBindingSyntax.swift @@ -21,23 +21,24 @@ extension PatternBindingSyntax { } if let initializer { - if initializer.value.is(BooleanLiteralExprSyntax.self) { + let value = initializer.value.as(ForceUnwrapExprSyntax.self)?.expression ?? initializer.value + if value.is(BooleanLiteralExprSyntax.self) { return "Bool" - } else if initializer.value.is(IntegerLiteralExprSyntax.self) { + } else if value.is(IntegerLiteralExprSyntax.self) { return "Int" - } else if initializer.value.is(StringLiteralExprSyntax.self) { + } else if value.is(StringLiteralExprSyntax.self) { return "String" - } else if initializer.value.is(FloatLiteralExprSyntax.self) { + } else if value.is(FloatLiteralExprSyntax.self) { return "Double" - } else if initializer.value.is(RegexLiteralExprSyntax.self) { + } else if value.is(RegexLiteralExprSyntax.self) { return "Regex" - } else if let function = initializer.value.as(FunctionCallExprSyntax.self) { + } else if let function = value.as(FunctionCallExprSyntax.self) { if let identifier = function.calledExpression.as(DeclReferenceExprSyntax.self) { return TypeSyntax(IdentifierTypeSyntax(name: identifier.baseName)) } else if let memberAccess = function.calledExpression.as(MemberAccessExprSyntax.self)?.asMemberTypeSyntax() { return TypeSyntax(memberAccess.baseType) } - } else if let memberAccess = initializer.value.as(MemberAccessExprSyntax.self)?.asMemberTypeSyntax() { + } else if let memberAccess = value.as(MemberAccessExprSyntax.self)?.asMemberTypeSyntax() { return TypeSyntax(memberAccess.baseType) } } diff --git a/Tests/VexilMacroTests/EquatableFlagContainerMacroTests.swift b/Tests/VexilMacroTests/EquatableFlagContainerMacroTests.swift index 4975607e..0e94a8dd 100644 --- a/Tests/VexilMacroTests/EquatableFlagContainerMacroTests.swift +++ b/Tests/VexilMacroTests/EquatableFlagContainerMacroTests.swift @@ -62,8 +62,8 @@ final class EquatableFlagContainerMacroTests: XCTestCase { """ @FlagContainer struct TestFlags { - @Flag(default: false, description: "Some Flag") - var someFlag: Bool + @Flag("Some Flag") + var someFlag = false var someComputedNotEquatableProperty: (any Error)? { nil @@ -82,7 +82,7 @@ final class EquatableFlagContainerMacroTests: XCTestCase { expandedSource: """ struct TestFlags { - var someFlag: Bool { + var someFlag { get { _flagLookup.value(for: _flagKeyPath.append(.automatic("some-flag"))) ?? false } @@ -163,15 +163,15 @@ final class EquatableFlagContainerMacroTests: XCTestCase { """ @FlagContainer public struct TestFlags { - @Flag(default: false, description: "Some Flag") - var someFlag: Bool + @Flag("Some Flag") + var someFlag = false } """, expandedSource: """ public struct TestFlags { - var someFlag: Bool { + var someFlag { get { _flagLookup.value(for: _flagKeyPath.append(.automatic("some-flag"))) ?? false } @@ -239,8 +239,8 @@ final class EquatableFlagContainerMacroTests: XCTestCase { public extension SomeContainer { @FlagContainer struct TestFlags { - @Flag(default: false, description: "Some Flag") - var someFlag: Bool + @Flag("Some Flag") + var someFlag = false } } """, @@ -248,7 +248,7 @@ final class EquatableFlagContainerMacroTests: XCTestCase { """ public extension SomeContainer { struct TestFlags { - var someFlag: Bool { + var someFlag { get { _flagLookup.value(for: _flagKeyPath.append(.automatic("some-flag"))) ?? false } @@ -316,14 +316,14 @@ final class EquatableFlagContainerMacroTests: XCTestCase { """ @FlagContainer struct TestFlags: FlagContainer { - @Flag(default: false, description: "Some Flag") - var someFlag: Bool + @Flag("Some Flag") + var someFlag = false } """, expandedSource: """ struct TestFlags: FlagContainer { - var someFlag: Bool { + var someFlag { get { _flagLookup.value(for: _flagKeyPath.append(.automatic("some-flag"))) ?? false } @@ -390,23 +390,23 @@ final class EquatableFlagContainerMacroTests: XCTestCase { """ @FlagContainer struct TestFlags { - @Flag(default: false, description: "Flag 1") - var first: Bool - @FlagGroup(description: "Test Group") + @Flag("Flag 1") + var first = false + @FlagGroup("Test Group") var flagGroup: GroupOfFlags - @Flag(default: false, description: "Flag 2") - var second: Bool + @Flag("Flag 2") + var second = false } """, expandedSource: """ struct TestFlags { - @Flag(default: false, description: "Flag 1") - var first: Bool - @FlagGroup(description: "Test Group") + @Flag("Flag 1") + var first = false + @FlagGroup("Test Group") var flagGroup: GroupOfFlags - @Flag(default: false, description: "Flag 2") - var second: Bool + @Flag("Flag 2") + var second = false fileprivate let _flagKeyPath: FlagKeyPath @@ -484,23 +484,23 @@ final class EquatableFlagContainerMacroTests: XCTestCase { """ @FlagContainer public struct TestFlags { - @Flag(default: false, description: "Flag 1") - public var first: Bool - @FlagGroup(description: "Test Group") + @Flag("Flag 1") + public var first = false + @FlagGroup("Test Group") public var flagGroup: GroupOfFlags - @Flag(default: false, description: "Flag 2") - public var second: Bool + @Flag("Flag 2") + public var second = false } """, expandedSource: """ public struct TestFlags { - @Flag(default: false, description: "Flag 1") - public var first: Bool - @FlagGroup(description: "Test Group") + @Flag("Flag 1") + public var first = false + @FlagGroup("Test Group") public var flagGroup: GroupOfFlags - @Flag(default: false, description: "Flag 2") - public var second: Bool + @Flag("Flag 2") + public var second = false fileprivate let _flagKeyPath: FlagKeyPath diff --git a/Tests/VexilMacroTests/FlagContainerMacroTests.swift b/Tests/VexilMacroTests/FlagContainerMacroTests.swift index 99706a4f..fee0a488 100644 --- a/Tests/VexilMacroTests/FlagContainerMacroTests.swift +++ b/Tests/VexilMacroTests/FlagContainerMacroTests.swift @@ -138,23 +138,23 @@ final class FlagContainerMacroTests: XCTestCase { """ @FlagContainer struct TestFlags { - @Flag(default: false, description: "Flag 1") - var first: Bool - @FlagGroup(description: "Test Group") + @Flag("Flag 1") + var first = false + @FlagGroup("Test Group") var flagGroup: GroupOfFlags - @Flag(default: false, description: "Flag 2") - var second: Bool + @Flag("Flag 2") + var second = false } """, expandedSource: """ struct TestFlags { - @Flag(default: false, description: "Flag 1") - var first: Bool - @FlagGroup(description: "Test Group") + @Flag("Flag 1") + var first = false + @FlagGroup("Test Group") var flagGroup: GroupOfFlags - @Flag(default: false, description: "Flag 2") - var second: Bool + @Flag("Flag 2") + var second = false fileprivate let _flagKeyPath: FlagKeyPath diff --git a/Tests/VexilMacroTests/FlagGroupMacroTests.swift b/Tests/VexilMacroTests/FlagGroupMacroTests.swift index 52061e65..ffb3e370 100644 --- a/Tests/VexilMacroTests/FlagGroupMacroTests.swift +++ b/Tests/VexilMacroTests/FlagGroupMacroTests.swift @@ -24,7 +24,7 @@ final class FlagGroupMacroTests: XCTestCase { assertMacroExpansion( """ struct TestFlags { - @FlagGroup(description: "Test Flag Group") + @FlagGroup("Test Flag Group") var testSubgroup: SubgroupFlags } """, @@ -58,7 +58,7 @@ final class FlagGroupMacroTests: XCTestCase { assertMacroExpansion( """ struct TestFlags { - @FlagGroup(description: "Test Flag Group") + @FlagGroup("Test Flag Group") public var testSubgroup: SubgroupFlags } """, diff --git a/Tests/VexilMacroTests/FlagMacroTests.swift b/Tests/VexilMacroTests/FlagMacroTests.swift index 153d4905..3112ba48 100644 --- a/Tests/VexilMacroTests/FlagMacroTests.swift +++ b/Tests/VexilMacroTests/FlagMacroTests.swift @@ -22,63 +22,28 @@ final class FlagMacroTests: XCTestCase { // MARK: - Type Tests - func testExpandsBool() throws { - assertMacroExpansion( - """ - struct TestFlags { - @Flag(default: false, description: "meow") - var testProperty: Bool - } - """, - expandedSource: - """ - struct TestFlags { - var testProperty: Bool { - get { - _flagLookup.value(for: _flagKeyPath.append(.automatic("test-property"))) ?? false - } - } - - var $testProperty: FlagWigwag { - FlagWigwag( - keyPath: _flagKeyPath.append(.automatic("test-property")), - name: "Test Property", - defaultValue: false, - description: "meow", - displayOption: .default, - lookup: _flagLookup - ) - } - } - """, - macros: [ - "Flag": FlagMacro.self, - ] - ) - } - - func testExpandsDouble() throws { + func testExpandsOptional() throws { assertMacroExpansion( """ struct TestFlags { - @Flag(default: 123.456, description: "meow") - var testProperty: Double + @Flag("meow") + var testProperty: Bool? } """, expandedSource: """ struct TestFlags { - var testProperty: Double { + var testProperty: Bool? { get { - _flagLookup.value(for: _flagKeyPath.append(.automatic("test-property"))) ?? 123.456 + _flagLookup.value(for: _flagKeyPath.append(.automatic("test-property"))) ?? nil } } - var $testProperty: FlagWigwag { + var $testProperty: FlagWigwag { FlagWigwag( keyPath: _flagKeyPath.append(.automatic("test-property")), name: "Test Property", - defaultValue: 123.456, + defaultValue: nil, description: "meow", displayOption: .default, lookup: _flagLookup @@ -92,28 +57,28 @@ final class FlagMacroTests: XCTestCase { ) } - func testExpandsString() throws { + func testExpandsPublic() throws { assertMacroExpansion( """ struct TestFlags { - @Flag(default: "alpha", description: "meow") - var testProperty: String + @Flag("meow") + public var testProperty: Bool = false } """, expandedSource: """ struct TestFlags { - var testProperty: String { + public var testProperty: Bool { get { - _flagLookup.value(for: _flagKeyPath.append(.automatic("test-property"))) ?? "alpha" + _flagLookup.value(for: _flagKeyPath.append(.automatic("test-property"))) ?? false } } - var $testProperty: FlagWigwag { + public var $testProperty: FlagWigwag { FlagWigwag( keyPath: _flagKeyPath.append(.automatic("test-property")), name: "Test Property", - defaultValue: "alpha", + defaultValue: false, description: "meow", displayOption: .default, lookup: _flagLookup @@ -127,63 +92,31 @@ final class FlagMacroTests: XCTestCase { ) } - func testExpandsEnum() throws { - assertMacroExpansion( - """ - struct TestFlags { - @Flag(default: .testCase, description: "meow") - var testProperty: SomeEnum - } - """, - expandedSource: - """ - struct TestFlags { - var testProperty: SomeEnum { - get { - _flagLookup.value(for: _flagKeyPath.append(.automatic("test-property"))) ?? .testCase - } - } - var $testProperty: FlagWigwag { - FlagWigwag( - keyPath: _flagKeyPath.append(.automatic("test-property")), - name: "Test Property", - defaultValue: .testCase, - description: "meow", - displayOption: .default, - lookup: _flagLookup - ) - } - } - """, - macros: [ - "Flag": FlagMacro.self, - ] - ) - } + // MARK: - Property Initialisation Tests - func testExpandsOptional() throws { + func testExpandsBoolPropertyInitialization() throws { assertMacroExpansion( """ struct TestFlags { - @Flag(description: "meow") - var testProperty: Bool? + @Flag("meow") + var testProperty = false } """, expandedSource: """ struct TestFlags { - var testProperty: Bool? { + var testProperty { get { - _flagLookup.value(for: _flagKeyPath.append(.automatic("test-property"))) ?? nil + _flagLookup.value(for: _flagKeyPath.append(.automatic("test-property"))) ?? false } } - var $testProperty: FlagWigwag { + var $testProperty: FlagWigwag { FlagWigwag( keyPath: _flagKeyPath.append(.automatic("test-property")), name: "Test Property", - defaultValue: nil, + defaultValue: false, description: "meow", displayOption: .default, lookup: _flagLookup @@ -197,28 +130,28 @@ final class FlagMacroTests: XCTestCase { ) } - func testExpandsPublic() throws { + func testExpandsDoublePropertyInitialization() throws { assertMacroExpansion( """ struct TestFlags { - @Flag(default: false, description: "meow") - public var testProperty: Bool + @Flag("meow") + var testProperty = 123.456 } """, expandedSource: """ struct TestFlags { - public var testProperty: Bool { + var testProperty { get { - _flagLookup.value(for: _flagKeyPath.append(.automatic("test-property"))) ?? false + _flagLookup.value(for: _flagKeyPath.append(.automatic("test-property"))) ?? 123.456 } } - public var $testProperty: FlagWigwag { + var $testProperty: FlagWigwag { FlagWigwag( keyPath: _flagKeyPath.append(.automatic("test-property")), name: "Test Property", - defaultValue: false, + defaultValue: 123.456, description: "meow", displayOption: .default, lookup: _flagLookup @@ -232,15 +165,12 @@ final class FlagMacroTests: XCTestCase { ) } - - // MARK: - Property Initialisation Tests - - func testExpandsBoolPropertyInitialization() throws { + func testExpandsStringPropertyInitialization() throws { assertMacroExpansion( """ struct TestFlags { @Flag("meow") - var testProperty = false + var testProperty = "alpha" } """, expandedSource: @@ -248,15 +178,15 @@ final class FlagMacroTests: XCTestCase { struct TestFlags { var testProperty { get { - _flagLookup.value(for: _flagKeyPath.append(.automatic("test-property"))) ?? false + _flagLookup.value(for: _flagKeyPath.append(.automatic("test-property"))) ?? "alpha" } } - var $testProperty: FlagWigwag { + var $testProperty: FlagWigwag { FlagWigwag( keyPath: _flagKeyPath.append(.automatic("test-property")), name: "Test Property", - defaultValue: false, + defaultValue: "alpha", description: "meow", displayOption: .default, lookup: _flagLookup @@ -270,12 +200,12 @@ final class FlagMacroTests: XCTestCase { ) } - func testExpandsDoublePropertyInitialization() throws { + func testExpandsEnumPropertyInitialization() throws { assertMacroExpansion( """ struct TestFlags { @Flag("meow") - var testProperty = 123.456 + var testProperty = SomeEnum.testCase } """, expandedSource: @@ -283,15 +213,15 @@ final class FlagMacroTests: XCTestCase { struct TestFlags { var testProperty { get { - _flagLookup.value(for: _flagKeyPath.append(.automatic("test-property"))) ?? 123.456 + _flagLookup.value(for: _flagKeyPath.append(.automatic("test-property"))) ?? SomeEnum.testCase } } - var $testProperty: FlagWigwag { + var $testProperty: FlagWigwag { FlagWigwag( keyPath: _flagKeyPath.append(.automatic("test-property")), name: "Test Property", - defaultValue: 123.456, + defaultValue: SomeEnum.testCase, description: "meow", displayOption: .default, lookup: _flagLookup @@ -305,12 +235,12 @@ final class FlagMacroTests: XCTestCase { ) } - func testExpandsStringPropertyInitialization() throws { + func testExpandsTypePropertyInitialization() throws { assertMacroExpansion( """ struct TestFlags { @Flag("meow") - var testProperty = "alpha" + var testProperty = SomeType(arg1: false) } """, expandedSource: @@ -318,15 +248,15 @@ final class FlagMacroTests: XCTestCase { struct TestFlags { var testProperty { get { - _flagLookup.value(for: _flagKeyPath.append(.automatic("test-property"))) ?? "alpha" + _flagLookup.value(for: _flagKeyPath.append(.automatic("test-property"))) ?? SomeType(arg1: false) } } - var $testProperty: FlagWigwag { + var $testProperty: FlagWigwag { FlagWigwag( keyPath: _flagKeyPath.append(.automatic("test-property")), name: "Test Property", - defaultValue: "alpha", + defaultValue: SomeType(arg1: false), description: "meow", displayOption: .default, lookup: _flagLookup @@ -340,12 +270,12 @@ final class FlagMacroTests: XCTestCase { ) } - func testExpandsEnumPropertyInitialization() throws { + func testExpandsForceUnwrapPropertyInitialization() throws { assertMacroExpansion( """ struct TestFlags { @Flag("meow") - var testProperty = SomeEnum.testCase + var testProperty = URL(string: "https://test.com/")! } """, expandedSource: @@ -353,15 +283,15 @@ final class FlagMacroTests: XCTestCase { struct TestFlags { var testProperty { get { - _flagLookup.value(for: _flagKeyPath.append(.automatic("test-property"))) ?? SomeEnum.testCase + _flagLookup.value(for: _flagKeyPath.append(.automatic("test-property"))) ?? URL(string: "https://test.com/")! } } - var $testProperty: FlagWigwag { + var $testProperty: FlagWigwag { FlagWigwag( keyPath: _flagKeyPath.append(.automatic("test-property")), name: "Test Property", - defaultValue: SomeEnum.testCase, + defaultValue: URL(string: "https://test.com/")!, description: "meow", displayOption: .default, lookup: _flagLookup @@ -375,15 +305,14 @@ final class FlagMacroTests: XCTestCase { ) } - // MARK: - Argument Tests func testExpandsName() throws { assertMacroExpansion( """ struct TestFlags { - @Flag(name: "Super Test!", default: false, description: "meow") - var testProperty: Bool + @Flag(name: "Super Test!", description: "meow") + var testProperty: Bool = false } """, expandedSource: @@ -417,8 +346,8 @@ final class FlagMacroTests: XCTestCase { assertMacroExpansion( """ struct TestFlags { - @Flag(name: "Super Test!", default: false, description: "Test", display: .hidden) - var testProperty: Bool + @Flag(name: "Super Test!", description: "Test", display: .hidden) + var testProperty: Bool = false } """, expandedSource: @@ -452,8 +381,8 @@ final class FlagMacroTests: XCTestCase { assertMacroExpansion( """ struct TestFlags { - @Flag(name: "Super Test!", default: false, description: "Test", display: FlagDisplayOption.hidden) - var testProperty: Bool + @Flag(name: "Super Test!", description: "Test", display: FlagDisplayOption.hidden) + var testProperty: Bool = false } """, expandedSource: @@ -490,8 +419,8 @@ final class FlagMacroTests: XCTestCase { assertMacroExpansion( """ struct TestFlags { - @Flag(keyStrategy: .default, default: false, description: "meow") - var testProperty: Bool + @Flag(keyStrategy: .default, description: "meow") + var testProperty: Bool = false } """, expandedSource: @@ -525,8 +454,8 @@ final class FlagMacroTests: XCTestCase { assertMacroExpansion( """ struct TestFlags { - @Flag(keyStrategy: VexilConfiguration.FlagKeyStrategy.default, default: false, description: "meow") - var testProperty: Bool + @Flag(keyStrategy: VexilConfiguration.FlagKeyStrategy.default, description: "meow") + var testProperty: Bool = false } """, expandedSource: @@ -563,8 +492,8 @@ final class FlagMacroTests: XCTestCase { assertMacroExpansion( """ struct TestFlags { - @Flag(keyStrategy: .default, default: false, description: "meow") - var testProperty: Bool + @Flag(keyStrategy: .default, description: "meow") + var testProperty: Bool = false } """, expandedSource: @@ -598,8 +527,8 @@ final class FlagMacroTests: XCTestCase { assertMacroExpansion( """ struct TestFlags { - @Flag(keyStrategy: .kebabcase, default: false, description: "meow") - var testProperty: Bool + @Flag(keyStrategy: .kebabcase, description: "meow") + var testProperty: Bool = false } """, expandedSource: @@ -633,8 +562,8 @@ final class FlagMacroTests: XCTestCase { assertMacroExpansion( """ struct TestFlags { - @Flag(keyStrategy: .snakecase, default: false, description: "meow") - var testProperty: Bool + @Flag(keyStrategy: .snakecase, description: "meow") + var testProperty: Bool = false } """, expandedSource: @@ -668,8 +597,8 @@ final class FlagMacroTests: XCTestCase { assertMacroExpansion( """ struct TestFlags { - @Flag(keyStrategy: .customKey("test"), default: false, description: "meow") - var testProperty: Bool + @Flag(keyStrategy: .customKey("test"), description: "meow") + var testProperty: Bool = false } """, expandedSource: @@ -703,8 +632,8 @@ final class FlagMacroTests: XCTestCase { assertMacroExpansion( """ struct TestFlags { - @Flag(keyStrategy: .customKeyPath("test"), default: false, description: "meow") - var testProperty: Bool + @Flag(keyStrategy: .customKeyPath("test"), description: "meow") + var testProperty: Bool = false } """, expandedSource: diff --git a/Tests/VexilTests/EquatableTests.swift b/Tests/VexilTests/EquatableTests.swift index 0025f911..a0a509cf 100644 --- a/Tests/VexilTests/EquatableTests.swift +++ b/Tests/VexilTests/EquatableTests.swift @@ -148,13 +148,13 @@ struct EquatableTests { @FlagContainer private struct TestFlags { - @Flag(default: false, description: "Top level test flag") - var topLevelFlag: Bool + @Flag("Top level test flag") + var topLevelFlag = false - @Flag(default: false, description: "Second test flag") - var secondTestFlag: Bool + @Flag("Second test flag") + var secondTestFlag = false - @FlagGroup(description: "Subgroup of test flags") + @FlagGroup("Subgroup of test flags") var subgroup: SubgroupFlags } @@ -162,10 +162,10 @@ private struct TestFlags { @FlagContainer private struct SubgroupFlags { - @Flag(default: false, description: "Second level test flag") - var secondLevelFlag: Bool + @Flag("Second level test flag") + var secondLevelFlag = false - @FlagGroup(description: "Another level of test flags") + @FlagGroup("Another level of test flags") var doubleSubgroup: DoubleSubgroupFlags } @@ -173,7 +173,7 @@ private struct SubgroupFlags { @FlagContainer private struct DoubleSubgroupFlags { - @Flag(default: false, description: "Third level test flag") - var thirdLevelFlag: Bool + @Flag("Third level test flag") + var thirdLevelFlag = false } diff --git a/Tests/VexilTests/FlagDetailTests.swift b/Tests/VexilTests/FlagDetailTests.swift index ca98da94..d7a36515 100644 --- a/Tests/VexilTests/FlagDetailTests.swift +++ b/Tests/VexilTests/FlagDetailTests.swift @@ -51,10 +51,10 @@ private struct TestFlags { @Flag("Top level test flag") var topLevelFlag = false - @Flag(name: "Super Test!", default: false, description: "Second test flag") - var secondTestFlag: Bool + @Flag(name: "Super Test!", description: "Second test flag") + var secondTestFlag = false - @FlagGroup(description: "Subgroup of test flags") + @FlagGroup("Subgroup of test flags") var subgroup: SubgroupFlags } @@ -62,10 +62,10 @@ private struct TestFlags { @FlagContainer private struct SubgroupFlags { - @Flag(default: false, description: "Second Level Flag", display: .hidden) - var secondLevelFlag: Bool + @Flag(description: "Second Level Flag", display: .hidden) + var secondLevelFlag = false - @FlagGroup(description: "Another level of test flags") + @FlagGroup("Another level of test flags") var doubleSubgroup: DoubleSubgroupFlags } @@ -73,7 +73,7 @@ private struct SubgroupFlags { @FlagContainer private struct DoubleSubgroupFlags { - @Flag(name: "meow", default: false, description: "Third Level Flag", display: FlagDisplayOption.hidden) - var thirdLevelFlag: Bool + @Flag(name: "meow", description: "Third Level Flag", display: FlagDisplayOption.hidden) + var thirdLevelFlag = false } diff --git a/Tests/VexilTests/FlagValueCompilationTests.swift b/Tests/VexilTests/FlagValueCompilationTests.swift index 13c5195f..6322a04c 100644 --- a/Tests/VexilTests/FlagValueCompilationTests.swift +++ b/Tests/VexilTests/FlagValueCompilationTests.swift @@ -220,44 +220,44 @@ struct FlagValueCompilationTests { @FlagContainer private struct BooleanTestFlags { - @Flag(default: true, description: "Test Flag") - var flag: Bool + @Flag("Test Flag") + var flag = true } @FlagContainer private struct StringTestFlags { - @Flag(default: "Test", description: "Test Flag") - var flag: String + @Flag("Test Flag") + var flag = "Test" } @FlagContainer private struct URLTestFlags { - @Flag(default: URL(string: "https://google.com/")!, description: "Test Flag") - var flag: URL + @Flag("Test Flag") + var flag = URL(string: "https://google.com/")! } @FlagContainer private struct DateTestFlags { - @Flag(default: Date.now, description: "Test Flag") - var flag: Date + @Flag("Test Flag") + var flag = Date.now } @FlagContainer private struct DataTestFlags { - @Flag(default: Data("hello".utf8), description: "Test Flag") - var flag: Data + @Flag("Test Flag") + var flag = Data("hello".utf8) } @FlagContainer(generateEquatable: false) private struct IntTestFlags where Value: FlagValue & ExpressibleByIntegerLiteral { - @Flag(default: 123, description: "Test flag") - var flag: Value + @Flag("Test flag") + var flag: Value = 123 } @FlagContainer(generateEquatable: false) private struct FloatTestFlags where Value: FlagValue & ExpressibleByFloatLiteral { - @Flag(default: 123.23, description: "Test flag") - var flag: Value + @Flag("Test flag") + var flag: Value = 123.23 } private struct RawRepresentableTestStruct: RawRepresentable, FlagValue, Equatable { @@ -266,32 +266,32 @@ private struct RawRepresentableTestStruct: RawRepresentable, FlagValue, Equatabl @FlagContainer private struct RawRepresentableTestFlags { - @Flag(default: RawRepresentableTestStruct(rawValue: "Test"), description: "Test flag") - var flag: RawRepresentableTestStruct + @Flag("Test flag") + var flag = RawRepresentableTestStruct(rawValue: "Test") } @FlagContainer private struct OptionalValueTestFlags { - @Flag(default: "Test", description: "Test flas") - var flag: String? + @Flag("Test flas") + var flag: String? = "Test" } @FlagContainer private struct OptionalNoValueTestFlags { - @Flag(default: String?.none, description: "Test flag") + @Flag("Test flag") var flag: String? } @FlagContainer private struct ArrayTestFlags { - @Flag(default: [ 123, 456, 789 ], description: "Test flag") - var flag: [Int] + @Flag("Test flag") + var flag: [Int] = [ 123, 456, 789 ] } @FlagContainer private struct DictionaryTestFlags { - @Flag(default: [ "First": 123, "Second": 456, "Third": 789 ], description: "Test flag") - var flag: [String: Int] + @Flag("Test flag") + var flag: [String: Int] = [ "First": 123, "Second": 456, "Third": 789 ] } private struct CodableTestStruct: Codable, FlagValue, Equatable { @@ -308,6 +308,6 @@ private struct CodableTestStruct: Codable, FlagValue, Equatable { @FlagContainer private struct CodableTestFlags { - @Flag(default: CodableTestStruct(), description: "Test flag") - var flag: CodableTestStruct + @Flag("Test flag") + var flag = CodableTestStruct() } diff --git a/Tests/VexilTests/FlagValueDictionaryTests.swift b/Tests/VexilTests/FlagValueDictionaryTests.swift index f008b0da..f72155a4 100644 --- a/Tests/VexilTests/FlagValueDictionaryTests.swift +++ b/Tests/VexilTests/FlagValueDictionaryTests.swift @@ -151,15 +151,15 @@ private struct TestFlags { @FlagGroup(description: "Test 1") var oneFlagGroup: OneFlags - @Flag(default: false, description: "Top level test flag") - var topLevelFlag: Bool + @Flag("Top level test flag") + var topLevelFlag = false } @FlagContainer private struct OneFlags { - @Flag(default: false, description: "Second level test flag") - var secondLevelFlag: Bool + @Flag("Second level test flag") + var secondLevelFlag = false } diff --git a/Tests/VexilTests/FlagValueSourceTests.swift b/Tests/VexilTests/FlagValueSourceTests.swift index 999b7b5d..86c76ddf 100644 --- a/Tests/VexilTests/FlagValueSourceTests.swift +++ b/Tests/VexilTests/FlagValueSourceTests.swift @@ -118,21 +118,21 @@ struct FlagValueSourceTests { @FlagContainer private struct TestFlags { - @Flag(default: false, description: "This is a test flag") - var testFlag: Bool + @Flag("This is a test flag") + var testFlag = false - @Flag(default: true, description: "This is another test flag") - var secondTestFlag: Bool + @Flag("This is another test flag") + var secondTestFlag = true - @FlagGroup(description: "A test subgroup") + @FlagGroup("A test subgroup") var subgroup: Subgroup } @FlagContainer private struct Subgroup { - @Flag(default: false, description: "A test flag in a subgroup") - var testFlag: Bool + @Flag("A test flag in a subgroup") + var testFlag = false } diff --git a/Tests/VexilTests/KeyEncodingTests.swift b/Tests/VexilTests/KeyEncodingTests.swift index cfd42090..356d559a 100644 --- a/Tests/VexilTests/KeyEncodingTests.swift +++ b/Tests/VexilTests/KeyEncodingTests.swift @@ -84,8 +84,8 @@ private struct TestFlags { @FlagGroup(description: "Test 1") var oneFlagGroup: OneFlags - @Flag(default: false, description: "Top level test flag") - var topLevelFlag: Bool + @Flag("Top level test flag") + var topLevelFlag = false } @@ -95,8 +95,8 @@ private struct OneFlags { @FlagGroup(keyStrategy: .customKey("two"), description: "Test Two") var twoFlagGroup: TwoFlags - @Flag(default: false, description: "Second level test flag") - var secondLevelFlag: Bool + @Flag("Second level test flag") + var secondLevelFlag = false } @FlagContainer @@ -105,24 +105,24 @@ private struct TwoFlags { @FlagGroup(keyStrategy: .skip, description: "Skipping test 3") var flagGroupThree: ThreeFlags - @Flag(default: false, description: "Third level test flag") - var thirdLevelFlag: Bool + @Flag("Third level test flag") + var thirdLevelFlag = false - @Flag(default: false, description: "Second Third level test flag") - var thirdLevelFlag2: Bool + @Flag("Second Third level test flag") + var thirdLevelFlag2 = false } @FlagContainer private struct ThreeFlags { - @Flag(keyStrategy: .customKey("customKey"), default: false, description: "Test flag with custom key") - var custom: Bool + @Flag(keyStrategy: .customKey("customKey"), description: "Test flag with custom key") + var custom = false - @Flag(keyStrategy: .customKeyPath("customKeyPath"), default: false, description: "Test flag with custom key path") - var full: Bool + @Flag(keyStrategy: .customKeyPath("customKeyPath"), description: "Test flag with custom key path") + var full = false - @Flag(default: true, description: "Standard Flag") - var standard: Bool + @Flag("Standard Flag") + var standard = true } diff --git a/Tests/VexilTests/PublisherTests.swift b/Tests/VexilTests/PublisherTests.swift index 6380e80a..31d7d3aa 100644 --- a/Tests/VexilTests/PublisherTests.swift +++ b/Tests/VexilTests/PublisherTests.swift @@ -182,17 +182,17 @@ final class PublisherTests: XCTestCase { @FlagContainer private struct TestFlags { - @Flag(default: false, description: "This is a test flag") - var testFlag: Bool + @Flag("This is a test flag") + var testFlag = false - @Flag(default: false, description: "This is a test flag") - var testFlag2: Bool + @Flag("This is a test flag") + var testFlag2 = false - @Flag(default: false, description: "This is a test flag") - var testFlag3: Bool + @Flag("This is a test flag") + var testFlag3 = false - @Flag(default: false, description: "This is a test flag") - var testFlag4: Bool + @Flag("This is a test flag") + var testFlag4 = false } diff --git a/Tests/VexilTests/SnapshotTests.swift b/Tests/VexilTests/SnapshotTests.swift index fa571a53..785a39b7 100644 --- a/Tests/VexilTests/SnapshotTests.swift +++ b/Tests/VexilTests/SnapshotTests.swift @@ -125,11 +125,11 @@ struct SnapshotTests { @FlagContainer private struct TestFlags { - @Flag(default: false, description: "Top level test flag") - var topLevelFlag: Bool + @Flag("Top level test flag") + var topLevelFlag = false - @Flag(default: false, description: "Second test flag") - var secondTestFlag: Bool + @Flag("Second test flag") + var secondTestFlag = false @FlagGroup(description: "Subgroup of test flags") var subgroup: SubgroupFlags @@ -139,8 +139,8 @@ private struct TestFlags { @FlagContainer private struct SubgroupFlags { - @Flag(default: false, description: "Second level test flag") - var secondLevelFlag: Bool + @Flag("Second level test flag") + var secondLevelFlag = false @FlagGroup(description: "Another level of test flags") var doubleSubgroup: DoubleSubgroupFlags @@ -150,7 +150,7 @@ private struct SubgroupFlags { @FlagContainer private struct DoubleSubgroupFlags { - @Flag(default: false, description: "Third level test flag") - var thirdLevelFlag: Bool + @Flag("Third level test flag") + var thirdLevelFlag = false } diff --git a/Tests/VexilTests/VisitorTests.swift b/Tests/VexilTests/VisitorTests.swift index c4041701..108d45c9 100644 --- a/Tests/VexilTests/VisitorTests.swift +++ b/Tests/VexilTests/VisitorTests.swift @@ -53,13 +53,13 @@ struct VisitorTests { @FlagContainer private struct TestFlags { - @Flag(default: false, description: "Top level test flag") - var topLevelFlag: Bool + @Flag("Top level test flag") + var topLevelFlag = false - @Flag(default: false, description: "Second test flag") - var secondTestFlag: Bool + @Flag("Second test flag") + var secondTestFlag = false - @FlagGroup(description: "Subgroup of test flags") + @FlagGroup("Subgroup of test flags") var subgroup: SubgroupFlags } @@ -67,8 +67,8 @@ private struct TestFlags { @FlagContainer private struct SubgroupFlags { - @Flag(default: false, description: "Second level test flag") - var secondLevelFlag: Bool + @Flag("Second level test flag") + var secondLevelFlag = false @FlagGroup(description: "Another level of test flags") var doubleSubgroup: DoubleSubgroupFlags @@ -78,8 +78,8 @@ private struct SubgroupFlags { @FlagContainer private struct DoubleSubgroupFlags { - @Flag(default: false, description: "Third level test flag") - var thirdLevelFlag: Bool + @Flag("Third level test flag") + var thirdLevelFlag = false }