diff --git a/.swift-format b/.swift-format new file mode 100644 index 0000000..c2f1f0a --- /dev/null +++ b/.swift-format @@ -0,0 +1,74 @@ +{ + "fileScopedDeclarationPrivacy": { + "accessLevel": "private" + }, + "indentConditionalCompilationBlocks": false, + "indentSwitchCaseLabels": false, + "indentation": { + "spaces": 4 + }, + "lineBreakAroundMultilineExpressionChainComponents": false, + "lineBreakBeforeControlFlowKeywords": false, + "lineBreakBeforeEachArgument": true, + "lineBreakBeforeEachGenericRequirement": false, + "lineBreakBetweenDeclarationAttributes": false, + "lineLength": 120, + "maximumBlankLines": 1, + "multiElementCollectionTrailingCommas": true, + "noAssignmentInExpressions": { + "allowedFunctions": [ + "XCTAssertNoThrow" + ] + }, + "prioritizeKeepingFunctionOutputTogether": true, + "reflowMultilineStringLiterals": { + "never": {} + }, + "respectsExistingLineBreaks": true, + "rules": { + "AllPublicDeclarationsHaveDocumentation": false, + "AlwaysUseLiteralForEmptyCollectionInit": false, + "AlwaysUseLowerCamelCase": false, + "AmbiguousTrailingClosureOverload": false, + "BeginDocumentationCommentWithOneLineSummary": false, + "DoNotUseSemicolons": false, + "DontRepeatTypeInStaticProperties": false, + "FileScopedDeclarationPrivacy": true, + "FullyIndirectEnum": true, + "GroupNumericLiterals": true, + "IdentifiersMustBeASCII": true, + "NeverForceUnwrap": false, + "NeverUseForceTry": false, + "NeverUseImplicitlyUnwrappedOptionals": false, + "NoAccessLevelOnExtensionDeclaration": false, + "NoAssignmentInExpressions": true, + "NoBlockComments": false, + "NoCasesWithOnlyFallthrough": true, + "NoEmptyTrailingClosureParentheses": true, + "NoLabelsInCasePatterns": true, + "NoLeadingUnderscores": false, + "NoParensAroundConditions": true, + "NoPlaygroundLiterals": true, + "NoVoidReturnOnFunctionSignature": true, + "OmitExplicitReturns": false, + "OneCasePerLine": true, + "OneVariableDeclarationPerLine": true, + "OnlyOneTrailingClosureArgument": true, + "OrderedImports": true, + "ReplaceForEachWithForLoop": true, + "ReturnVoidInsteadOfEmptyTuple": true, + "TypeNamesShouldBeCapitalized": true, + "UseEarlyExits": false, + "UseExplicitNilCheckInConditions": true, + "UseLetInEveryBoundCaseVariable": false, + "UseShorthandTypeNames": true, + "UseSingleLinePropertyGetter": true, + "UseSynthesizedInitializer": false, + "UseTripleSlashForDocumentationComments": true, + "UseWhereClausesInForLoops": false, + "ValidateDocumentationComments": false + }, + "spacesAroundRangeFormationOperators": false, + "spacesBeforeEndOfLineComments": 2, + "version": 1 +} diff --git a/CompatibilityTesting/Package.swift b/CompatibilityTesting/Package.swift index 7e4c23a..87371d3 100644 --- a/CompatibilityTesting/Package.swift +++ b/CompatibilityTesting/Package.swift @@ -63,6 +63,6 @@ let package = Package( .enableExperimentalFeature("Extern") ], linkerSettings: [.linkedLibrary("swiftDemangle")] - ) + ), ] ) diff --git a/Package.swift b/Package.swift index dc7480a..f868e58 100644 --- a/Package.swift +++ b/Package.swift @@ -14,7 +14,7 @@ let package = Package( platforms: [.macOS(.v26)], products: [ .library(name: "Compute", targets: ["Compute"]), - .library(name: "_ComputeTestSupport", targets: ["_ComputeTestSupport"]) + .library(name: "_ComputeTestSupport", targets: ["_ComputeTestSupport"]), ], traits: [ .trait(name: "CompatibilityModeAttributeGraphV6") @@ -100,8 +100,8 @@ let package = Package( "-DPURE_BRIDGING_MODE", "-isystem", "\(swiftCheckoutPath)/include", "-isystem", "\(swiftCheckoutPath)/stdlib/include", - "-isystem", "\(swiftCheckoutPath)/stdlib/public/SwiftShims" - ]) + "-isystem", "\(swiftCheckoutPath)/stdlib/public/SwiftShims", + ]), ] ), .target(name: "ComputeCxxSwiftSupport"), diff --git a/Sources/Compute/Attribute/AnyAttribute.swift b/Sources/Compute/Attribute/AnyAttribute.swift index f989ff9..c92d7d0 100644 --- a/Sources/Compute/Attribute/AnyAttribute.swift +++ b/Sources/Compute/Attribute/AnyAttribute.swift @@ -3,7 +3,11 @@ import ComputeCxx extension Graph { @_extern(c, "AGGraphSearch") - static func search(attribute: AnyAttribute, options: SearchOptions, predicate: @escaping (AnyAttribute) -> Bool) -> Bool + static func search( + attribute: AnyAttribute, + options: SearchOptions, + predicate: @escaping (AnyAttribute) -> Bool + ) -> Bool @_extern(c, "AGGraphMutateAttribute") static func mutateAttribute( diff --git a/Sources/Compute/Attribute/Attribute.swift b/Sources/Compute/Attribute/Attribute.swift index 443ea44..82c7f39 100644 --- a/Sources/Compute/Attribute/Attribute.swift +++ b/Sources/Compute/Attribute/Attribute.swift @@ -47,9 +47,9 @@ public struct Attribute { ) { let bodyType: _AttributeBody.Type #if CompatibilityModeAttributeGraphV6 - bodyType = Body.self + bodyType = Body.self #else - bodyType = flags.contains(.external) ? _External.self : Body.self + bodyType = flags.contains(.external) ? _External.self : Body.self #endif let attributeType = _AttributeType( diff --git a/Sources/Compute/Attribute/AttributeType.swift b/Sources/Compute/Attribute/AttributeType.swift index c1ad0ef..580589a 100644 --- a/Sources/Compute/Attribute/AttributeType.swift +++ b/Sources/Compute/Attribute/AttributeType.swift @@ -51,7 +51,7 @@ extension _AttributeType { vtable.pointee.self_destroy = { attributeType, body in attributeType.pointee.attributeBody._destroySelf(body) } -#if os(macOS) + #if os(macOS) vtable.pointee.self_description = { attributeType, body in let description: String if let selfType = attributeType.pointee.self_id.type @@ -68,7 +68,7 @@ extension _AttributeType { let description = String._describing(value, of: valueType) return Unmanaged.passRetained(description as CFString).autorelease() } -#else + #else vtable.pointee.copy_self_description = { attributeType, body in let description: String if let selfType = attributeType.pointee.self_id.type @@ -85,7 +85,7 @@ extension _AttributeType { let description = String._describing(value, of: valueType) return Unmanaged.passRetained(description.cfString) } -#endif + #endif vtable.pointee.update_default = { attributeType, body in attributeType.pointee.attributeBody._updateDefault(body) } diff --git a/Sources/Compute/Attribute/External.swift b/Sources/Compute/Attribute/External.swift index da619c0..6fd3470 100644 --- a/Sources/Compute/Attribute/External.swift +++ b/Sources/Compute/Attribute/External.swift @@ -1,11 +1,11 @@ import ComputeCxx public struct _External { - + public init() {} public static func _update(_: UnsafeMutableRawPointer, attribute: AnyAttribute) {} - + } extension _External: CustomStringConvertible { diff --git a/Sources/Compute/Attribute/Indirect/IndirectAttribute.swift b/Sources/Compute/Attribute/Indirect/IndirectAttribute.swift index 945cb62..dac6631 100644 --- a/Sources/Compute/Attribute/Indirect/IndirectAttribute.swift +++ b/Sources/Compute/Attribute/Indirect/IndirectAttribute.swift @@ -12,13 +12,13 @@ public struct IndirectAttribute { public var source: Attribute { get { - return Attribute(identifier: identifier.source) + return Attribute(identifier: identifier.source) } nonmutating set { identifier.source = newValue.identifier } } - + public var attribute: Attribute { return Attribute(identifier: identifier) } diff --git a/Sources/Compute/Attribute/Observed/ObservedAttribute.swift b/Sources/Compute/Attribute/Observed/ObservedAttribute.swift index 51b3a1e..b5a786e 100644 --- a/Sources/Compute/Attribute/Observed/ObservedAttribute.swift +++ b/Sources/Compute/Attribute/Observed/ObservedAttribute.swift @@ -1,7 +1,7 @@ public protocol ObservedAttribute: _AttributeBody { mutating func destroy() - + } extension ObservedAttribute { diff --git a/Sources/Compute/Attribute/Optional/OptionalAttribute.swift b/Sources/Compute/Attribute/Optional/OptionalAttribute.swift index 03fe607..589cd61 100644 --- a/Sources/Compute/Attribute/Optional/OptionalAttribute.swift +++ b/Sources/Compute/Attribute/Optional/OptionalAttribute.swift @@ -1,29 +1,29 @@ @propertyWrapper @dynamicMemberLookup public struct OptionalAttribute { - + public var base: AnyOptionalAttribute - + public init(base: AnyOptionalAttribute) { self.base = base } - + public init() { base = AnyOptionalAttribute() } - + public init(_ weakAttribute: WeakAttribute) { base = AnyOptionalAttribute(weakAttribute.base) } - + public init(_ attribute: Attribute) { base = AnyOptionalAttribute(attribute.identifier) } - + public init(_ attribute: Attribute?) { base = AnyOptionalAttribute(attribute?.identifier) } - + public var attribute: Attribute? { get { return base.attribute?.unsafeCast(to: Value.self) @@ -32,7 +32,7 @@ public struct OptionalAttribute { base.attribute = newValue?.identifier } } - + public var value: Value? { return attribute?.value } @@ -48,11 +48,11 @@ public struct OptionalAttribute { return nil } } - + public var wrappedValue: Value? { return value } - + public var projectedValue: Attribute? { get { return attribute @@ -64,7 +64,7 @@ public struct OptionalAttribute { yield &attribute } } - + public subscript(dynamicMember keyPath: KeyPath) -> Attribute? { return attribute?[dynamicMember: keyPath] } diff --git a/Sources/Compute/Attribute/PointerOffset.swift b/Sources/Compute/Attribute/PointerOffset.swift index 29f38ae..5298982 100644 --- a/Sources/Compute/Attribute/PointerOffset.swift +++ b/Sources/Compute/Attribute/PointerOffset.swift @@ -1,29 +1,29 @@ public struct PointerOffset { - + public var byteOffset: Int - + public init(byteOffset: Int) { self.byteOffset = byteOffset } - + public static func of(_ member: inout Member) -> PointerOffset { return withUnsafePointer(to: &member) { memberPointer in let offset = UnsafeRawPointer(memberPointer) - UnsafeRawPointer(invalidScenePointer()) return PointerOffset(byteOffset: offset) } } - + public static func offset(_ body: (inout Base) -> PointerOffset) -> PointerOffset { guard MemoryLayout.size != 0 else { return PointerOffset(byteOffset: 0) } return body(&invalidScenePointer().pointee) } - + public static func invalidScenePointer() -> UnsafeMutablePointer { return UnsafeMutablePointer(bitPattern: MemoryLayout.stride)! } - + } extension PointerOffset where Base == Member { @@ -36,7 +36,10 @@ extension PointerOffset where Base == Member { extension PointerOffset { - public static func + (_ lhs: PointerOffset, _ rhs: PointerOffset) -> PointerOffset< + public static func + ( + _ lhs: PointerOffset, + _ rhs: PointerOffset + ) -> PointerOffset< Base, Member > { return PointerOffset(byteOffset: lhs.byteOffset + rhs.byteOffset) @@ -46,7 +49,10 @@ extension PointerOffset { extension UnsafePointer { - public static func + (_ lhs: UnsafePointer, _ rhs: PointerOffset) + public static func + ( + _ lhs: UnsafePointer, + _ rhs: PointerOffset + ) -> UnsafePointer< Member > diff --git a/Sources/Compute/Attribute/Rule/StatefulRule.swift b/Sources/Compute/Attribute/Rule/StatefulRule.swift index 462c4a1..51481c8 100644 --- a/Sources/Compute/Attribute/Rule/StatefulRule.swift +++ b/Sources/Compute/Attribute/Rule/StatefulRule.swift @@ -56,7 +56,7 @@ extension StatefulRule { public var attribute: Attribute { return Attribute(identifier: AnyAttribute.current!) } - + public var context: RuleContext { return RuleContext(attribute: attribute) } diff --git a/Sources/Compute/Attribute/RuleContext/AnyRuleContext.swift b/Sources/Compute/Attribute/RuleContext/AnyRuleContext.swift index 90c09d3..9f50c4a 100644 --- a/Sources/Compute/Attribute/RuleContext/AnyRuleContext.swift +++ b/Sources/Compute/Attribute/RuleContext/AnyRuleContext.swift @@ -26,7 +26,10 @@ public struct AnyRuleContext { } } - public func changedValue(of input: Attribute, options: AGValueOptions) -> ( + public func changedValue( + of input: Attribute, + options: AGValueOptions + ) -> ( value: Value, changed: Bool ) { let result = __AGGraphGetInputValue(attribute, input.identifier, options, Metadata(Value.self)) @@ -36,7 +39,10 @@ public struct AnyRuleContext { ) } - public func valueAndFlags(of input: Attribute, options: AGValueOptions) -> ( + public func valueAndFlags( + of input: Attribute, + options: AGValueOptions + ) -> ( value: Value, flags: AGChangedValueFlags ) { let result = __AGGraphGetInputValue(attribute, input.identifier, options, Metadata(Value.self)) diff --git a/Sources/Compute/Attribute/RuleContext/RuleContext.swift b/Sources/Compute/Attribute/RuleContext/RuleContext.swift index f90a1a1..cb739da 100644 --- a/Sources/Compute/Attribute/RuleContext/RuleContext.swift +++ b/Sources/Compute/Attribute/RuleContext/RuleContext.swift @@ -5,7 +5,7 @@ public struct RuleContext { public init(attribute: Attribute) { self.attribute = attribute } - + @_extern(c, "AGGraphWithUpdate") private static func withUpdate(_ attribute: AnyAttribute, body: @escaping () -> Void) @@ -42,7 +42,10 @@ public struct RuleContext { ) } - public func valueAndFlags(of input: Attribute, options: AGValueOptions) -> ( + public func valueAndFlags( + of input: Attribute, + options: AGValueOptions + ) -> ( value: InputValue, flags: AGChangedValueFlags ) { let value = __AGGraphGetInputValue( diff --git a/Sources/Compute/Attribute/Weak/WeakAttribute.swift b/Sources/Compute/Attribute/Weak/WeakAttribute.swift index 47e97cf..1745239 100644 --- a/Sources/Compute/Attribute/Weak/WeakAttribute.swift +++ b/Sources/Compute/Attribute/Weak/WeakAttribute.swift @@ -9,7 +9,9 @@ public struct WeakAttribute { } public init() { - base = AnyWeakAttribute(_details: AnyWeakAttribute.__Unnamed_struct__details(identifier: AnyAttribute(rawValue: 0), seed: 0)) + base = AnyWeakAttribute( + _details: AnyWeakAttribute.__Unnamed_struct__details(identifier: AnyAttribute(rawValue: 0), seed: 0) + ) } public init(_ attribute: Attribute) { diff --git a/Sources/Compute/Runtime/Metadata.swift b/Sources/Compute/Runtime/Metadata.swift index 7d0366a..36021e1 100644 --- a/Sources/Compute/Runtime/Metadata.swift +++ b/Sources/Compute/Runtime/Metadata.swift @@ -31,7 +31,10 @@ extension Metadata { ) -> Bool - public func forEachField(options: Metadata.ApplyOptions, do body: (UnsafePointer, Int, Any.Type) -> Bool) + public func forEachField( + options: Metadata.ApplyOptions, + do body: (UnsafePointer, Int, Any.Type) -> Bool + ) -> Bool { return Metadata.applyFields2(type: self, options: options) { fieldName, fieldOffset, fieldType in @@ -45,9 +48,9 @@ extension Metadata: @retroactive CustomStringConvertible { public var description: String { #if os(macOS) - return __AGTypeDescription(self) as String + return __AGTypeDescription(self) as String #else - return String(__AGTypeCopyDescription(self)) + return String(__AGTypeCopyDescription(self)) #endif } diff --git a/Sources/Compute/Runtime/Tuple.swift b/Sources/Compute/Runtime/Tuple.swift index d7a3a75..3abaa76 100644 --- a/Sources/Compute/Runtime/Tuple.swift +++ b/Sources/Compute/Runtime/Tuple.swift @@ -100,7 +100,10 @@ extension UnsafeTuple { return value.assumingMemoryBound(to: expectedType) } - public func address(of index: Int, as elementType: T.Type) + public func address( + of index: Int, + as elementType: T.Type + ) -> UnsafePointer { return value.advanced( @@ -180,7 +183,10 @@ extension UnsafeMutableTuple { return value.assumingMemoryBound(to: expectedType) } - public func address(of index: Int, as elementType: T.Type) + public func address( + of index: Int, + as elementType: T.Type + ) -> UnsafeMutablePointer { return value.advanced( diff --git a/Tests/ComputeLayoutDescriptorTests/Shared/PrefetchCompareValuesTests.swift b/Tests/ComputeLayoutDescriptorTests/Shared/PrefetchCompareValuesTests.swift index 4f3e952..2c6592d 100644 --- a/Tests/ComputeLayoutDescriptorTests/Shared/PrefetchCompareValuesTests.swift +++ b/Tests/ComputeLayoutDescriptorTests/Shared/PrefetchCompareValuesTests.swift @@ -27,7 +27,11 @@ extension Optional: @retroactive CustomStringConvertible where Wrapped == ValueL } -func prefetchCompareValues(of type: Value.Type, options: ComparisonOptions, priority: Int) +func prefetchCompareValues( + of type: Value.Type, + options: ComparisonOptions, + priority: Int +) -> ValueLayout? { @@ -1071,14 +1075,14 @@ struct PrefetchCompareValuesTests { ) } } - + @Test func layoutForIndirectEnumCase() async { setenv("AG_ASYNC_LAYOUTS", "0", 1) setenv("AG_PRINT_LAYOUTS", "1", 1) - + protocol NodeProtocol { - + } struct Node { let field0: NodeProtocol.Type @@ -1107,7 +1111,7 @@ struct PrefetchCompareValuesTests { (enum #:size 8 #:type Stack (case 0 (read 8)))) - + """ ) } @@ -1129,7 +1133,7 @@ struct PrefetchCompareValuesTests { (enum #:size 8 #:type Stack (case 0 (indirect #:size 40 #:type (value: Node, next: Stack))))) - + """ ) } @@ -1151,7 +1155,7 @@ struct PrefetchCompareValuesTests { (enum #:size 8 #:type Stack (case 0 (indirect #:size 40 #:type (value: Node, next: Stack))))) - + """ ) } @@ -1173,7 +1177,7 @@ struct PrefetchCompareValuesTests { (enum #:size 8 #:type Stack (case 0 (indirect #:size 40 #:type (value: Node, next: Stack))))) - + """ ) } @@ -1760,11 +1764,11 @@ struct PrefetchCompareValuesTests { #expect(layout3 != nil) #expect( output3 == """ - == Any, 32 bytes == - (layout #:length 10 #:address \(String(describing: layout3)) - (existential #:size 32 #:type Any)) - - """ + == Any, 32 bytes == + (layout #:length 10 #:address \(String(describing: layout3)) + (existential #:size 32 #:type Any)) + + """ ) } } diff --git a/Tests/ComputeTests/Shared/Attribute/AnyAttributeTests.swift b/Tests/ComputeTests/Shared/Attribute/AnyAttributeTests.swift index 4c20caf..8583f80 100644 --- a/Tests/ComputeTests/Shared/Attribute/AnyAttributeTests.swift +++ b/Tests/ComputeTests/Shared/Attribute/AnyAttributeTests.swift @@ -22,5 +22,4 @@ struct AnyAttributeTests { } - } diff --git a/Tests/ComputeTests/Shared/Attribute/AttributeTests.swift b/Tests/ComputeTests/Shared/Attribute/AttributeTests.swift index db8ec0c..8411789 100644 --- a/Tests/ComputeTests/Shared/Attribute/AttributeTests.swift +++ b/Tests/ComputeTests/Shared/Attribute/AttributeTests.swift @@ -35,9 +35,9 @@ struct AttributeTests { let attributeType = attribute.identifier.info.type.pointee #if CompatibilityModeAttributeGraphV6 - #expect(attributeType.self_id == Metadata(External.self)) + #expect(attributeType.self_id == Metadata(External.self)) #else - #expect(attributeType.self_id == Metadata(_External.self)) + #expect(attributeType.self_id == Metadata(_External.self)) #endif #expect(attributeType.value_id == Metadata(Int.self)) @@ -46,15 +46,15 @@ struct AttributeTests { #expect(attributeType.value_layout == expectedlayout) #if CompatibilityModeAttributeGraphV6 - let attributeBody = unsafeBitCast( - External.self as any _AttributeBody.Type, - to: (type: Metadata, witnessTable: UnsafeRawPointer).self - ) + let attributeBody = unsafeBitCast( + External.self as any _AttributeBody.Type, + to: (type: Metadata, witnessTable: UnsafeRawPointer).self + ) #else - let attributeBody = unsafeBitCast( - _External.self as any _AttributeBody.Type, - to: (type: Metadata, witnessTable: UnsafeRawPointer).self - ) + let attributeBody = unsafeBitCast( + _External.self as any _AttributeBody.Type, + to: (type: Metadata, witnessTable: UnsafeRawPointer).self + ) #endif #expect(attributeType.body_conformance.type_id == attributeBody.type) #expect(attributeType.body_conformance.witness_table == attributeBody.witnessTable) @@ -81,9 +81,9 @@ struct AttributeTests { let attributeType = attribute.identifier.info.type.pointee #if CompatibilityModeAttributeGraphV6 - #expect(attributeType.self_id == Metadata(External.self)) + #expect(attributeType.self_id == Metadata(External.self)) #else - #expect(attributeType.self_id == Metadata(_External.self)) + #expect(attributeType.self_id == Metadata(_External.self)) #endif #expect(attributeType.value_id == Metadata(Int.self)) @@ -92,15 +92,15 @@ struct AttributeTests { #expect(attributeType.value_layout == expectedlayout) #if CompatibilityModeAttributeGraphV6 - let attributeBody = unsafeBitCast( - External.self as any _AttributeBody.Type, - to: (type: Metadata, witnessTable: UnsafeRawPointer).self - ) + let attributeBody = unsafeBitCast( + External.self as any _AttributeBody.Type, + to: (type: Metadata, witnessTable: UnsafeRawPointer).self + ) #else - let attributeBody = unsafeBitCast( - _External.self as any _AttributeBody.Type, - to: (type: Metadata, witnessTable: UnsafeRawPointer).self - ) + let attributeBody = unsafeBitCast( + _External.self as any _AttributeBody.Type, + to: (type: Metadata, witnessTable: UnsafeRawPointer).self + ) #endif #expect(attributeType.body_conformance.type_id == attributeBody.type) #expect(attributeType.body_conformance.witness_table == attributeBody.witnessTable) diff --git a/Tests/ComputeTests/Shared/Attribute/ExternalTests.swift b/Tests/ComputeTests/Shared/Attribute/ExternalTests.swift index 49448d3..130076e 100644 --- a/Tests/ComputeTests/Shared/Attribute/ExternalTests.swift +++ b/Tests/ComputeTests/Shared/Attribute/ExternalTests.swift @@ -2,17 +2,17 @@ import Testing @Suite struct ExternalTests { - + @Test func external() throws { let type = External.self - + #expect(type.comparisonMode == .equatableAlways) #expect(type.flags == []) - + let externalInt = type.init() - + #expect(externalInt.description == "Int") } - + } diff --git a/Tests/ComputeTests/Shared/Attribute/RuleTests.swift b/Tests/ComputeTests/Shared/Attribute/RuleTests.swift index c976084..0e434e6 100644 --- a/Tests/ComputeTests/Shared/Attribute/RuleTests.swift +++ b/Tests/ComputeTests/Shared/Attribute/RuleTests.swift @@ -59,7 +59,7 @@ struct RuleTests { let value = attribute2.value #expect(value == "derived: rule 1 computed value") } - + @Test func initialValue() { let attribute1 = Attribute(TestRule1(), initialValue: "rule 1 initial value") @@ -67,7 +67,7 @@ struct RuleTests { let value = attribute2.value #expect(value == "derived: rule 1 initial value") } - + @Test func invalidateValue() { let attribute1 = Attribute(TestRule1(), initialValue: "rule 1 initial value") @@ -77,7 +77,6 @@ struct RuleTests { #expect(value == "derived: rule 1 computed value") } - } } diff --git a/Tests/ComputeTests/Shared/Attribute/WeakAttributeTests.swift b/Tests/ComputeTests/Shared/Attribute/WeakAttributeTests.swift index 2d0edad..1d1fe15 100644 --- a/Tests/ComputeTests/Shared/Attribute/WeakAttributeTests.swift +++ b/Tests/ComputeTests/Shared/Attribute/WeakAttributeTests.swift @@ -2,32 +2,32 @@ import Testing @Suite struct WeakAttributeTests { - + @MainActor @Suite(.applySubgraph) struct InitTests { - + @Test func initDefault() { let weakAttribute = WeakAttribute() #expect(weakAttribute.attribute == nil) } - + @Test func initWithNil() { let weakAttribute = WeakAttribute(nil) #expect(weakAttribute.attribute == nil) } - + @Test func initWithAttribute() { let attribute = Attribute(value: 0) let weakAttribute = WeakAttribute(attribute) #expect(weakAttribute.attribute == attribute) } - + } - + @Suite struct SubgraphTraversalTests { @@ -36,15 +36,15 @@ struct WeakAttributeTests { let graph = Graph() let subgraph = Subgraph(graph: graph) Subgraph.current = subgraph - + let attribute = Attribute(value: 0) let weakAttribute = WeakAttribute(attribute) #expect(weakAttribute.attribute == attribute) - + subgraph.invalidate() - + #expect(weakAttribute.attribute == nil) - + Subgraph.current = nil } diff --git a/Tests/ComputeTests/Shared/Graph+DictionaryDescription.swift b/Tests/ComputeTests/Shared/Graph+DictionaryDescription.swift index 94df657..87cb16f 100644 --- a/Tests/ComputeTests/Shared/Graph+DictionaryDescription.swift +++ b/Tests/ComputeTests/Shared/Graph+DictionaryDescription.swift @@ -179,8 +179,11 @@ extension Graph { let data = try! JSONSerialization.data(withJSONObject: description, options: [.prettyPrinted, .sortedKeys]) return try! JSONDecoder().decode(DictionaryDescription.self, from: data) } - - public static func dictionaryDescription(allGraphs: Bool = false, includeValues: Bool = false) + + public static func dictionaryDescription( + allGraphs: Bool = false, + includeValues: Bool = false + ) -> DictionaryDescription? { let options = @@ -198,8 +201,11 @@ extension Graph { } return try? JSONDecoder().decode(DictionaryDescription.self, from: data) } - - public static func dictionaryDescriptionJSON(allGraphs: Bool = false, includeValues: Bool = false) + + public static func dictionaryDescriptionJSON( + allGraphs: Bool = false, + includeValues: Bool = false + ) -> Data? { let options = diff --git a/Tests/ComputeTests/Shared/Runtime/ReflectionTests.swift b/Tests/ComputeTests/Shared/Runtime/ReflectionTests.swift index a062739..892416e 100644 --- a/Tests/ComputeTests/Shared/Runtime/ReflectionTests.swift +++ b/Tests/ComputeTests/Shared/Runtime/ReflectionTests.swift @@ -2,12 +2,12 @@ import Testing @Suite struct ReflectionTests { - + @Test func reflectEmptyStruct() { - + struct EmptyStruct {} - + var fields: [(String, Int, any Any.Type)] = [] let finished = Metadata(EmptyStruct.self).forEachField(options: []) { fieldName, @@ -16,14 +16,14 @@ struct ReflectionTests { fields.append((String(cString: fieldName), fieldOffset, fieldType)) return true } - + #expect(finished == false) #expect(fields.count == 0) } - + @Test func reflectStaticString() { - + var fields: [(String, Int, any Any.Type)] = [] let finished = Metadata(StaticString.self).forEachField(options: []) { fieldName, @@ -32,18 +32,18 @@ struct ReflectionTests { fields.append((String(cString: fieldName), fieldOffset, fieldType)) return true } - + #expect(finished == true) #expect(fields.count == 3) - + #expect(fields[0].1 == 0) #expect(fields[1].1 == 8) #expect(fields[2].1 == 16) } - + @Test func reflectOptionalInt() { - + var fields: [(String, Int, any Any.Type)] = [] let finished = Metadata(Optional.self).forEachField(options: [.enumerateEnumCases]) { fieldName, @@ -52,9 +52,9 @@ struct ReflectionTests { fields.append((String(cString: fieldName), fieldOffset, fieldType)) return true } - + #expect(finished == true) #expect(fields.count == 1) } - + } diff --git a/Tests/ComputeTests/Shared/Subgraph/SubgraphTests.swift b/Tests/ComputeTests/Shared/Subgraph/SubgraphTests.swift index b0862ef..1e5b77f 100644 --- a/Tests/ComputeTests/Shared/Subgraph/SubgraphTests.swift +++ b/Tests/ComputeTests/Shared/Subgraph/SubgraphTests.swift @@ -422,29 +422,29 @@ struct SubgraphTests { } } - + @Suite struct FlagsTests { - + @Test func intersects() { let graph = Graph() let subgraph = Subgraph(graph: graph) - + let child = Subgraph(graph: graph) subgraph.addChild(child) - + Subgraph.current = child - + let attribute = Attribute(value: 1) #expect(subgraph.intersects(flags: Subgraph.Flags(rawValue: 1)) == false) #expect(child.intersects(flags: Subgraph.Flags(rawValue: 1)) == false) - + attribute.flags = Subgraph.Flags(rawValue: 1) #expect(subgraph.intersects(flags: Subgraph.Flags(rawValue: 1)) == true) #expect(child.intersects(flags: Subgraph.Flags(rawValue: 1)) == true) } - + } }